Operand-driven diagonal algebra for the dense path - #224
Open
mtfishman wants to merge 13 commits into
Open
Conversation
Preserve the Diagonal type through the operations whose result is genuinely diagonal: factorizations return the spectrum bare, unmatricize keeps the (1,1) endomorphism split, and single-contracted-leg Diagonal times Diagonal stays Diagonal. Densify only where the result is not representable as a Diagonal.
2 tasks
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #224 +/- ##
==========================================
+ Coverage 80.05% 80.17% +0.11%
==========================================
Files 28 28
Lines 1038 1054 +16
==========================================
+ Hits 831 845 +14
- Misses 207 209 +2
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:
|
1 task
The dense `unmatricize` reshaped without validating the split, so a mismatched codomain/domain boundary with the right total element count would reshape silently. Add a `check_input` size guard, matching the `Diagonal` and graded paths.
Replaces a runtime length branch in the two-`Diagonal` `contract` output allocation with dispatch on the perm tuples, matching the operand-driven convention. Also drops the `Diagonal`-specific `unmatricize` `check_input`, whose general-looking signature only admitted the `{1,1}` split, in favor of the generic size check.
A dense `unmatricize` is a `reshape`, so it only needs the total element count to match, not the per-side codomain/domain split. The earlier per-side check rejected valid regroupings such as `unmatricize(m, (), axes)`.
`promote_type` returns the plain element type, but a product accumulation can widen (for example `Bool` inputs accumulate to `Int`), so model it with `Base.promote_op(matprod, ...)` as matmul does.
The helper is only ever called with `Diagonal` operands and reads `a1.diag`, so annotate `a1::Diagonal` to make that explicit.
The output type is a function of both operands, so take `a1::Diagonal, a2::Diagonal` even though the allocation reads only the first.
Re-opens 0.20.0 as a prerelease accumulator (its standalone registration was removed), so these changes ship in a single 0.20.0 release rather than a separate patch.
The matricized input's rows must be the fused codomain and its columns the fused domain, matching what `matricize` produces, so a matrix with the right element count but the wrong split is rejected instead of reshaped silently.
Mechanical rename matching the `axes_codomain`/`axes_domain` naming used across the ecosystem.
The standalone 0.20.0 registration was pulled, so this ships as the 0.20.0 release (registered manually, since the version matches main).
mtfishman
marked this pull request as ready for review
August 21, 2026 01:09
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:
Diagonalis kept when the result is genuinely diagonal and densified otherwise. Also renames[co]domain_axestoaxes_[co]domain. Companion to ITensor/GradedArrays.jl#264.