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

Wording for comparison operators implies complex number support for inequality operators #737

Closed
hameerabbasi opened this issue Jan 23, 2024 · 0 comments · Fixed by #736
Closed
Milestone

Comments

@hameerabbasi
Copy link
Contributor

hameerabbasi commented Jan 23, 2024

In https://data-apis.org/array-api/latest/API_specification/array_object.html#comparison-operators, it is stated:

Comparison operators should be defined for arrays having any data type.

Is that right? I don't think operator.{lt, gt, le, ge} should be defined for anything but real-valued datatypes. In particular, defining them for bool is weird and for complex* makes less sense (see, e.g., https://math.stackexchange.com/a/311341).

In addition, numpy.array_api doesn't support this either:

>>> xp.asarray(5 + 5j) < xp.asarray(-5 + 5j) 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/habbasi/miniforge3/envs/sparse-dev/lib/python3.11/site-packages/numpy/array_api/_array_object.py", line 631, in __lt__
    other = self._check_allowed_dtypes(other, "real numeric", "__lt__")
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/habbasi/miniforge3/envs/sparse-dev/lib/python3.11/site-packages/numpy/array_api/_array_object.py", line 142, in _check_allowed_dtypes
    raise TypeError(f"Only {dtype_category} dtypes are allowed in {op}")
TypeError: Only real numeric dtypes are allowed in __lt__

Note also that other operators state the datatypes for which there's actually a valid implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants