RFC: assignment via integer array indexing

Open
#864 39 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
30/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
numpy, python, pytorch
Domain
data, tooling

Research direction

Start with the array-api-compat discussion linked in the issue and review the existing array indexing requirements across the named implementations. Define the common assignment semantics for one integer or boolean array index, including the proposed xp.put or equivalent surface; multiple fancy indices remain out of scope. Done means the standard resolves the listed compatibility differences with an agreed specification.

Written by the indexing model from the issue text.

Description

RFC

[EDIT] this issue is about the lack of xp.put or equivalent __setitem_ semantics for integar array indices. Read comments below.

[original post]
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 https://github.com/data-apis/array-api-compat/pull/205#discussion_r1861288136

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

Dominant language
Python
Stars
281
Forks
52
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from data-apis/array-api

All issues in data-apis/array-api

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.