Skip to content

Commit 74eb089

Browse files
authored
Add complex number support to isfinite (#531)
1 parent f81cc32 commit 74eb089

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

spec/API_specification/array_api/elementwise_functions.py

+18-3
Original file line numberDiff line numberDiff line change
@@ -1026,17 +1026,32 @@ def imag(x: array, /) -> array:
10261026

10271027
def isfinite(x: array, /) -> array:
10281028
"""
1029-
Tests each element ``x_i`` of the input array ``x`` to determine if finite (i.e., not ``NaN`` and not equal to positive or negative infinity).
1029+
Tests each element ``x_i`` of the input array ``x`` to determine if finite.
1030+
1031+
**Special Cases**
1032+
1033+
For real-valued floating-point operands,
1034+
1035+
- If ``x_i`` is either ``+infinity`` or ``-infinity``, the result is ``False``.
1036+
- If ``x_i`` is ``NaN``, the result is ``False``.
1037+
- If ``x_i`` is a finite number, the result is ``True``.
1038+
1039+
For complex floating-point operands, let ``a = real(x_i)``, ``b = imag(x_i)``, and
1040+
1041+
- If ``a`` is ``NaN`` or ``b`` is ``NaN``, the result is ``False``.
1042+
- If ``a`` is either ``+infinity`` or ``-infinity`` and ``b`` is any value, the result is ``False``.
1043+
- If ``a`` is any value and ``b`` is either ``+infinity`` or ``-infinity``, the result is ``False``.
1044+
- If ``a`` is a finite number and ``b`` is a finite number, the result is ``True``.
10301045
10311046
Parameters
10321047
----------
10331048
x: array
1034-
input array. Should have a real-valued data type.
1049+
input array. Should have a numeric data type.
10351050
10361051
Returns
10371052
-------
10381053
out: array
1039-
an array containing test results. An element ``out_i`` is ``True`` if ``x_i`` is finite and ``False`` otherwise. The returned array must have a data type of ``bool``.
1054+
an array containing test results. The returned array must have a data type of ``bool``.
10401055
"""
10411056

10421057
def isinf(x: array, /) -> array:

0 commit comments

Comments
 (0)