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 2 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 !

Comment on lines +364 to +366
# Vectorize the operation using boolean indexing
# For non-unique indices, take the last occurrence. This requires creating
# masks for x and y that create matching shapes.
Copy link
Member

Choose a reason for hiding this comment

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

can you add a docs note explaining this behaviour?

Comment on lines +357 to +359
# Work around lack of fancy indexing __setitem__ support in array-api-strict.
if (
is_array_api_strict_namespace(xp)
Copy link
Member

Choose a reason for hiding this comment

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

what do you think about changing this PR to instead do this?

  • try fancy indexing for all backends
  • fallback to this in the else case

In general I think unknown backends should go down the same path as array-api-strict if they have to.

@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
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