Operand-driven diagonal algebra for the graded path - #264
Merged
Conversation
Preserve the FusedGradedDiagonal type through the operations whose result is genuinely diagonal, and densify only where the result is not representable as a diagonal.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #264 +/- ##
==========================================
- Coverage 82.02% 76.96% -5.07%
==========================================
Files 38 37 -1
Lines 2504 2527 +23
==========================================
- Hits 2054 1945 -109
- Misses 450 582 +132
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:
|
Generalizes `pow_diag_safe!` to `AbstractFusedGradedMatrix`, delegating to the generic per-block kernel, so the `isdiag` fast path in `sqrth_invsqrth_safe` powers a dense-typed but runtime-diagonal graded matrix directly, not only a `FusedGradedDiagonal`.
Forwards in-place scaling through `matricize` to the fused level, so scaling a graded-backed array no longer falls to LinearAlgebra's element-wise fallback, which the scalar-indexing guard rejects.
Guards `diag` with a new `checksquare`, so a rectangular-block matrix errors instead of silently returning per-block diagonals on a mismatched axis. Also renames `isblockdiagonal` to `isblockdiag` to match `LinearAlgebra.isdiag`.
`FusedGradedMatrix{T,S,V}(undef, cod, dom)` allocates the buffer as `V(undef, total)`, so a caller can keep its own block backend instead of defaulting to `Vector{T}`.
Replace the `densematrix` helper with a `FusedGradedMatrix(d::FusedGradedDiagonal)` constructor that forwards the diagonal's block backend. A non-`{1,1}` matricize bends a leg fused storage cannot represent, so it now errors.
Factorizations return spectra at the matrix level and nothing wraps one into a `GradedArray`, so this was speculative. Wrapped diagonal spectra now contract through the generic dense allocation.
Eigendecomposition and hermitian projection require the graded-square precondition, not just matching dimensions. Also tightens the diagonal matricize error path and fills test gaps from review.
mtfishman
added a commit
to ITensor/TensorAlgebra.jl
that referenced
this pull request
Aug 21, 2026
## Summary Make diagonal algebra operand-driven: `Diagonal` is kept when the result is genuinely diagonal and densified otherwise. Also renames `[co]domain_axes` to `axes_[co]domain`. Companion to ITensor/GradedArrays.jl#264.
TensorAlgebra accumulates unregistered on main at 0.20.0-DEV, so the pin stays until the release PRs drop it.
mtfishman
marked this pull request as ready for review
August 21, 2026 16:53
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
Make diagonal algebra operand-driven on the graded path: keep a
FusedGradedDiagonalwhen the result is diagonal, densify otherwise. Companion to ITensor/TensorAlgebra.jl#224.