RFC: add APIs for setting elements via an array of indices (i.e., put, put_along_axis, etc)

Aperta
#979 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
numpy, python, pytorch, tensorflow
Ambito
data

Direzione di ricerca

Inizia con la discussione sull’indicizzazione di array API in gh-177 e con il commento all’issue array-api collegato, quindi confronta le API elencate di NumPy, CuPy, JAX, PyTorch, TensorFlow, Dask e Ndonnx. Il lavoro è completo quando la proposta definisce un’API e una semantica consolidate e interoperabili per impostare gli elementi tramite indici, incluso il comportamento per gli array immutabili.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Copied and adapted from @kgryte's proposal at gh-177 per https://github.com/data-apis/array-api/issues/177#issuecomment-2883011323

Proposal

Add APIs for setting elements via an array of indices.

Motivation

Currently, the array API specification does not provide a direct means of setting a list of elements along an axis. Such operations are relatively common in NumPy usage either via "fancy indexing" or put APIs.

The main argument is that Indexing does not currently support providing a array of indices to index into an array. The principal reason for not supporting fancy indexing is . However, use of fancy indexing is relatively common in NumPy and similar libraries where dynamically setting rows/cols/values is possible and can be readily implemented. Another reason for not support fancy indexing mutation is that some libraries feature immutable arrays. array_api_extra.at.set demonstrates that it is often sufficient to mutate where possible and create a copy with the specified updates otherwise.

Background

The following table summarizes library implementations of such APIs:

op NumPy CuPy JAX.numpy Torch Tensorflow Dask.array Ndonnx
setting elements along axis put put put scatter_? scatter_nd? ?
setting elements over matching 1d slices put_along_axis put_along_axis put_along_axis scatter_? See pytorch/pytorch#120209. scatter_nd? ?

Discussion about these function in gh-177 concluded with https://github.com/data-apis/array-api/issues/177#issuecomment-1514155595, especially:

The JAX issue is most difficult to resolve (can be done, but a lot of work still to deal with read-only views or similar), but the lack of API uniformity makes this a hard sell in general.

This seems to be resolved. jax.numpy.put and jax.numpy.put_along_axis are implemented; they just return modifyied copies rather than mutating the array in place.

Lingua principale
Python
Stelle
281
Fork
52
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di data-apis/array-api

Tutte le issue di data-apis/array-api

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.