Skip to content
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

Standardize one-dimensional fancy indices #864

Open
crusaderky opened this issue Nov 28, 2024 · 2 comments
Open

Standardize one-dimensional fancy indices #864

crusaderky opened this issue Nov 28, 2024 · 2 comments

Comments

@crusaderky
Copy link

The current situation when an index is an array of ints or bools is very messy:

  • numpy blindly passes every unexpected object it finds to np.asarray, which makes it accept np.ndarray, lists, tuples, but also memoryviews and anything with an __array__ interface
  • Sparse accepts lists, tuples, or numpy arrays; other sparse arrays don't work
  • PyTorch won't accept numpy arrays of unsigned integers
  • PyTorch won't accept PyTorch arrays of integers with dtype other than the native int
  • JAX won't accept lists or tuples
  • dask won't accept tuples

I think the array API standard should define a reasonable common surface.

xref data-apis/array-api-compat#205 (comment)

NOTE: the much more complicated case of multiple fancy indices, e.g. a[[0, 1], [1, 2]] is out of scope for this issue.

@rgommers
Copy link
Member

Just a quick note that take is the standardized/uniform way of doing indexing with an integer array (xref gh-416 and the issue that PR links to).

You're completely right that it's very messy across libraries - it's just very hard, since we can't mandate that libraries stop doing something and break backwards compatible (or technically we can, but it'll probably just be ignored rather than implemented).

@crusaderky
Copy link
Author

Just a quick note that take is the standardized/uniform way of doing indexing with an integer array (xref gh-416 and the issue that PR links to).

I couldn't find put or anything similar though? How do you update along a fancy index?

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