Skip to content

ENH: at: add __setitem__ fancy indexing fallback #395

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

amacati
Copy link

@amacati amacati commented Aug 21, 2025

Fancy indexing is currently not supported for __setitem__, which blocks some PRs in scipy (scipy/scipy#23425).

As discussed in data-apis/array-api#864 (comment), all frameworks of the array api already implement this feature, but not necessarily in a consistent manner for duplicate indices. It is currently not part of the standard. This PR adds a workaround for array api strict to allow fancy indexing in xpx.at(x, ...).

@amacati amacati changed the title Add __setitem__ fancy indexing support for array-api-strict ENH: Add __setitem__ fancy indexing support for array-api-strict Aug 21, 2025
@lucascolley lucascolley added the enhancement New feature or request label Aug 22, 2025
Copy link
Member

@lucascolley lucascolley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @amacati !

@lucascolley lucascolley changed the title ENH: Add __setitem__ fancy indexing support for array-api-strict ENH: Add __setitem__ fancy indexing fallback Aug 22, 2025
@lucascolley lucascolley changed the title ENH: Add __setitem__ fancy indexing fallback ENH: at: add __setitem__ fancy indexing fallback Aug 22, 2025
@amacati
Copy link
Author

amacati commented Aug 23, 2025

The fallback is now implemented as error handling for __setitem__ and the behaviour for data races is documented. I also fixed the handling of negative indices and the assignment of scalar values.

One remaining concern is out-of-bounds indices. For anything negative or positive > len(x), the fallback currently does not throw an error. We would need to add value-based checks to catch that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants