BUG: matmul fails with zero-length broadcast batch dimensions

オープン
#1,007 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

@nawaaaaaAaar がすでに取り組んでいます。

2026年10月22日 から。

  • #1012 @nawaaaaaAaar による — オープン

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
40/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
numpy, python
領域
backend, databases

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Python
スター
670
フォーク
167
平均マージ
3日 4時間
マージ済み PR(30日)
7

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

pydata/sparse のほかの issue

pydata/sparse の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。