Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add complex number support to not_equal #529

Merged
merged 1 commit into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions spec/API_specification/array_api/array_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,26 @@ def __ne__(self: array, other: Union[int, float, bool, array], /) -> array:
"""
Computes the truth value of ``self_i != other_i`` for each element of an array instance with the respective element of the array ``other``.

**Special Cases**

Let ``self`` equal ``x1`` and ``other`` equal ``x2``.

For real-valued floating-point operands,

- If ``x1_i`` is ``NaN`` or ``x2_i`` is ``NaN``, the result is ``True``.
- If ``x1_i`` is ``+infinity`` and ``x2_i`` is ``-infinity``, the result is ``True``.
- If ``x1_i`` is ``-infinity`` and ``x2_i`` is ``+infinity``, the result is ``True``.
- If ``x1_i`` is a finite number, ``x2_i`` is a finite number, and ``x1_i`` does not equal ``x2_i``, the result is ``True``.
- In the remaining cases, the result is ``False``.

For complex floating-point operands, let ``a = real(x1_i)``, ``b = imag(x1_i)``, ``c = real(x2_i)``, ``d = imag(x2_i)``, and

- If ``a``, ``b``, ``c``, or ``d`` is ``NaN``, the result is ``True``.
- In the remaining cases, the result is the logical OR of the equality comparison between the real values ``a`` and ``c`` (real components) and between the real values ``b`` and ``d`` (imaginary components), as described above for real-valued floating-point operands (i.e., ``a != c OR b != d``).

.. note::
For discussion of complex number equality, see :ref:`complex-numbers`.

Parameters
----------
self: array
Expand Down
18 changes: 18 additions & 0 deletions spec/API_specification/array_api/elementwise_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,24 @@ def not_equal(x1: array, x2: array, /) -> array:
"""
Computes the truth value of ``x1_i != x2_i`` for each element ``x1_i`` of the input array ``x1`` with the respective element ``x2_i`` of the input array ``x2``.

**Special Cases**

For real-valued floating-point operands,

- If ``x1_i`` is ``NaN`` or ``x2_i`` is ``NaN``, the result is ``True``.
- If ``x1_i`` is ``+infinity`` and ``x2_i`` is ``-infinity``, the result is ``True``.
- If ``x1_i`` is ``-infinity`` and ``x2_i`` is ``+infinity``, the result is ``True``.
- If ``x1_i`` is a finite number, ``x2_i`` is a finite number, and ``x1_i`` does not equal ``x2_i``, the result is ``True``.
- In the remaining cases, the result is ``False``.

For complex floating-point operands, let ``a = real(x1_i)``, ``b = imag(x1_i)``, ``c = real(x2_i)``, ``d = imag(x2_i)``, and

- If ``a``, ``b``, ``c``, or ``d`` is ``NaN``, the result is ``True``.
- In the remaining cases, the result is the logical OR of the equality comparison between the real values ``a`` and ``c`` (real components) and between the real values ``b`` and ``d`` (imaginary components), as described above for real-valued floating-point operands (i.e., ``a != c OR b != d``).

.. note::
For discussion of complex number equality, see :ref:`complex-numbers`.

Parameters
----------
x1: array
Expand Down