Skip to content

Commit 89d93e6

Browse files
committed
Update square, tan, tanh and unwrap functions to use math where applicable
1 parent 8c3bccb commit 89d93e6

File tree

1 file changed

+41
-31
lines changed

1 file changed

+41
-31
lines changed

dpnp/dpnp_iface_trigonometric.py

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -774,8 +774,8 @@ def _get_accumulation_res_dt(a, dtype):
774774
Returns
775775
-------
776776
out : dpnp.ndarray
777-
An array containing the element-wise cosine. The data type of the returned
778-
array is determined by the Type Promotion Rules.
777+
An array containing the element-wise cosine, in radians. The data type of
778+
the returned array is determined by the Type Promotion Rules.
779779
780780
Limitations
781781
-----------
@@ -2269,8 +2269,8 @@ def reduce_hypot(x, /, *, axis=None, dtype=None, keepdims=False, out=None):
22692269
Returns
22702270
-------
22712271
out : dpnp.ndarray
2272-
An array containing the element-wise sine. The data type of the returned
2273-
array is determined by the Type Promotion Rules.
2272+
An array containing the element-wise sine, in radians. The data type of the
2273+
returned array is determined by the Type Promotion Rules.
22742274
22752275
Limitations
22762276
-----------
@@ -2441,14 +2441,14 @@ def reduce_hypot(x, /, *, axis=None, dtype=None, keepdims=False, out=None):
24412441

24422442

24432443
_SQUARE_DOCSTRING = r"""
2444-
Squares each element `x_i` of input array `x`.
2444+
Squares each element :math:`x_i` of input array `x`.
24452445
24462446
For full documentation refer to :obj:`numpy.square`.
24472447
24482448
Parameters
24492449
----------
24502450
x : {dpnp.ndarray, usm_ndarray}
2451-
Input array.
2451+
Input array, expected to have a boolean or numeric data type.
24522452
out : {None, dpnp.ndarray, usm_ndarray}, optional
24532453
Output array to populate.
24542454
Array must have the correct shape and the expected data type.
@@ -2462,8 +2462,8 @@ def reduce_hypot(x, /, *, axis=None, dtype=None, keepdims=False, out=None):
24622462
Returns
24632463
-------
24642464
out : dpnp.ndarray
2465-
An array containing the element-wise squares of `x`. The data type of
2466-
the returned array is determined by the Type Promotion Rules.
2465+
An array containing the element-wise squares of `x`. The data type of the
2466+
returned array is determined by the Type Promotion Rules.
24672467
24682468
Limitations
24692469
-----------
@@ -2473,11 +2473,11 @@ def reduce_hypot(x, /, *, axis=None, dtype=None, keepdims=False, out=None):
24732473
24742474
See Also
24752475
--------
2476-
:obj:`dpnp..linalg.matrix_power` : Raise a square matrix
2477-
to the (integer) power `n`.
2476+
:obj:`dpnp..linalg.matrix_power` : Raise a square matrix to the (integer)
2477+
power `n`.
24782478
:obj:`dpnp.sqrt` : Calculate :math:`\sqrt{x}`, element-wise.
2479-
:obj:`dpnp.power` : First array elements raised to powers
2480-
from second array, element-wise.
2479+
:obj:`dpnp.power` : Exponentiation by raising the first array to the power of
2480+
the second array, element-wise.
24812481
24822482
Examples
24832483
--------
@@ -2499,14 +2499,14 @@ def reduce_hypot(x, /, *, axis=None, dtype=None, keepdims=False, out=None):
24992499

25002500

25012501
_TAN_DOCSTRING = """
2502-
Computes tangent for each element `x_i` for input array `x`.
2502+
Computes the tangent for each element :math:`x_i` for input array `x`.
25032503
25042504
For full documentation refer to :obj:`numpy.tan`.
25052505
25062506
Parameters
25072507
----------
25082508
x : {dpnp.ndarray, usm_ndarray}
2509-
Input array, expected to have numeric data type.
2509+
Input array, expected to have a floating-point data type.
25102510
out : {None, dpnp.ndarray, usm_ndarray}, optional
25112511
Output array to populate.
25122512
Array must have the correct shape and the expected data type.
@@ -2520,8 +2520,8 @@ def reduce_hypot(x, /, *, axis=None, dtype=None, keepdims=False, out=None):
25202520
Returns
25212521
-------
25222522
out : dpnp.ndarray
2523-
An array containing the element-wise tangent. The data type
2524-
of the returned array is determined by the Type Promotion Rules.
2523+
An array containing the element-wise tangent, in radians. The data type of
2524+
the returned array is determined by the Type Promotion Rules.
25252525
25262526
Limitations
25272527
-----------
@@ -2531,7 +2531,7 @@ def reduce_hypot(x, /, *, axis=None, dtype=None, keepdims=False, out=None):
25312531
25322532
See Also
25332533
--------
2534-
:obj:`dpnp.arctan` : Trigonometric inverse tangent, element-wise.
2534+
:obj:`dpnp.atan` : Trigonometric inverse tangent, element-wise.
25352535
:obj:`dpnp.sin` : Trigonometric sine, element-wise.
25362536
:obj:`dpnp.cos` : Trigonometric cosine, element-wise.
25372537
:obj:`dpnp.tanh` : Hyperbolic tangent, element-wise.
@@ -2555,15 +2555,21 @@ def reduce_hypot(x, /, *, axis=None, dtype=None, keepdims=False, out=None):
25552555
)
25562556

25572557

2558-
_TANH_DOCSTRING = """
2559-
Computes hyperbolic tangent for each element `x_i` for input array `x`.
2558+
_TANH_DOCSTRING = r"""
2559+
Computes the hyperbolic tangent for each element :math:`x_i` for input array
2560+
`x`.
2561+
2562+
The mathematical definition of the hyperbolic tangent is
2563+
2564+
.. math::
2565+
\operatorname{tanh}(x) = \frac{\operatorname{sinh}(x)}{\operatorname{cosh}(x)}
25602566
25612567
For full documentation refer to :obj:`numpy.tanh`.
25622568
25632569
Parameters
25642570
----------
25652571
x : {dpnp.ndarray, usm_ndarray}
2566-
Input array, expected to have numeric data type.
2572+
Input array, expected to have a floating-point data type.
25672573
out : {None, dpnp.ndarray, usm_ndarray}, optional
25682574
Output array to populate.
25692575
Array must have the correct shape and the expected data type.
@@ -2577,8 +2583,8 @@ def reduce_hypot(x, /, *, axis=None, dtype=None, keepdims=False, out=None):
25772583
Returns
25782584
-------
25792585
out : dpnp.ndarray
2580-
An array containing the element-wise hyperbolic tangent. The data type
2581-
of the returned array is determined by the Type Promotion Rules.
2586+
An array containing the element-wise hyperbolic tangent. The data type of
2587+
the returned array is determined by the Type Promotion Rules.
25822588
25832589
Limitations
25842590
-----------
@@ -2588,7 +2594,7 @@ def reduce_hypot(x, /, *, axis=None, dtype=None, keepdims=False, out=None):
25882594
25892595
See Also
25902596
--------
2591-
:obj:`dpnp.arctanh` : Hyperbolic inverse tangent, element-wise.
2597+
:obj:`dpnp.atanh` : Hyperbolic inverse tangent, element-wise.
25922598
:obj:`dpnp.sinh` : Hyperbolic sine, element-wise.
25932599
:obj:`dpnp.cosh` : Hyperbolic cosine, element-wise.
25942600
:obj:`dpnp.tan` : Trigonometric tangent, element-wise.
@@ -2617,8 +2623,9 @@ def unwrap(p, discont=None, axis=-1, *, period=2 * dpnp.pi):
26172623
Unwrap by taking the complement of large deltas with respect to the period.
26182624
26192625
This unwraps a signal `p` by changing elements which have an absolute
2620-
difference from their predecessor of more than ``max(discont, period / 2)``
2621-
to their `period`-complementary values.
2626+
difference from their predecessor of more than
2627+
:math:`\max(discont, \frac{period}{2})` to their `period`-complementary
2628+
values.
26222629
26232630
For the default case where `period` is :math:`2\pi` and `discont` is
26242631
:math:`\pi`, this unwraps a radian phase `p` such that adjacent differences
@@ -2633,16 +2640,19 @@ def unwrap(p, discont=None, axis=-1, *, period=2 * dpnp.pi):
26332640
Input array.
26342641
discont : {float, None}, optional
26352642
Maximum discontinuity between values, default is ``None`` which is an
2636-
alias for ``period / 2``. Values below ``period / 2`` are treated as if
2637-
they were ``period / 2``. To have an effect different from the default,
2638-
`discont` should be larger than ``period / 2``.
2643+
alias for :math:`\frac{period}{2}`. Values below
2644+
:math:`\frac{period}{2}` are treated as if they were
2645+
:math:`\frac{period}{2}`. To have an effect different from the default,
2646+
`discont` should be larger than :math:`\frac{period}{2}`.
26392647
26402648
Default: ``None``.
26412649
axis : int, optional
26422650
Axis along which unwrap will operate, default is the last axis.
2651+
26432652
Default: ``-1``.
26442653
period : float, optional
26452654
Size of the range over which the input wraps.
2655+
26462656
Default: ``2 * pi``.
26472657
26482658
Returns
@@ -2657,9 +2667,9 @@ def unwrap(p, discont=None, axis=-1, *, period=2 * dpnp.pi):
26572667
26582668
Notes
26592669
-----
2660-
If the discontinuity in `p` is smaller than ``period / 2``, but larger than
2661-
`discont`, no unwrapping is done because taking the complement would only
2662-
make the discontinuity larger.
2670+
If the discontinuity in `p` is smaller than :math:`\frac{period}{2}`, but
2671+
larger than `discont`, no unwrapping is done because taking the complement
2672+
would only make the discontinuity larger.
26632673
26642674
Examples
26652675
--------

0 commit comments

Comments
 (0)