Skip to content

Commit 53fbb77

Browse files
committed
Update docstring of atan, atan2, and atanh functions to use math where applicable.
Also `arctan` is now alias on `atan` function. And `arctan2` is now alias on `atan2` function. And `arctanh` is now alias on `atanh` function.
1 parent ef192ca commit 53fbb77

File tree

1 file changed

+85
-77
lines changed

1 file changed

+85
-77
lines changed

dpnp/dpnp_iface_trigonometric.py

Lines changed: 85 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -440,17 +440,18 @@ def _get_accumulation_res_dt(a, dtype):
440440

441441

442442
_ATAN_DOCSTRING = r"""
443-
Computes inverse tangent for each element `x_i` for input array `x`.
443+
Computes inverse tangent for each element :math:`x_i` for input array `x`.
444444
445-
The inverse of :obj:`dpnp.tan`, so that if ``y = tan(x)`` then ``x = arctan(y)``.
446-
Note that :obj:`dpnp.atan` is an alias of :obj:`dpnp.arctan`.
445+
The inverse of :obj:`dpnp.tan`, so that if :math:`y = tan(x)` then
446+
:math:`x = atan(y)`. Note that :obj:`dpnp.arctan` is an alias of
447+
:obj:`dpnp.atan`.
447448
448-
For full documentation refer to :obj:`numpy.arctan`.
449+
For full documentation refer to :obj:`numpy.atan`.
449450
450451
Parameters
451452
----------
452453
x : {dpnp.ndarray, usm_ndarray}
453-
Input array, expected to have numeric data type.
454+
Input array, expected to have a floating-point data type.
454455
out : {None, dpnp.ndarray, usm_ndarray}, optional
455456
Output array to populate.
456457
Array must have the correct shape and the expected data type.
@@ -464,9 +465,9 @@ def _get_accumulation_res_dt(a, dtype):
464465
Returns
465466
-------
466467
out : dpnp.ndarray
467-
An array containing the element-wise inverse tangent, in radians
468-
and in the closed interval `[-\pi/2, \pi/2]`. The data type
469-
of the returned array is determined by the Type Promotion Rules.
468+
An array containing the element-wise inverse tangent, in radians and in the
469+
closed interval :math:`[-\pi/2, \pi/2]`. The data type of the returned
470+
array is determined by the Type Promotion Rules.
470471
471472
Limitations
472473
-----------
@@ -476,73 +477,70 @@ def _get_accumulation_res_dt(a, dtype):
476477
477478
See Also
478479
--------
479-
:obj:`dpnp.arctan2` : Element-wise arc tangent of `x1/x2` choosing the quadrant correctly.
480+
:obj:`dpnp.atan2` : Element-wise arc tangent of `x1/x2`
481+
choosing the quadrant correctly.
480482
:obj:`dpnp.angle` : Argument of complex values.
481483
:obj:`dpnp.tan` : Trigonometric tangent, element-wise.
482-
:obj:`dpnp.arcsin` : Trigonometric inverse sine, element-wise.
483-
:obj:`dpnp.arccos` : Trigonometric inverse cosine, element-wise.
484-
:obj:`dpnp.arctanh` : Inverse hyperbolic tangent, element-wise.
484+
:obj:`dpnp.asin` : Trigonometric inverse sine, element-wise.
485+
:obj:`dpnp.acos` : Trigonometric inverse cosine, element-wise.
486+
:obj:`dpnp.atanh` : Inverse hyperbolic tangent, element-wise.
485487
486488
Notes
487489
-----
488-
:obj:`dpnp.arctan` is a multivalued function: for each `x` there are infinitely
489-
many numbers `z` such that ``tan(z) = x``. The convention is to return the
490-
angle `z` whose real part lies in `[-\pi/2, \pi/2]`.
490+
:obj:`dpnp.atan` is a multivalued function: for each `x` there are infinitely
491+
many numbers `z` such that :math:`tan(z) = x`. The convention is to return the
492+
angle `z` whose the real part lies in the interval :math:`[-\pi/2, \pi/2]`.
491493
492-
For real-valued input data types, :obj:`dpnp.arctan` always returns real output.
493-
For each value that cannot be expressed as a real number or infinity, it yields
494-
``NaN``.
494+
For real-valued floating-point input data types, :obj:`dpnp.atan` always
495+
returns real output. For each value that cannot be expressed as a real number
496+
or infinity, it yields ``NaN``.
495497
496-
For complex-valued input, :obj:`dpnp.arctan` is a complex analytic function that
497-
has, by convention, the branch cuts `[1j, infj]` and `[-1j, -infj]` and is continuous
498-
from the left on the former and from the right on the latter.
498+
For complex floating-point input data types, :obj:`dpnp.atan` is a complex
499+
analytic function that has, by convention, the branch cuts
500+
:math:`(-\infty j, -j)` and :math:`(j, \infty j)` and is continuous from the right
501+
on the former and from the left on the latter.
499502
500-
The inverse tan is also known as :math:`atan` or :math:`tan^{-1}`.
503+
The inverse tangent is also known as :math:`tan^{-1}`.
501504
502505
Examples
503506
--------
504507
>>> import dpnp as np
505508
>>> x = np.array([0, 1])
506-
>>> np.arctan(x)
509+
>>> np.atan(x)
507510
array([0.0, 0.78539816])
508511
509512
"""
510513

511-
arctan = DPNPUnaryFunc(
512-
"arctan",
514+
atan = DPNPUnaryFunc(
515+
"atan",
513516
ti._atan_result_type,
514517
ti._atan,
515518
_ATAN_DOCSTRING,
516519
mkl_fn_to_call="_mkl_atan_to_call",
517520
mkl_impl_fn="_atan",
518521
)
519522

520-
atan = arctan # atan is an alias for arctan
523+
arctan = atan # arctan is an alias for atan
521524

522525

523526
_ATAN2_DOCSTRING = """
524-
Calculates the inverse tangent of the quotient `x1_i/x2_i` for each element
525-
`x1_i` of the input array `x1` with the respective element `x2_i` of the
526-
input array `x2`. Each element-wise result is expressed in radians.
527+
Calculates the inverse tangent of the quotient :math:`x1_i/x2_i` for each
528+
element :math:`x1_i` of the input array `x1` with the respective element
529+
:math:`x2_i` of the input array `x2`.
527530
528-
Note that :obj:`dpnp.atan2` is an alias of :obj:`dpnp.arctan2`.
531+
Note that :obj:`dpnp.arctan2` is an alias of :obj:`dpnp.atan2`.
529532
This function is not defined for complex-valued arguments; for the so-called
530533
argument of complex values, use :obj:`dpnp.angle`.
531534
532-
For full documentation refer to :obj:`numpy.arctan2`.
535+
For full documentation refer to :obj:`numpy.atan2`.
533536
534537
Parameters
535538
----------
536539
x1 : {dpnp.ndarray, usm_ndarray, scalar}
537-
First input array, expected to have a real-valued floating-point
538-
data type.
539-
Both inputs `x1` and `x2` can not be scalars at the same time.
540+
First input array, expected to have a real-valued floating-point data type.
540541
x2 : {dpnp.ndarray, usm_ndarray, scalar}
541-
Second input array, also expected to have a real-valued
542-
floating-point data type.
543-
Both inputs `x1` and `x2` can not be scalars at the same time.
544-
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
545-
(which becomes the shape of the output).
542+
Second input array, also expected to have a real-valued floating-point data
543+
type.
546544
out : {None, dpnp.ndarray, usm_ndarray}, optional
547545
Output array to populate.
548546
Array must have the correct shape and the expected data type.
@@ -556,9 +554,9 @@ def _get_accumulation_res_dt(a, dtype):
556554
Returns
557555
-------
558556
out : dpnp.ndarray
559-
An array containing the inverse tangent of the quotient `x1`/`x2`.
560-
The returned array must have a real-valued floating-point data type
561-
determined by Type Promotion Rules.
557+
An array containing the inverse tangent of the quotient :math:`x1/x2`, in
558+
radians. The returned array must have a real-valued floating-point data
559+
type determined by Type Promotion Rules.
562560
563561
Limitations
564562
-----------
@@ -568,57 +566,66 @@ def _get_accumulation_res_dt(a, dtype):
568566
569567
See Also
570568
--------
571-
:obj:`dpnp.arctan` : Trigonometric inverse tangent, element-wise.
569+
:obj:`dpnp.atan` : Trigonometric inverse tangent, element-wise.
572570
:obj:`dpnp.tan` : Compute tangent element-wise.
573571
:obj:`dpnp.angle` : Return the angle of the complex argument.
574-
:obj:`dpnp.arcsin` : Trigonometric inverse sine, element-wise.
575-
:obj:`dpnp.arccos` : Trigonometric inverse cosine, element-wise.
576-
:obj:`dpnp.arctanh` : Inverse hyperbolic tangent, element-wise.
572+
:obj:`dpnp.asin` : Trigonometric inverse sine, element-wise.
573+
:obj:`dpnp.acos` : Trigonometric inverse cosine, element-wise.
574+
:obj:`dpnp.atanh` : Inverse hyperbolic tangent, element-wise.
575+
576+
Notes
577+
-----
578+
At least one of `x1` or `x2` must be an array.
579+
580+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
581+
(which becomes the shape of the output).
577582
578583
Examples
579584
--------
580585
>>> import dpnp as np
581586
>>> x1 = np.array([1., -1.])
582587
>>> x2 = np.array([0., 0.])
583-
>>> np.arctan2(x1, x2)
588+
>>> np.atan2(x1, x2)
584589
array([1.57079633, -1.57079633])
585590
586591
>>> x1 = np.array([0., 0., np.inf])
587592
>>> x2 = np.array([+0., -0., np.inf])
588-
>>> np.arctan2(x1, x2)
593+
>>> np.atan2(x1, x2)
589594
array([0.0 , 3.14159265, 0.78539816])
590595
591596
>>> x1 = np.array([-1, +1, +1, -1])
592597
>>> x2 = np.array([-1, -1, +1, +1])
593-
>>> np.arctan2(x1, x2) * 180 / np.pi
598+
>>> np.atan2(x1, x2) * 180 / np.pi
594599
array([-135., -45., 45., 135.])
595600
596601
"""
597602

598-
arctan2 = DPNPBinaryFunc(
599-
"arctan2",
603+
atan2 = DPNPBinaryFunc(
604+
"atan2",
600605
ti._atan2_result_type,
601606
ti._atan2,
602607
_ATAN2_DOCSTRING,
603608
mkl_fn_to_call="_mkl_atan2_to_call",
604609
mkl_impl_fn="_atan2",
605610
)
606611

607-
atan2 = arctan2 # atan2 is an alias for arctan2
612+
arctan2 = atan2 # arctan2 is an alias for atan2
608613

609614

610615
_ATANH_DOCSTRING = r"""
611-
Computes hyperbolic inverse tangent for each element `x_i` for input array `x`.
616+
Computes hyperbolic inverse tangent for each element :math:`x_i` for input
617+
array `x`.
612618
613-
The inverse of :obj:`dpnp.tanh`, so that if ``y = tanh(x)`` then ``x = arctanh(y)``.
614-
Note that :obj:`dpnp.atanh` is an alias of :obj:`dpnp.arctanh`.
619+
The inverse of :obj:`dpnp.tanh`, so that if :math:`y = tanh(x)` then
620+
:math:`x = atanh(y)`. Note that :obj:`dpnp.arctanh` is an alias of
621+
:obj:`dpnp.atanh`.
615622
616-
For full documentation refer to :obj:`numpy.arctanh`.
623+
For full documentation refer to :obj:`numpy.atanh`.
617624
618625
Parameters
619626
----------
620627
x : {dpnp.ndarray, usm_ndarray}
621-
Input array, expected to have numeric data type.
628+
Input array, expected to have a floating-point data type.
622629
out : {None, dpnp.ndarray, usm_ndarray}, optional
623630
Output array to populate.
624631
Array must have the correct shape and the expected data type.
@@ -632,9 +639,9 @@ def _get_accumulation_res_dt(a, dtype):
632639
Returns
633640
-------
634641
out : dpnp.ndarray
635-
An array containing the element-wise hyperbolic inverse tangent.
636-
The data type of the returned array is determined by
637-
the Type Promotion Rules.
642+
An array containing the element-wise inverse hyperbolic tangent, in
643+
radians. The data type of the returned array is determined by the Type
644+
Promotion Rules.
638645
639646
Limitations
640647
-----------
@@ -645,45 +652,46 @@ def _get_accumulation_res_dt(a, dtype):
645652
See Also
646653
--------
647654
:obj:`dpnp.tanh` : Hyperbolic tangent, element-wise.
648-
:obj:`dpnp.arcsinh` : Hyperbolic inverse sine, element-wise.
649-
:obj:`dpnp.arccosh` : Hyperbolic inverse cosine, element-wise.
650-
:obj:`dpnp.arctan` : Trigonometric inverse tangent, element-wise.
655+
:obj:`dpnp.asinh` : Hyperbolic inverse sine, element-wise.
656+
:obj:`dpnp.acosh` : Hyperbolic inverse cosine, element-wise.
657+
:obj:`dpnp.atan` : Trigonometric inverse tangent, element-wise.
651658
652659
Notes
653660
-----
654-
:obj:`dpnp.arctanh` is a multivalued function: for each `x` there are infinitely
655-
many numbers `z` such that ``tanh(z) = x``. The convention is to return the
656-
angle `z` whose real part lies in `[-\pi/2, \pi/2]`.
661+
:obj:`dpnp.atanh` is a multivalued function: for each `x` there are infinitely
662+
many numbers `z` such that :math:`tanh(z) = x`. The convention is to return the
663+
angle `z` whose the imaginary part lies in the interval :math:`[-\pi/2, \pi/2]`.
657664
658-
For real-valued input data types, :obj:`dpnp.arctanh` always returns real output.
659-
For each value that cannot be expressed as a real number or infinity, it yields
660-
``NaN``.
665+
For real-valued floating-point input data types, :obj:`dpnp.atanh` always
666+
returns real output. For each value that cannot be expressed as a real number
667+
or infinity, it yields ``NaN``.
661668
662-
For complex-valued input, :obj:`dpnp.arctanh` is a complex analytic function that
663-
has, by convention, the branch cuts `[-1, -\infty]` and `[1, \infty]` and is is continuous
664-
from above on the former and from below on the latter.
669+
For complex floating-point input data types, :obj:`dpnp.atanh` is a complex
670+
analytic function that has, by convention, the branch cuts
671+
:math:`(-\infty, -1]` and :math:`[1, \infty)` and is continuous from above on
672+
the former and from below on the latter.
665673
666-
The inverse hyperbolic tan is also known as :math:`atanh` or :math:`tanh^{-1}`.
674+
The inverse hyperbolic tangent is also known as :math:`tanh^{-1}`.
667675
668676
Examples
669677
--------
670678
>>> import dpnp as np
671679
>>> x = np.array([0, -0.5])
672-
>>> np.arctanh(x)
680+
>>> np.atanh(x)
673681
array([0.0, -0.54930614])
674682
675683
"""
676684

677-
arctanh = DPNPUnaryFunc(
678-
"arctanh",
685+
atanh = DPNPUnaryFunc(
686+
"atanh",
679687
ti._atanh_result_type,
680688
ti._atanh,
681689
_ATANH_DOCSTRING,
682690
mkl_fn_to_call="_mkl_atanh_to_call",
683691
mkl_impl_fn="_atanh",
684692
)
685693

686-
atanh = arctanh # atanh is an alias for arctanh
694+
arctanh = atanh # arctanh is an alias for atanh
687695

688696

689697
_CBRT_DOCSTRING = """

0 commit comments

Comments
 (0)