BUG: zero-length tensor contractions ignore requested output types

Aperta
#1,005 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@nawaaaaaAaar ci sta già lavorando.

Dal 22/10/2026.

  • #1010 di @nawaaaaaAaar — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
numpy, python
Ambito
data

Direzione di ricerca

Start by reading the zero-contraction fast path in sparse.tensordot and the existing tests for tensor contractions. Add regression coverage for COO, GCXS and mixed dense inputs across the supported return_type values; the issue says a 32-case matrix reproduces the behavior. Done means output type, values, shape and dtype match the requested type and NumPy expectations.

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

Descrizione

Bug

The zero-contraction fast path in sparse.tensordot ignores return_type and does not preserve the normal default GCXS output selection.

Reproduced on main at d63255057744331b96626a1f1c24504b3a3783cd.

import numpy as np
import sparse

a = sparse.COO.from_numpy(np.empty((2, 0), dtype=np.float32))
b = sparse.COO.from_numpy(np.empty((0, 3), dtype=np.float32))
result = sparse.tensordot(a, b, axes=1, return_type=np.ndarray)
assert isinstance(result, np.ndarray)  # fails: result is COO

Conversely, mixing a dense operand with a sparse one returns an ndarray even when return_type=COO or GCXS is explicitly requested. Two GCXS operands also return COO by default on this fast path, unlike non-empty contractions.

A fix and a 32-case regression matrix are ready. The matrix covers COO, GCXS and mixed dense inputs and all supported explicit output types; 19 cases fail before the production change. Numerical values, output shapes and dtype are compared with NumPy.

This is an AI-assisted bug investigation with locally executed reproductions and tests. No assignment is requested.

Lingua principale
Python
Stelle
670
Fork
167
Merge medio
3g 4h
PR unite (30g)
7

Preparare l'ambiente

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 pydata/sparse

Tutte le issue di pydata/sparse

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.