Closed
Description
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.
Metadata
Metadata
Assignees
Labels
No labels