Skip to content

fix: mixed dense/sparse add!, scale! and inner - #75

Merged
lkdvos merged 1 commit into
mainfrom
mixed
Sep 10, 2026
Merged

fix: mixed dense/sparse add!, scale! and inner#75
lkdvos merged 1 commit into
mainfrom
mixed

Conversation

@lkdvos

@lkdvos lkdvos commented Sep 10, 2026

Copy link
Copy Markdown
Member

Fixes #74.

add!, scale!(y, x, α) and inner were only defined for dense/dense and sparse/sparse pairs; a mixed pair fell through to TensorKit's generic methods, which broadcast over the fused per-sector BlockMatrixes and hit a BoundsError for coupled sectors with an interior zero-length block.

  • one AbstractBlockTensorMap method each instead of the per-storage specializations, branching on issparse only where needed
  • dropped the dense-only axpy!/axpby!/dot/mul!: they reimplement TensorKit generics that forward here (the deleted mul! called SparseArrayKit._zero!, not a dependency)
  • add! into a sparse destination from a dense source fills it in; dropzeros! afterwards if needed
  • tests now run over all four storage pairs, plus a regression test on U₁ spaces (the trivial-sector spaces in that file never produce interior zero blocks)

🤖 Generated with Claude Code

These were only defined for `BlockTensorMap`/`BlockTensorMap` and
`SparseBlockTensorMap`/`SparseBlockTensorMap` pairs, so a mixed pair fell
through to TensorKit's generic `AbstractTensorMap` methods, which operate on
the fused per-sector `BlockMatrix`es. That path throws a `BoundsError` whenever
a coupled sector has an interior zero-length block, which is the normal
situation for a `SumSpace` with heterogeneous summands.

Replace the specializations by a single `AbstractBlockTensorMap` method each,
branching on `issparse` only where the cases differ. Also drop the dense-only
`axpy!`, `axpby!`, `dot` and `mul!`, which reimplement TensorKit generics that
forward to this layer (the deleted `mul!` referenced `SparseArrayKit._zero!`,
which is not a dependency of this package).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/linalg/linalg.jl 82.48% <ø> (+11.05%) ⬆️
src/tensors/vectorinterface.jl 97.36% <100.00%> (+5.30%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lkdvos

lkdvos commented Sep 10, 2026

Copy link
Copy Markdown
Member Author

Failures are unrelated and will be fixed elsewhere

@lkdvos
lkdvos merged commit 95d776a into main Sep 10, 2026
22 of 28 checks passed
@lkdvos
lkdvos deleted the mixed branch September 10, 2026 17:17
@lkdvos lkdvos mentioned this pull request Sep 11, 2026
lkdvos referenced this pull request Sep 11, 2026
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

add!(::BlockTensorMap, ::SparseBlockTensorMap) throws BoundsError: no mixed-storage method, and the fallback is unsound for zero-length blocks

1 participant