Skip to content

fix: 4d sparse statistics crashed on an undefined accumulator (closes #812) - #814

Open
sotashimozono wants to merge 1 commit into
finch-tensor:mainfrom
sotashimozono:fix/galley-4d-dcs-init
Open

fix: 4d sparse statistics crashed on an undefined accumulator (closes #812)#814
sotashimozono wants to merge 1 commit into
finch-tensor:mainfrom
sotashimozono:fix/galley-4d-dcs-init

Conversation

@sotashimozono

@sotashimozono sotashimozono commented Aug 21, 2026

Copy link
Copy Markdown

The first @finch block of _4d_structure_to_dcs initializes d_ijk while the declared accumulator is d_ijkl:

d_ijkl = Scalar(0)
@finch begin
    d_ijk .= 0          # <- the 3d accumulator's name; UndefVarError on first touch

so DCStats could never be built for any rank-4 sparse input. Closes #812.

Reproduction, restated here so the PR stands alone:

using Finch
g = Finch.galley_scheduler()
A = fsprand(20, 20, 20, 20, 0.05)
B = Tensor(Dense(Dense(Element(0.0))), rand(20, 4))
compute(tensordot(lazy(A), lazy(B), ((4,), (1,))); ctx=g)
# before this patch: ERROR: UndefVarError: `d_ijk` not defined in local scope

The same error fires for nested SparseList formats too — this function is the statistics entry for every rank-4 sparse input, whatever the level types.

One-line fix, plus a regression test in the DCStats suite constructing statistics for a rank-4 sparse tensor.

Validated on this branch:

  • the reproduction above plans and computes, with values matching a dense reference;
  • a Dense(SparseList(SparseList(SparseList(Element)))) rank-4 operand plans, and the output preserves sparsity (stored count = the exact product support).

The generic rank >= 5 statistics path (subset enumeration) is a separate concern and not touched here.

@sotashimozono
sotashimozono force-pushed the fix/galley-4d-dcs-init branch from 2218b66 to 18e5f03 Compare August 21, 2026 08:45
…loses finch-tensor#812)

The first @finch block of _4d_structure_to_dcs initializes d_ijk while
the declared accumulator is d_ijkl — an UndefVarError on first touch, so
DCStats could never be built for any rank-4 sparse input (reproduced for
SparseCOO and for nested SparseList formats alike).

Adds a regression test constructing DCStats for a rank-4 sparse tensor.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sotashimozono
sotashimozono force-pushed the fix/galley-4d-dcs-init branch from 18e5f03 to e515a88 Compare August 21, 2026 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Galley DCStats: UndefVarError d_ijk in _4d_structure_to_dcs for sparse rank-4 inputs

1 participant