Skip to content

Commit 0e35d64

Browse files
committed
Update docstring of log, log10, log1p, and log2 functions to use math where applicable
1 parent bac9deb commit 0e35d64

File tree

1 file changed

+107
-41
lines changed

1 file changed

+107
-41
lines changed

dpnp/dpnp_iface_trigonometric.py

Lines changed: 107 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,15 +1355,15 @@ def cumlogsumexp(
13551355
)
13561356

13571357

1358-
_LOG_DOCSTRING = """
1359-
Computes the natural logarithm for each element `x_i` of input array `x`.
1358+
_LOG_DOCSTRING = r"""
1359+
Computes the natural logarithm for each element :math:`x_i` of input array `x`.
13601360
13611361
For full documentation refer to :obj:`numpy.log`.
13621362
13631363
Parameters
13641364
----------
13651365
x : {dpnp.ndarray, usm_ndarray}
1366-
Input array, expected to have numeric data type.
1366+
Input array, expected to have a floating-point data type.
13671367
out : {None, dpnp.ndarray, usm_ndarray}, optional
13681368
Output array to populate.
13691369
Array must have the correct shape and the expected data type.
@@ -1377,9 +1377,8 @@ def cumlogsumexp(
13771377
Returns
13781378
-------
13791379
out : dpnp.ndarray
1380-
An array containing the element-wise natural logarithm values.
1381-
The data type of the returned array is determined by the Type
1382-
Promotion Rules.
1380+
An array containing the element-wise natural logarithm values. The data
1381+
type of the returned array is determined by the Type Promotion Rules.
13831382
13841383
Limitations
13851384
-----------
@@ -1389,11 +1388,27 @@ def cumlogsumexp(
13891388
13901389
See Also
13911390
--------
1392-
:obj:`dpnp.log10` : Return the base 10 logarithm of the input array,
1393-
element-wise.
1394-
:obj:`dpnp.log2` : Base-2 logarithm of x.
1395-
:obj:`dpnp.log1p` : Return the natural logarithm of one plus
1396-
the input array, element-wise.
1391+
:obj:`dpnp.log10` : Calculate :math:`\log_{10}(x)`, element-wise.
1392+
:obj:`dpnp.log2` : Calculate :math:`\log_2(x)`, element-wise.
1393+
:obj:`dpnp.log1p` : Calculate :math:`\log(1 + x)`, element-wise.
1394+
1395+
Notes
1396+
-----
1397+
:obj:`dpnp.log` is a multivalued function: for each `x` there are infinitely
1398+
many numbers `z` such that :math:`e^z = x`. The convention is to return the `z`
1399+
whose the imaginary part lies in the interval :math:`[-\pi, \pi]`.
1400+
1401+
For real-valued floating-point input data types, :obj:`dpnp.log` always returns
1402+
real output. For each value that cannot be expressed as a real number or
1403+
nfinity, it yields ``NaN``.
1404+
1405+
For complex floating-point input data types, :obj:`dpnp.log` is a complex
1406+
analytic function that has, by convention, the branch cuts
1407+
:math:`(-\infty, 0)` and is continuous from above on it.
1408+
1409+
In the cases where the input has a negative real part and a very small negative
1410+
complex part (approaching 0), the result is so close to :math:`-\pi` that it
1411+
evaluates to exactly :math:`-\pi`.
13971412
13981413
Examples
13991414
--------
@@ -1414,15 +1429,15 @@ def cumlogsumexp(
14141429
)
14151430

14161431

1417-
_LOG10_DOCSTRING = """
1418-
Computes the base-10 logarithm for each element `x_i` of input array `x`.
1432+
_LOG10_DOCSTRING = r"""
1433+
Computes the base-10 logarithm for each element :math:`x_i` of input array `x`.
14191434
14201435
For full documentation refer to :obj:`numpy.log10`.
14211436
14221437
Parameters
14231438
----------
14241439
x : {dpnp.ndarray, usm_ndarray}
1425-
Input array, expected to have numeric data type.
1440+
Input array, expected to have a floating-point data type.
14261441
out : {None, dpnp.ndarray, usm_ndarray}, optional
14271442
Output array to populate.
14281443
Array must have the correct shape and the expected data type.
@@ -1436,9 +1451,8 @@ def cumlogsumexp(
14361451
Returns
14371452
-------
14381453
out : dpnp.ndarray
1439-
An array containing the element-wise base-10 logarithm of `x`.
1440-
The data type of the returned array is determined by the
1441-
Type Promotion Rules.
1454+
An array containing the element-wise base-10 logarithm of `x`. The data
1455+
type of the returned array is determined by the Type Promotion Rules.
14421456
14431457
Limitations
14441458
-----------
@@ -1448,9 +1462,27 @@ def cumlogsumexp(
14481462
14491463
See Also
14501464
--------
1451-
:obj:`dpnp.log` : Natural logarithm, element-wise.
1452-
:obj:`dpnp.log2` : Return the base-2 logarithm of the input array, element-wise.
1453-
:obj:`dpnp.log1p` : Return the natural logarithm of one plus the input array, element-wise.
1465+
:obj:`dpnp.log` : Calculate :math:`\log(x)`, element-wise.
1466+
:obj:`dpnp.log2` : Calculate :math:`\log_2(x)`, element-wise.
1467+
:obj:`dpnp.log1p` : Calculate :math:`\log(1 + x)`, element-wise.
1468+
1469+
Notes
1470+
-----
1471+
:obj:`dpnp.log10` is a multivalued function: for each `x` there are infinitely
1472+
many numbers `z` such that :math:`10^z = x`. The convention is to return the `z`
1473+
whose the imaginary part lies in the interval :math:`[-\pi, \pi]`.
1474+
1475+
For real-valued floating-point input data types, :obj:`dpnp.log10` always
1476+
returns real output. For each value that cannot be expressed as a real number
1477+
or nfinity, it yields ``NaN``.
1478+
1479+
For complex floating-point input data types, :obj:`dpnp.log10` is a complex
1480+
analytic function that has, by convention, the branch cuts
1481+
:math:`(-\infty, 0)` and is continuous from above on it.
1482+
1483+
In the cases where the input has a negative real part and a very small negative
1484+
complex part (approaching 0), the result is so close to :math:`-\pi` that it
1485+
evaluates to exactly :math:`-\pi`.
14541486
14551487
Examples
14561488
--------
@@ -1474,18 +1506,16 @@ def cumlogsumexp(
14741506
)
14751507

14761508

1477-
_LOG1P_DOCSTRING = """
1478-
Computes the natural logarithm of (1 + `x`) for each element `x_i` of input
1479-
array `x`.
1480-
1481-
This function calculates `log(1 + x)` more accurately for small values of `x`.
1509+
_LOG1P_DOCSTRING = r"""
1510+
Computes the natural logarithm of (1 + `x`) for each element :math:`x_i` of
1511+
input array `x`.
14821512
14831513
For full documentation refer to :obj:`numpy.log1p`.
14841514
14851515
Parameters
14861516
----------
14871517
x : {dpnp.ndarray, usm_ndarray}
1488-
Input array, expected to have numeric data type.
1518+
Input array, expected to have a floating-point data type.
14891519
out : {None, dpnp.ndarray, usm_ndarray}, optional
14901520
Output array to populate.
14911521
Array must have the correct shape and the expected data type.
@@ -1499,8 +1529,8 @@ def cumlogsumexp(
14991529
Returns
15001530
-------
15011531
out : dpnp.ndarray
1502-
An array containing the element-wise `log(1 + x)` results. The data type
1503-
of the returned array is determined by the Type Promotion Rules.
1532+
An array containing the element-wise :math:`\log(1 + x)` results. The data
1533+
type of the returned array is determined by the Type Promotion Rules.
15041534
15051535
Limitations
15061536
-----------
@@ -1510,10 +1540,29 @@ def cumlogsumexp(
15101540
15111541
See Also
15121542
--------
1513-
:obj:`dpnp.expm1` : ``exp(x) - 1``, the inverse of :obj:`dpnp.log1p`.
1514-
:obj:`dpnp.log` : Natural logarithm, element-wise.
1515-
:obj:`dpnp.log10` : Return the base 10 logarithm of the input array, element-wise.
1516-
:obj:`dpnp.log2` : Return the base-2 logarithm of the input array, element-wise.
1543+
:obj:`dpnp.expm1` : Calculate :math:`e^x - 1`, element-wise,
1544+
the inverse of :obj:`dpnp.log1p`.
1545+
:obj:`dpnp.log` : Calculate :math:`\log(x)`, element-wise.
1546+
:obj:`dpnp.log10` : Calculate :math:`\log_{10}(x)`, element-wise.
1547+
:obj:`dpnp.log2` : Calculate :math:`\log_2(x)`, element-wise.
1548+
1549+
Notes
1550+
-----
1551+
For real-valued floating-point input data types, :obj:`dpnp.log1p` provides
1552+
greater precision than :math:`\log(1 + x)` for `x` so small that
1553+
:math:`1 + x == 1`.
1554+
1555+
:obj:`dpnp.log1p` is a multivalued function: for each `x` there are infinitely
1556+
many numbers `z` such that :math:`e^z = 1 + x`. The convention is to return the
1557+
`z` whose the imaginary part lies in the interval :math:`[-\pi, \pi]`.
1558+
1559+
For real-valued floating-point input data types, :obj:`dpnp.log1p` always
1560+
returns real output. For each value that cannot be expressed as a real number
1561+
or nfinity, it yields ``NaN``.
1562+
1563+
For complex floating-point input data types, :obj:`dpnp.log1p` is a complex
1564+
analytic function that has, by convention, the branch cuts
1565+
:math:`(-\infty, 0)` and is continuous from above on it.
15171566
15181567
Examples
15191568
--------
@@ -1540,15 +1589,15 @@ def cumlogsumexp(
15401589
)
15411590

15421591

1543-
_LOG2_DOCSTRING = """
1544-
Computes the base-2 logarithm for each element `x_i` of input array `x`.
1592+
_LOG2_DOCSTRING = r"""
1593+
Computes the base-2 logarithm for each element :math:`x_i` of input array `x`.
15451594
15461595
For full documentation refer to :obj:`numpy.log2`.
15471596
15481597
Parameters
15491598
----------
15501599
x : {dpnp.ndarray, usm_ndarray}
1551-
Input array, expected to have numeric data type.
1600+
Input array, expected to have a floating-point data type.
15521601
out : {None, dpnp.ndarray, usm_ndarray}, optional
15531602
Output array to populate.
15541603
Array must have the correct shape and the expected data type.
@@ -1562,9 +1611,8 @@ def cumlogsumexp(
15621611
Returns
15631612
-------
15641613
out : dpnp.ndarray
1565-
An array containing the element-wise base-2 logarithm of `x`.
1566-
The data type of the returned array is determined by the
1567-
Type Promotion Rules.
1614+
An array containing the element-wise base-2 logarithm of `x`. The data type
1615+
of the returned array is determined by the Type Promotion Rules.
15681616
15691617
Limitations
15701618
-----------
@@ -1574,9 +1622,27 @@ def cumlogsumexp(
15741622
15751623
See Also
15761624
--------
1577-
:obj:`dpnp.log` : Natural logarithm, element-wise.
1578-
:obj:`dpnp.log10` : Return the base 10 logarithm of the input array, element-wise.
1579-
:obj:`dpnp.log1p` : Return the natural logarithm of one plus the input array, element-wise.
1625+
:obj:`dpnp.log` : Calculate :math:`\log(x)`, element-wise.
1626+
:obj:`dpnp.log10` : Calculate :math:`\log_{10}(x)`, element-wise.
1627+
:obj:`dpnp.log1p` : Calculate :math:`\log(1 + x)`, element-wise.
1628+
1629+
Notes
1630+
-----
1631+
:obj:`dpnp.log2` is a multivalued function: for each `x` there are infinitely
1632+
many numbers `z` such that :math:`2^z = x`. The convention is to return the `z`
1633+
whose the imaginary part lies in the interval :math:`[-\pi, \pi]`.
1634+
1635+
For real-valued floating-point input data types, :obj:`dpnp.log2` always
1636+
returns real output. For each value that cannot be expressed as a real number
1637+
or nfinity, it yields ``NaN``.
1638+
1639+
For complex floating-point input data types, :obj:`dpnp.log2` is a complex
1640+
analytic function that has, by convention, the branch cuts
1641+
:math:`(-\infty, 0)` and is continuous from above on it.
1642+
1643+
In the cases where the input has a negative real part and a very small negative
1644+
complex part (approaching 0), the result is so close to :math:`-\pi` that it
1645+
evaluates to exactly :math:`-\pi`.
15801646
15811647
Examples
15821648
--------

0 commit comments

Comments
 (0)