-
Notifications
You must be signed in to change notification settings - Fork 11
BUG: fix __setitem__ for invalid dtype combinations #157
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
Conversation
with this branch:
and
Which looks like a scipy bug with an inplace assignment of uint64 into a uint8 array. WDYT @mdhaber?
|
Huh. The scipy issue is actually this:
which is inherited by array-api-strict:
And this is actually deliberate, both in numpy (https://numpy.org/doc/2.1/reference/generated/numpy.sum.html) and array-api-strict (https://data-apis.org/array-api/2024.12/API_specification/generated/array_api.sum.html#sum). So it does look like an issue in |
…ests This tests does this: `vectorized_filter(input, xp.sum, output)`, with output being `xp.empty_like(input)`. This is problematic for short integers because - the output of xp.sum(int8_array) is int64 (the default int dtype), and - internally, vectorized_filter does roughly, `output[some_indices] = xp.sum(input[some_indices])` So what happens here is that the output of the `sum` in the r.h.s. gets silently downcast to the dtype of the l.h.s. by `__setitem__`. This kind of sort of works in many array libraries, but is technically unspecified by the Array API standard. And indeed this starts failing with array-api-strict in data-apis/array-api-strict#157 Thus, a test only change to make downcasting explicit.
Do not allow e.g. >>> a = xp.asarray([1, 2, 3]) >>> a[0] = 3.5 # cannot type-promote a float scalar and an int array >>> a[0] = xp.asarray(3.5) # cannot integer and float arrays cannot be promoted together
Do not allow e.g.
intends to close #136
TODO: