BUG: matmul fails with zero-length broadcast batch dimensions
Maintainers usually reply within 2 days
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 40/100
Research direction
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.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Python
- Stars
- 670
- Forks
- 167
- Avg merge
- 3d 4h
- Merged PRs (30d)
- 7
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from pydata/sparse
-
Bug: full einsum contractions upcast the dtype and count booleansPossibly taken @RaphaelFakhri claimed this 17 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 2 days
-
BUG: ufunc outer rejects Python scalar and sequence operandsPossibly taken @nawaaaaaAaar claimed this 29 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 2 days
-
Bug: slices with a negative step and a negative stop return wrong elementsPossibly taken @JoeyTan21 claimed this 19 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 75/100
pydata/sparse#1019 · 1 comment ·
Maintainers usually reply within 2 days
-
BUG: zero-length tensor contractions ignore requested output typesPossibly taken @nawaaaaaAaar claimed this 29 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
Maintainers usually reply within 2 days
-
BUG: inferred COO reshape dimensions lose integer precisionPossibly taken @nawaaaaaAaar claimed this 29 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 25/100
Maintainers usually reply within 2 days
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
abetlen/llama-cpp-python#2424 ·
Maintainers usually reply within 1 day
-
Bug IronPython Python 3
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
pyrevitlabs/pyRevit#4184 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 74/100
jqueryscript/awesome-claude-code#1009 ·
-
tests
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day