Skip to content

Operand-driven diagonal algebra for the dense path - #224

Open
mtfishman wants to merge 13 commits into
mainfrom
mf/diagonal-algebra
Open

Operand-driven diagonal algebra for the dense path#224
mtfishman wants to merge 13 commits into
mainfrom
mf/diagonal-algebra

Conversation

@mtfishman

@mtfishman mtfishman commented Aug 20, 2026

Copy link
Copy Markdown
Member

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.

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.
@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.54167% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.17%. Comparing base (4360ee3) to head (c43b1bc).

Files with missing lines Patch % Lines
src/projectto.jl 82.60% 4 Missing ⚠️
src/similar_map.jl 84.21% 3 Missing ⚠️
ext/TensorAlgebraTensorKitExt.jl 86.66% 2 Missing ⚠️
src/matricize.jl 87.50% 2 Missing ⚠️
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     
Flag Coverage Δ
docs 21.91% <14.73%> (+0.02%) ⬆️

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.

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 mtfishman changed the title [WIP] Operand-driven diagonal algebra for the dense path Operand-driven diagonal algebra for the dense path Aug 21, 2026
@mtfishman
mtfishman marked this pull request as ready for review August 21, 2026 01:09
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