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

fix: address missing complex type in applicable function signatures #905

Merged
merged 2 commits into from
Feb 26, 2025
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
38 changes: 19 additions & 19 deletions src/array_api_stubs/_2022_12/array_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ def __abs__(self: array, /) -> array:
Added complex data type support.
"""

def __add__(self: array, other: Union[int, float, array], /) -> array:
def __add__(self: array, other: Union[int, float, complex, array], /) -> array:
"""
Calculates the sum for each element of an array instance with the respective element of the array ``other``.

Parameters
----------
self: array
array instance (augend array). Should have a numeric data type.
other: Union[int, float, array]
other: Union[int, float, complex, array]
addend array. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type.

Returns
Expand Down Expand Up @@ -374,15 +374,15 @@ def __dlpack_device__(self: array, /) -> Tuple[Enum, int]:
ROCM = 10
"""

def __eq__(self: array, other: Union[int, float, bool, array], /) -> array:
def __eq__(self: array, other: Union[int, float, complex, bool, array], /) -> array:
r"""
Computes the truth value of ``self_i == other_i`` for each element of an array instance with the respective element of the array ``other``.

Parameters
----------
self: array
array instance. May have any data type.
other: Union[int, float, bool, array]
other: Union[int, float, complex, bool, array]
other array. Must be compatible with ``self`` (see :ref:`broadcasting`). May have any data type.

Returns
Expand All @@ -393,6 +393,9 @@ def __eq__(self: array, other: Union[int, float, bool, array], /) -> array:

.. note::
Element-wise results, including special cases, must equal the results returned by the equivalent element-wise function :func:`~array_api.equal`.

.. versionchanged:: 2022.12
Added complex data type support.
"""

def __float__(self: array, /) -> float:
Expand Down Expand Up @@ -746,7 +749,7 @@ def __mod__(self: array, other: Union[int, float, array], /) -> array:
Element-wise results, including special cases, must equal the results returned by the equivalent element-wise function :func:`~array_api.remainder`.
"""

def __mul__(self: array, other: Union[int, float, array], /) -> array:
def __mul__(self: array, other: Union[int, float, complex, array], /) -> array:
r"""
Calculates the product for each element of an array instance with the respective element of the array ``other``.

Expand All @@ -757,7 +760,7 @@ def __mul__(self: array, other: Union[int, float, array], /) -> array:
----------
self: array
array instance. Should have a numeric data type.
other: Union[int, float, array]
other: Union[int, float, complex, array]
other array. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type.

Returns
Expand All @@ -775,15 +778,15 @@ def __mul__(self: array, other: Union[int, float, array], /) -> array:
Added complex data type support.
"""

def __ne__(self: array, other: Union[int, float, bool, array], /) -> array:
def __ne__(self: array, other: Union[int, float, complex, 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``.

Parameters
----------
self: array
array instance. May have any data type.
other: Union[int, float, bool, array]
other: Union[int, float, complex, bool, array]
other array. Must be compatible with ``self`` (see :ref:`broadcasting`). May have any data type.

Returns
Expand Down Expand Up @@ -852,9 +855,6 @@ def __or__(self: array, other: Union[int, bool, array], /) -> array:

.. note::
Element-wise results must equal the results returned by the equivalent element-wise function :func:`~array_api.bitwise_or`.

.. versionchanged:: 2022.12
Added complex data type support.
"""

def __pos__(self: array, /) -> array:
Expand All @@ -876,7 +876,7 @@ def __pos__(self: array, /) -> array:
Element-wise results must equal the results returned by the equivalent element-wise function :func:`~array_api.positive`.
"""

def __pow__(self: array, other: Union[int, float, array], /) -> array:
def __pow__(self: array, other: Union[int, float, complex, array], /) -> array:
r"""
Calculates an implementation-dependent approximation of exponentiation by raising each element (the base) of an array instance to the power of ``other_i`` (the exponent), where ``other_i`` is the corresponding element of the array ``other``.

Expand All @@ -889,7 +889,7 @@ def __pow__(self: array, other: Union[int, float, array], /) -> array:
----------
self: array
array instance whose elements correspond to the exponentiation base. Should have a numeric data type.
other: Union[int, float, array]
other: Union[int, float, complex, array]
other array whose elements correspond to the exponentiation exponent. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type.

Returns
Expand Down Expand Up @@ -933,7 +933,7 @@ def __setitem__(
key: Union[
int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], array
],
value: Union[int, float, bool, array],
value: Union[int, float, complex, bool, array],
/,
) -> None:
"""
Expand All @@ -947,7 +947,7 @@ def __setitem__(
array instance.
key: Union[int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], array]
index key.
value: Union[int, float, bool, array]
value: Union[int, float, complex, bool, array]
value(s) to set. Must be compatible with ``self[key]`` (see :ref:`broadcasting`).


Expand All @@ -960,7 +960,7 @@ def __setitem__(
When ``value`` is an ``array`` of a different data type than ``self``, how values are cast to the data type of ``self`` is implementation defined.
"""

def __sub__(self: array, other: Union[int, float, array], /) -> array:
def __sub__(self: array, other: Union[int, float, complex, array], /) -> array:
"""
Calculates the difference for each element of an array instance with the respective element of the array ``other``.

Expand All @@ -970,7 +970,7 @@ def __sub__(self: array, other: Union[int, float, array], /) -> array:
----------
self: array
array instance (minuend array). Should have a numeric data type.
other: Union[int, float, array]
other: Union[int, float, complex, array]
subtrahend array. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type.

Returns
Expand All @@ -988,7 +988,7 @@ def __sub__(self: array, other: Union[int, float, array], /) -> array:
Added complex data type support.
"""

def __truediv__(self: array, other: Union[int, float, array], /) -> array:
def __truediv__(self: array, other: Union[int, float, complex, array], /) -> array:
r"""
Evaluates ``self_i / other_i`` for each element of an array instance with the respective element of the array ``other``.

Expand All @@ -1001,7 +1001,7 @@ def __truediv__(self: array, other: Union[int, float, array], /) -> array:
----------
self: array
array instance. Should have a numeric data type.
other: Union[int, float, array]
other: Union[int, float, complex, array]
other array. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type.

Returns
Expand Down
35 changes: 19 additions & 16 deletions src/array_api_stubs/_2023_12/array_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ def __abs__(self: array, /) -> array:
Added complex data type support.
"""

def __add__(self: array, other: Union[int, float, array], /) -> array:
def __add__(self: array, other: Union[int, float, complex, array], /) -> array:
"""
Calculates the sum for each element of an array instance with the respective element of the array ``other``.

Parameters
----------
self: array
array instance (augend array). Should have a numeric data type.
other: Union[int, float, array]
other: Union[int, float, complex, array]
addend array. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type.

Returns
Expand Down Expand Up @@ -494,15 +494,15 @@ def __dlpack_device__(self: array, /) -> Tuple[Enum, int]:
ONE_API = 14
"""

def __eq__(self: array, other: Union[int, float, bool, array], /) -> array:
def __eq__(self: array, other: Union[int, float, complex, bool, array], /) -> array:
r"""
Computes the truth value of ``self_i == other_i`` for each element of an array instance with the respective element of the array ``other``.

Parameters
----------
self: array
array instance. May have any data type.
other: Union[int, float, bool, array]
other: Union[int, float, complex, bool, array]
other array. Must be compatible with ``self`` (see :ref:`broadcasting`). May have any data type.

Returns
Expand All @@ -513,6 +513,9 @@ def __eq__(self: array, other: Union[int, float, bool, array], /) -> array:

.. note::
Element-wise results, including special cases, must equal the results returned by the equivalent element-wise function :func:`~array_api.equal`.

.. versionchanged:: 2022.12
Added complex data type support.
"""

def __float__(self: array, /) -> float:
Expand Down Expand Up @@ -893,7 +896,7 @@ def __mod__(self: array, other: Union[int, float, array], /) -> array:
Element-wise results, including special cases, must equal the results returned by the equivalent element-wise function :func:`~array_api.remainder`.
"""

def __mul__(self: array, other: Union[int, float, array], /) -> array:
def __mul__(self: array, other: Union[int, float, complex, array], /) -> array:
r"""
Calculates the product for each element of an array instance with the respective element of the array ``other``.

Expand All @@ -904,7 +907,7 @@ def __mul__(self: array, other: Union[int, float, array], /) -> array:
----------
self: array
array instance. Should have a numeric data type.
other: Union[int, float, array]
other: Union[int, float, complex, array]
other array. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type.

Returns
Expand All @@ -922,15 +925,15 @@ def __mul__(self: array, other: Union[int, float, array], /) -> array:
Added complex data type support.
"""

def __ne__(self: array, other: Union[int, float, bool, array], /) -> array:
def __ne__(self: array, other: Union[int, float, complex, 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``.

Parameters
----------
self: array
array instance. May have any data type.
other: Union[int, float, bool, array]
other: Union[int, float, complex, bool, array]
other array. Must be compatible with ``self`` (see :ref:`broadcasting`). May have any data type.

Returns
Expand Down Expand Up @@ -1024,7 +1027,7 @@ def __pos__(self: array, /) -> array:
Added complex data type support.
"""

def __pow__(self: array, other: Union[int, float, array], /) -> array:
def __pow__(self: array, other: Union[int, float, complex, array], /) -> array:
r"""
Calculates an implementation-dependent approximation of exponentiation by raising each element (the base) of an array instance to the power of ``other_i`` (the exponent), where ``other_i`` is the corresponding element of the array ``other``.

Expand All @@ -1037,7 +1040,7 @@ def __pow__(self: array, other: Union[int, float, array], /) -> array:
----------
self: array
array instance whose elements correspond to the exponentiation base. Should have a numeric data type.
other: Union[int, float, array]
other: Union[int, float, complex, array]
other array whose elements correspond to the exponentiation exponent. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type.

Returns
Expand Down Expand Up @@ -1081,7 +1084,7 @@ def __setitem__(
key: Union[
int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], array
],
value: Union[int, float, bool, array],
value: Union[int, float, complex, bool, array],
/,
) -> None:
"""
Expand All @@ -1095,7 +1098,7 @@ def __setitem__(
array instance.
key: Union[int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], array]
index key.
value: Union[int, float, bool, array]
value: Union[int, float, complex, bool, array]
value(s) to set. Must be compatible with ``self[key]`` (see :ref:`broadcasting`).


Expand All @@ -1108,7 +1111,7 @@ def __setitem__(
When ``value`` is an ``array`` of a different data type than ``self``, how values are cast to the data type of ``self`` is implementation defined.
"""

def __sub__(self: array, other: Union[int, float, array], /) -> array:
def __sub__(self: array, other: Union[int, float, complex, array], /) -> array:
"""
Calculates the difference for each element of an array instance with the respective element of the array ``other``.

Expand All @@ -1118,7 +1121,7 @@ def __sub__(self: array, other: Union[int, float, array], /) -> array:
----------
self: array
array instance (minuend array). Should have a numeric data type.
other: Union[int, float, array]
other: Union[int, float, complex, array]
subtrahend array. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type.

Returns
Expand All @@ -1136,7 +1139,7 @@ def __sub__(self: array, other: Union[int, float, array], /) -> array:
Added complex data type support.
"""

def __truediv__(self: array, other: Union[int, float, array], /) -> array:
def __truediv__(self: array, other: Union[int, float, complex, array], /) -> array:
r"""
Evaluates ``self_i / other_i`` for each element of an array instance with the respective element of the array ``other``.

Expand All @@ -1149,7 +1152,7 @@ def __truediv__(self: array, other: Union[int, float, array], /) -> array:
----------
self: array
array instance. Should have a numeric data type.
other: Union[int, float, array]
other: Union[int, float, complex, array]
other array. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type.

Returns
Expand Down
3 changes: 3 additions & 0 deletions src/array_api_stubs/_draft/array_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,9 @@ def __eq__(self: array, other: Union[int, float, complex, bool, array], /) -> ar

- Element-wise results, including special cases, must equal the results returned by the equivalent element-wise function :func:`~array_api.equal`.
- Comparison of arrays without a corresponding promotable data type (see :ref:`type-promotion`) is undefined and thus implementation-dependent.

.. versionchanged:: 2022.12
Added complex data type support.
"""

def __float__(self: array, /) -> float:
Expand Down