Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

`asarray` with `copy=False` produces new array?

Aperta
#1,009 3 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
50/100
Tipo di issue
Documentazione
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
python
Ambito
documentation

Direzione di ricerca

Inizia confrontando la formulazione della specifica per asarray e astype con gli esempi nell’issue, quindi verifica come il testo normativo esistente tratta l’identità dell’oggetto rispetto alla memoria condivisa. Il lavoro è completato quando è stato chiarito se copy=False richiede di restituire lo stesso oggetto array e la specifica è resa non ambigua.

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

Descrizione

This may be related to gh-788, but I think it is distinct.

The behavior of astype with copy=False is:

If False and the specified dtype matches the data type of the input array, the input array must be returned...

So this passes:

import array_api_strict as xp
dtype = xp.int64
x = xp.asarray([1, 2, 3], dtype=dtype)

y = xp.astype(x, dtype, copy=False)
assert y is x 

For asarray:

If False, the function must never copy for input which supports the buffer protocol...

Here, it is not explicit whether "must never copy" refers to the array object itself or the underlying memory buffer. In any case, array_api_strict creates a new array object, so the equivalent assertion fails.

y = xp.asarray(x, dtype=dtype, copy=False)
assert y is x 
# AssertionError: 

Is "must never copy" intended to allow the returned object to be different from the input? Either way, should it be more explicit?
If it helps, NumPy, PyTorch, JAX, and Dask all pass both assertions.

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.