`diff` to allow Python scalar or 0d array `append` and `prepend`?

Aperta
#930 3 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
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python
Ambito
api

Direzione di ricerca

Inizia dalla specifica di diff collegata e confronta i suoi requisiti per append/prepend con il comportamento di array-api-strict mostrato negli esempi. Determina se gli scalari Python e gli array 0d debbano essere consentiti, quindi allinea la specifica e l’implementazione con test corrispondenti; l’issue non indica file di implementazione né test.

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

Descrizione

The specification of diff requires append and prepend to be arrays with the same shape as the first argument except along axis.

array-api-strict currently does not:

import array_api_strict as xp
xp.diff(xp.ones((2, 3)), append=xp.asarray(10), axis=0)
# Array([[0., 0., 0.],
#        [9., 9., 9.]], dtype=array_api_strict.float64)
xp.diff(xp.ones((2, 3)), append=xp.asarray(10), axis=1)
# Array([[0., 0., 9.],
#        [0., 0., 9.]], dtype=array_api_strict.float64)

Like NumPy, CuPy, and JAX, it expands the value as necessary (and follows the same promotion rules as other functions. I see that following the usual promotion rules was already tabled, so I won't bring that up again right now.)

This suggest that the operation can be well-defined, and I think it can be useful (e.g. prepend 0 and append shape[axis]). It would be even more useful to accept Python scalars, following the example of clip (which also requires array min/max to have the same type as x, but allows Python scalars). This would avoid requiring the user to do something like:

append = xp.full(x.shape[:axis] + (1,) + x.shape[axis:], append, dtype=xp.result_type(x, prepend, append))
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.