BUG: matmul fails with zero-length broadcast batch dimensions

Aperta
#1,007 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.

  • #1012 di @nawaaaaaAaar — aperta

Valutazione

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

Direzione di ricerca

Start in the recursive implementation of sparse.matmul and compare its batch handling with NumPy broadcasting for zero-sized dimensions. Reproduce the two examples in the issue, then add regression coverage for the listed rank, broadcasting, input type, dtype, and shape cases. Done when valid cases return NumPy-compatible shapes and invalid shapes still fail appropriately.

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

Descrizione

Bug

Batched sparse.matmul fails when a broadcast batch dimension is zero.

Reproduced on main at d63255057744331b96626a1f1c24504b3a3783cd.

import numpy as np
import sparse

a = sparse.COO.from_numpy(np.zeros((0, 2, 3)))
b = sparse.COO.from_numpy(np.zeros((0, 3, 4)))
sparse.matmul(a, b)
# ValueError: At least one array required.

a = sparse.COO.from_numpy(np.zeros((1, 2, 3)))
sparse.matmul(a, b)
# IndexError: Index is not smaller than dimension 0 >= 0

NumPy returns shape (0, 2, 4) in both cases. The recursive implementation either stacks an empty result list or iterates using max(1, 0), rather than the broadcast result size zero.

A focused empty-batch path and regression coverage are ready. The matrix exercises differing ranks, zero/singleton broadcasting, COO/GCXS/mixed dense inputs, dtype promotion and invalid contraction/batch shapes. Thirty-two new cases fail before the production change.

This is a different path from zero-length contracted axes in tensordot: the contracted dimension here is three and the failure happens in batch recursion.

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.