Skip to content

Concatenate graded arrays through TensorAlgebra#214

Merged
mtfishman merged 10 commits into
mainfrom
mf/directsum-cat
Jul 14, 2026
Merged

Concatenate graded arrays through TensorAlgebra#214
mtfishman merged 10 commits into
mainfrom
mf/directsum-cat

Conversation

@mtfishman

@mtfishman mtfishman commented Jul 13, 2026

Copy link
Copy Markdown
Member

Summary

Adds Base.cat and directsum for abelian graded arrays by hooking into the concatenation interface in TensorAlgebra (ITensor/TensorAlgebra.jl#210). cat_axis on graded ranges block-appends in concat-order, keeping the argument sectors in order rather than merging or sorting them, and materialization places each argument's blocks into the destination's diagonal hyper-block. AbelianBlocks becomes an AbstractSparseArray exposing the stored (symmetry-allowed) blocks, so the placement visits only those blocks and never touches a forbidden position. The default directsum is plain concatenation, so it shares this path.

Adds `cat`/`directsum` support for `AbelianGradedArray` by hooking into TensorAlgebra's concatenation machinery. `cat_axis` on graded ranges block-appends in concat-order, keeping sectors in order rather than merging or sorting them, and materialization places each argument's blocks into the destination's diagonal hyper-block. `AbelianBlocks` gains the block-container `zero!` and a sector-aware block assignment that the concatenation path needs, restricted to the stored (symmetry-allowed) blocks. The default `directsum` is a plain `cat`, so it shares this path.

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

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.47619% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.60%. Comparing base (c49ff57) to head (a4398d2).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/abeliangradedarray.jl 83.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #214      +/-   ##
==========================================
+ Coverage   84.35%   84.60%   +0.24%     
==========================================
  Files          26       27       +1     
  Lines        2001     2013      +12     
==========================================
+ Hits         1688     1703      +15     
+ Misses        313      310       -3     
Flag Coverage Δ
docs 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

mtfishman and others added 9 commits July 13, 2026 20:55
…abelian

`AbelianBlocks` (the `blocks(::AbelianGradedArray)` view) is now an `AbstractSparseArray` implementing the full SparseArraysBase interface (`eachstoredindex`, `storedvalues`, `isstored`, and get/set for both stored and unstored indices), with the methods living next to the type definition. The concatenation machinery's `zero!` and offset range-assignment then fall out of the generic sparse map/assignment path, visiting only the stored (symmetry-allowed) blocks, so the bespoke `zero!` and range `setindex!` in `cat.jl` are gone. Reading an unstored block now returns a zero block rather than erroring, matching sparse-array (and BlockSparseArrays `blocks`) semantics.

The graded cat entry points (`similar`, `copyto!`, and `Base._cat`) are narrowed from `AbstractGradedStyle`/`AbstractGradedArray` to `AbelianGradedStyle`/`AbelianGradedArray`. The concat-order block-append is only a valid direct sum for `AbelianGradedArray`. Fused graded arrays direct-sum onto a merged, rotated basis and need a different implementation, so they are deliberately no longer routed through this path.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
For an `AbelianGradedArray`, which allocates exactly its symmetry-allowed blocks, an unstored block index is a forbidden block rather than a lazily-omitted zero. `getunstoredindex`/`setunstoredindex!` on `AbelianBlocks` now error, so reading or writing a forbidden block through `blocks(a)` fails loudly, as it did before `AbelianBlocks` became an `AbstractSparseArray`. The concatenation path never hits these (the destination pre-allocates all allowed blocks, so the assignment only touches stored indices).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Follows the TensorAlgebra change that replaces the lazy `Concatenated` wrapper with a function interface (ITensor/TensorAlgebra.jl#210). The abelian graded concatenation now overloads `TensorAlgebra.cat_similar(::AbelianGradedStyle, ...)` for the destination and `TensorAlgebra.cat_copyto!(dest, ::AbelianGradedStyle, ...)` for the block placement, in place of the previous `Base.similar`/`Base.copyto!` methods on `Concatenated{<:AbelianGradedStyle}`. Behavior is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Cut the comments to the non-obvious rationale (concat-order semantics, why fused graded arrays are excluded, why the destination override is needed, and why the block placement is safe on the sparse block container). Drops a stale reference to the removed `directsum_style`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Use concatenate! in place of cat! for the inner block-container placement.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Overload the style-first `TensorAlgebra.concatenate!(::AbelianGradedStyle, dest, dims, args...)`
placement hook instead of the former `cat_copyto!`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Follow the placement-hook change to destination dispatch: overload
`concatenate!(dest::AbelianGradedArray, dims, args...)` instead of on the
style. Allocation still overloads `cat_similar` on `AbelianGradedStyle`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Follow the `directsum(dims, as...)` signature change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
TensorAlgebra 0.17.5 and SparseArraysBase 0.10.8 are registered, so resolve
them from the registry.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mtfishman mtfishman changed the title [WIP] Concatenate graded arrays through TensorAlgebra Concatenate graded arrays through TensorAlgebra Jul 14, 2026
@mtfishman mtfishman marked this pull request as ready for review July 14, 2026 18:25
@mtfishman mtfishman enabled auto-merge (squash) July 14, 2026 18:25
@mtfishman mtfishman merged commit 60e6e09 into main Jul 14, 2026
25 of 28 checks passed
@mtfishman mtfishman deleted the mf/directsum-cat branch July 14, 2026 18:36
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.

1 participant