Add gram_eigh_full named overloads + fix Bijection ordering#225
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #225 +/- ##
==========================================
+ Coverage 71.00% 71.81% +0.81%
==========================================
Files 20 20
Lines 969 990 +21
==========================================
+ Hits 688 711 +23
+ Misses 281 279 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Add `TensorAlgebra.gram_eigh_full` and `TensorAlgebra.gram_eigh_full_with_pinv` overloads on `AbstractNamedDimsArray`, shape-matched to the existing `left_null_nameddims` / `svd_nameddims` patterns. Single-domain shorthand defers to the explicit (codomain, domain) form via `dimnames_setdiff`. Operator-entry overloads delegate to the named layer through a small `@eval` loop in `nameddimsoperator.jl` (parallel to the existing `MATRIX_FUNCTIONS` loop). - Add `similar_operator(prototype, codomain_axes)`: allocate an operator-shaped array whose domain mirrors the codomain axis lengths but gets fresh `randname`-generated dimension names. - Add `Base.one(::AbstractNamedDimsOperator)`, returning the identity operator on the same (codomain, domain). Previously lived in ITensorNetworksNext as a piracy-whitelisted method. - `[sources]` pins `TensorAlgebra` to the in-flight `mf/gram-eigh-full` branch until the upstream PR merges. - Tests cover named-array and operator entries for both gram factorizations, `similar_operator`, and `Base.one`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Tracks the upstream `TensorAlgebra.gram_eigh_full` change: the rank leg now sits first on `X` (`A ≈ X' * X`) and last on `Y` (`X * Y ≈ I` on the rank subspace), matching the Cholesky `A = U' * U` / standard Gram-matrix convention. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The `Base.one(::AbstractNamedDimsOperator)` definition matricized the operator and called `copyto!(_, I)` on the result, which only does the right thing for plain (non-symmetric) arrays — for `GradedArray`s and other symmetry-constrained operators, the identity is identity on each charge block, not on the matricized form. The cleaner factoring is a `one_map` / `similar_map` primitive in TensorAlgebra (acting on `AbstractArray` with a codomain/domain split) that NDA's named layer wraps, mirroring how the gram factorizations have a matrix layer in TA and a named entry here. Deferring both `similar_operator` and `Base.one` to a follow-up that designs that non-named interface, after testing on `GradedArray`s.
Match the signature of eigen: gram_eigh_full and gram_eigh_full_with_pinv on AbstractNamedDimsArray now require both dimnames_codomain and dimnames_domain, since their order matters.
Bijection previously stored its forward and reverse maps as separate Dicts, so codomain(b) and domain(b) iterated over different dicts with unrelated key orders, breaking positional pairing. Switch both fields to OrderedDict and base codomain/domain on a single canonical dict (codomain_to_domain) so successive calls return values in lock-step. Add docstrings with jldoctest examples to the four user-facing gram methods (AbstractNamedDimsArray and AbstractNamedDimsOperator overloads of gram_eigh_full / gram_eigh_full_with_pinv). The operator overloads use a const-string pattern with `@doc` inside the `@eval` loop so the loop body stays uniform while each method carries its own jldoctest. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The `[`TensorAlgebra.gram_eigh_full`](`ref`)` form was unresolvable from inside the NamedDimsArrays docs build, breaking it. Use unlinked code spans instead — the cross-package reference can be re-introduced later if we set up Documenter inventories. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
TensorAlgebra v0.9.3 (with gram_eigh_full / gram_eigh_full_with_pinv) is now registered in ITensorRegistry, so resolve against the registry. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
e1755eb to
6fcae13
Compare
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Rename one of the rank dimensions so `X * Y` contracts only on the shared codomain names `(i, k)` and leaves a (rank x rank) named identity, instead of reshaping parent storage by hand. Co-Authored-By: Claude Opus 4.7 (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
TensorAlgebra.gram_eigh_full/
gram_eigh_full_with_pinv(rank-first convention, matching thematrix/tensor layer in TensorAlgebra v0.9.3).
Bijection: previouslycodomain(b)anddomain(b)iteratedover independent
Dicts with unrelated key orders, breaking positionalpairing of the operator's codomain ↔ domain partition. Switch to
OrderedDictand base both accessors on one canonical dict sosuccessive calls return values in lock-step.