Skip to content

Commit 971c06a

Browse files
authored
Add complex number support to log (#514)
1 parent f6c18b5 commit 971c06a

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

spec/API_specification/array_api/elementwise_functions.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,28 +1213,58 @@ def less_equal(x1: array, x2: array, /) -> array:
12131213
"""
12141214

12151215
def log(x: array, /) -> array:
1216-
"""
1217-
Calculates an implementation-dependent approximation to the natural (base ``e``) logarithm, having domain ``[0, +infinity]`` and codomain ``[-infinity, +infinity]``, for each element ``x_i`` of the input array ``x``.
1216+
r"""
1217+
Calculates an implementation-dependent approximation to the natural (base ``e``) logarithm for each element ``x_i`` of the input array ``x``.
12181218
12191219
**Special cases**
12201220
1221-
For floating-point operands,
1221+
For real-valued floating-point operands,
12221222
12231223
- If ``x_i`` is ``NaN``, the result is ``NaN``.
12241224
- If ``x_i`` is less than ``0``, the result is ``NaN``.
12251225
- If ``x_i`` is either ``+0`` or ``-0``, the result is ``-infinity``.
12261226
- If ``x_i`` is ``1``, the result is ``+0``.
12271227
- If ``x_i`` is ``+infinity``, the result is ``+infinity``.
12281228
1229+
For complex floating-point operands, let ``a = real(x_i)``, ``b = imag(x_i)``, and
1230+
1231+
- If ``a`` is ``-0`` and ``b`` is ``+0``, the result is ``-infinity + πj``.
1232+
- If ``a`` is ``+0`` and ``b`` is ``+0``, the result is ``-infinity + 0j``.
1233+
- If ``a`` is a finite number and ``b`` is ``+infinity``, the result is ``+infinity + πj/2``.
1234+
- If ``a`` is a finite number and ``b`` is ``NaN``, the result is ``NaN + NaN j``.
1235+
- If ``a`` is ``-infinity`` and ``b`` is a positive (i.e., greater than ``0``) finite number, the result is ``+infinity + πj``.
1236+
- If ``a`` is ``+infinity`` and ``b`` is a positive (i.e., greater than ``0``) finite number, the result is ``+infinity + 0j``.
1237+
- If ``a`` is ``-infinity`` and ``b`` is ``+infinity``, the result is ``+infinity + 3πj/4``.
1238+
- If ``a`` is ``+infinity`` and ``b`` is ``+infinity``, the result is ``+infinity + πj/4``.
1239+
- If ``a`` is either ``+infinity`` or ``-infinity`` and ``b`` is ``NaN``, the result is ``+infinity + NaN j``.
1240+
- If ``a`` is ``NaN`` and ``b`` is a finite number, the result is ``NaN + NaN j``.
1241+
- If ``a`` is ``NaN`` and ``b`` is ``+infinity``, the result is ``+infinity + NaN j``.
1242+
- If ``a`` is ``NaN`` and ``b`` is ``NaN``, the result is ``NaN + NaN j``.
1243+
1244+
.. note::
1245+
The natural logarithm of a complex number :math:`z` with polar coordinates :math:`(r,\theta)` equals :math:`\ln r + (\theta + 2n\pi)j` with principal value :math:`\ln r + \theta j`.
1246+
1247+
.. note::
1248+
For complex floating-point operands, ``log(conj(x))`` must equal ``conj(log(x))``.
1249+
1250+
.. note::
1251+
By convention, the branch cut of the natural logarithm is the negative real axis :math:`(-\infty, 0)`.
1252+
1253+
The natural logarithm is a continuous function from above the branch cut, taking into account the sign of the imaginary component.
1254+
1255+
Accordingly, for complex arguments, the function returns the natural logarithm in the range of a strip in the interval :math:`[-\pi j, +\pi j]` along the imaginary axis and mathematically unbounded along the real axis.
1256+
1257+
*Note: branch cuts have provisional status* (see :ref:`branch-cuts`).
1258+
12291259
Parameters
12301260
----------
12311261
x: array
1232-
input array. Should have a real-valued floating-point data type.
1262+
input array. Should have a floating-point data type.
12331263
12341264
Returns
12351265
-------
12361266
out: array
1237-
an array containing the evaluated natural logarithm for each element in ``x``. The returned array must have a real-valued floating-point data type determined by :ref:`type-promotion`.
1267+
an array containing the evaluated natural logarithm for each element in ``x``. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
12381268
"""
12391269

12401270
def log1p(x: array, /) -> array:

0 commit comments

Comments
 (0)