int / int division
ev-br opened this issue · 4 comments
ev-br commented
While it looks deliberate, still feels a bit too strict:
In [6]: import array_api_strict as xp
In [7]: a = xp.arange(3)
In [8]: a / 2
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[8], line 1
----> 1 a / 2
File ~/miniforge3/envs/scipy-dev/lib/python3.12/site-packages/array_api_strict/_array_object.py:801, in Array.__truediv__(self, other)
797 def __truediv__(self: Array, other: Union[float, Array], /) -> Array:
798 """
799 Performs the operation __truediv__.
800 """
--> 801 other = self._check_allowed_dtypes(other, "floating-point", "__truediv__")
802 if other is NotImplemented:
803 return other
File ~/miniforge3/envs/scipy-dev/lib/python3.12/site-packages/array_api_strict/_array_object.py:164, in Array._check_allowed_dtypes(self, other, dtype_category, op)
153 """
154 Helper function for operators to only allow specific input dtypes
155
(...)
160 return other
161 """
163 if self.dtype not in _dtype_categories[dtype_category]:
--> 164 raise TypeError(f"Only {dtype_category} dtypes are allowed in {op}")
165 if isinstance(other, (int, complex, float, bool)):
166 other = self._promote_scalar(other)
TypeError: Only floating-point dtypes are allowed in __truediv__
asmeurer commented
array-api-strict just follows the standard. The standard says this behavior is implementation defined, so strict errors on it. See https://data-apis.org/array-api/latest/API_specification/generated/array_api.array.__truediv__.html#array_api.array.__truediv__. If you want to change that you should open an issue against the standard, not array-api-strict.
ev-br commented
Thanks. Mind pointing to a channel to discuss the standard and see past discussions (I suspect this was discussed at length).
asmeurer commented
This was discussed at data-apis/array-api#361
asmeurer commented
But feel free to open an issue on the array-api repo if you feel this should be changed.