Skip to content

Commit 0e89b5f

Browse files
authored
Add complex number support to log2 (#535)
1 parent 28e6041 commit 0e89b5f

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

spec/API_specification/array_api/elementwise_functions.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,28 +1323,38 @@ def log1p(x: array, /) -> array:
13231323
"""
13241324

13251325
def log2(x: array, /) -> array:
1326-
"""
1327-
Calculates an implementation-dependent approximation to the base ``2`` logarithm, having domain ``[0, +infinity]`` and codomain ``[-infinity, +infinity]``, for each element ``x_i`` of the input array ``x``.
1326+
r"""
1327+
Calculates an implementation-dependent approximation to the base ``2`` logarithm for each element ``x_i`` of the input array ``x``.
13281328
13291329
**Special cases**
13301330
1331-
For floating-point operands,
1331+
For real-valued floating-point operands,
13321332
13331333
- If ``x_i`` is ``NaN``, the result is ``NaN``.
13341334
- If ``x_i`` is less than ``0``, the result is ``NaN``.
13351335
- If ``x_i`` is either ``+0`` or ``-0``, the result is ``-infinity``.
13361336
- If ``x_i`` is ``1``, the result is ``+0``.
13371337
- If ``x_i`` is ``+infinity``, the result is ``+infinity``.
13381338
1339+
For complex floating-point operands, special cases must be handled as if the operation is implemented using the standard change of base formula
1340+
1341+
.. math::
1342+
\log_{2} x = \frac{\log_{e} x}{\log_{e} 2}
1343+
1344+
where :math:`\log_{e}` is the natural logarithm, as implemented by :func:`~array_api.log`.
1345+
1346+
.. note::
1347+
For complex floating-point operands, ``log2(conj(x))`` must equal ``conj(log2(x))``.
1348+
13391349
Parameters
13401350
----------
13411351
x: array
1342-
input array. Should have a real-valued floating-point data type.
1352+
input array. Should have a floating-point data type.
13431353
13441354
Returns
13451355
-------
13461356
out: array
1347-
an array containing the evaluated base ``2`` logarithm for each element in ``x``. The returned array must have a real-valued floating-point data type determined by :ref:`type-promotion`.
1357+
an array containing the evaluated base ``2`` logarithm for each element in ``x``. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
13481358
"""
13491359

13501360
def log10(x: array, /) -> array:

0 commit comments

Comments
 (0)