Skip to content

int / int division #51

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

Closed
ev-br opened this issue Jul 10, 2024 · 4 comments
Closed

int / int division #51

ev-br opened this issue Jul 10, 2024 · 4 comments

Comments

@ev-br
Copy link
Member

ev-br commented Jul 10, 2024

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
Copy link
Member

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.

@asmeurer asmeurer closed this as not planned Won't fix, can't repro, duplicate, stale Jul 10, 2024
@ev-br
Copy link
Member Author

ev-br commented Jul 10, 2024

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

@asmeurer
Copy link
Member

This was discussed at data-apis/array-api#361

@asmeurer
Copy link
Member

But feel free to open an issue on the array-api repo if you feel this should be changed.

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