Reductions return NumPy objects eagerly but blosc2 arrays lazily
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
- Da chiarire
- Stato di attività
- Tranquilla
- Stack tecnologico
- python
- Ambito
- backend-api-design, data
Direzione di ricerca
Inizia tracciando i punti di ingresso delle riduzioni mostrati negli esempi: blosc2.sum, array .sum(), array .mean(), array .std(), blosc2.any() e lazyexpr(...).compute(). Confronta i relativi tipi restituiti con i requisiti dell’Array API per le riduzioni, quindi risolvi le questioni relative alle riduzioni complete, alle riduzioni parziali e alla deprecation prima di definire quale comportamento coerente e quali test costituirebbero il completamento del lavoro.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Reductions return NumPy objects through the eager path but blosc2 arrays through
the lazy one, so the same reduction has two different return types depending on
how it is spelled.
import numpy as np, blosc2
na = np.arange(100, dtype="f8").reshape(10, 10)
a, b = blosc2.asarray(na), blosc2.asarray(na * 2)
a.sum() # numpy.float64
blosc2.sum(a) # numpy.float64
a.sum(axis=0) # numpy.ndarray
(a + b).sum(axis=0) # numpy.ndarray
a.mean(), a.std() # numpy.float64
blosc2.any(a > 5) # numpy.bool
blosc2.lazyexpr("sum(a + b)", {"a": a, "b": b}).compute() # blosc2.NDArray, shape ()
blosc2.lazyexpr("sum(a + b, axis=0)", {"a": a, "b": b}).compute() # blosc2.NDArray, shape (10,)
(a + b).compute() # blosc2.NDArray (no reduction: stays blosc2)
The last group is the point: sum(a + b) written as a string expression gives a
blosc2.NDArray, while the same reduction written as (a + b).sum() gives a
numpy.float64. A caller cannot tell from the operation what they will get back.
Beyond the inconsistency, returning NumPy makes reductions a hole in the lazy
model — the result of a reduction over a 100 GB array is materialised eagerly
and cannot be fed back into a blosc2 pipeline without a round trip through
asarray.
Array API
The array API specification has reduction functions return arrays of the calling
namespace rather than language scalars, so blosc2.sum(a) yielding
numpy.float64 is non-compliant regardless of which way the inconsistency above
is resolved. Related to #466, but kept separate: that issue is a checklist
organised by failing test file, whereas this cuts across every reduction and
needs a decision before those boxes can be ticked consistently.
Open questions
- Which way to converge? Making everything return blosc2 arrays is the
array-API answer and the consistent one. Making the lazy path return NumPy
would also be consistent, but gives up the ability to keep a reduction lazy. - What about full (0-d) reductions? A full reduction is one number, and
wrapping it in a compressed container with a schunk, chunks and blocks costs
more than it returns — every subsequentfloat()pays a decompression. An
axis=-reduction is a different matter. A split rule ("arrays for partial,
scalars for full") would be pragmatic but is exactly what the array API
forbids. - Deprecation. This is a breaking change:
if a.sum() > 5,float(a.mean()),
passing a result to matplotlib or to a C API all change behaviour. It needs a
transition plan — a keyword, a namespace flag, or a release where both are
documented — rather than a flag day.
Raised as a follow-up in #457 (whose indexing bug is now fixed), and split out
because it is an API semantics decision rather than a defect.
- Lingua principale
- Python
- Stelle
- 211
- Fork
- 63
- Merge medio
- 1g 7h
- PR unite (30g)
- 5
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Blosc/python-blosc2
-
documentation sustain-2026
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
Blosc/python-blosc2#710 ·
-
documentation sustain-2026
Difficoltà 2/5 Mezza giornata Idoneità per principianti 74/100
Blosc/python-blosc2#651 · 1 commento ·
-
documentation good first issue sustain-2026
Difficoltà 2/5 Mezza giornata Idoneità per principianti 74/100
Blosc/python-blosc2#650 ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
Blosc/python-blosc2#693 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
Blosc/python-blosc2#664 · 1 commento ·
Tutte le issue di Blosc/python-blosc2
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100