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

allow mixed -type comparisons #76

Closed
ev-br opened this issue Oct 30, 2024 · 2 comments
Closed

allow mixed -type comparisons #76

ev-br opened this issue Oct 30, 2024 · 2 comments

Comments

@ev-br
Copy link
Contributor

ev-br commented Oct 30, 2024

Somewhat similar to #51 (I've still no idea how to open an enhancement request against the standard itself).
The difference to #51 is that one can argue that int/int division is float; for comparisons however the limitation to matching dtypes serves no obvious purpose.

In [1]: import array_api_strict as xp

In [2]: xp.arange(5) < 3.0
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[2], line 1
----> 1 xp.arange(5) < 3.0

File ~/miniforge3/envs/scipy-dev/lib/python3.12/site-packages/array_api_strict/_array_object.py:717, in Array.__lt__(self, other)
    713 def __lt__(self: Array, other: Union[int, float, Array], /) -> Array:
    714     """
    715     Performs the operation __lt__.
    716     """
--> 717     other = self._check_allowed_dtypes(other, "real numeric", "__lt__")
    718     if other is NotImplemented:
    719         return other

File ~/miniforge3/envs/scipy-dev/lib/python3.12/site-packages/array_api_strict/_array_object.py:169, in Array._check_allowed_dtypes(self, other, dtype_category, op)
    167     raise TypeError(f"Only {dtype_category} dtypes are allowed in {op}")
    168 if isinstance(other, (int, complex, float, bool)):
--> 169     other = self._promote_scalar(other)
    170 elif isinstance(other, Array):
    171     if other.dtype not in _dtype_categories[dtype_category]:

File ~/miniforge3/envs/scipy-dev/lib/python3.12/site-packages/array_api_strict/_array_object.py:229, in Array._promote_scalar(self, scalar)
    227 elif isinstance(scalar, float):
    228     if self.dtype not in _floating_dtypes:
--> 229         raise TypeError(
    230             "Python float scalars can only be promoted with floating-point arrays."
    231         )
    232 elif isinstance(scalar, complex):
    233     if self.dtype not in _complex_floating_dtypes:

TypeError: Python float scalars can only be promoted with floating-point arrays.

@asmeurer
Copy link
Member

I've still no idea how to open an enhancement request against the standard itself

Issues for the standard itself should be opened at https://github.com/data-apis/array-api

for comparisons however the limitation to matching dtypes serves no obvious purpose.

FWIW, I agree with you. I brought this up at data-apis/array-api#819, and it was discussed at the consortium meetings, but the consensus there was that this should remain undefined data-apis/array-api#822 (which means the strict library will raise an error on it). Feel free to voice your concerns about this on that issue.

@asmeurer
Copy link
Member

Also XREF #50 #53 #54

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

No branches or pull requests

2 participants