data-apis / array-api-strict

Strict implementation of the Python array API (previously numpy.array_api)
http://data-apis.org/array-api-strict/
Other
7 stars 4 forks source link

int / int division #51

Closed ev-br closed 2 months ago

ev-br commented 2 months ago

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 2 months ago

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 2 months ago

Thanks. Mind pointing to a channel to discuss the standard and see past discussions (I suspect this was discussed at length).