Concatenate graded arrays through TensorAlgebra#214
Merged
Conversation
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 Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
Base.catanddirectsumfor abelian graded arrays by hooking into the concatenation interface in TensorAlgebra (ITensor/TensorAlgebra.jl#210).cat_axison 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.AbelianBlocksbecomes anAbstractSparseArrayexposing the stored (symmetry-allowed) blocks, so the placement visits only those blocks and never touches a forbidden position. The defaultdirectsumis plain concatenation, so it shares this path.