Skip to content

Add gram_eigh_full named overloads + fix Bijection ordering#225

Merged
mtfishman merged 9 commits into
mainfrom
mf/gram-eigh-full
May 30, 2026
Merged

Add gram_eigh_full named overloads + fix Bijection ordering#225
mtfishman merged 9 commits into
mainfrom
mf/gram-eigh-full

Conversation

@mtfishman

@mtfishman mtfishman commented May 28, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds named-array and operator overloads of TensorAlgebra.gram_eigh_full
    / gram_eigh_full_with_pinv (rank-first convention, matching the
    matrix/tensor layer in TensorAlgebra v0.9.3).
  • Fixes Bijection: previously codomain(b) and domain(b) iterated
    over independent Dicts with unrelated key orders, breaking positional
    pairing of the operator's codomain ↔ domain partition. Switch to
    OrderedDict and base both accessors on one canonical dict so
    successive calls return values in lock-step.

@codecov

codecov Bot commented May 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.81%. Comparing base (ba2de44) to head (3603311).

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     
Flag Coverage Δ
docs 23.92% <100.00%> (+6.22%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.

mtfishman and others added 7 commits May 29, 2026 18:04
- 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>
@mtfishman mtfishman force-pushed the mf/gram-eigh-full branch from e1755eb to 6fcae13 Compare May 29, 2026 22:47
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mtfishman mtfishman changed the title Lift named gram_eigh_full, similar_operator, Base.one of operator Add gram_eigh_full named overloads + fix Bijection ordering May 30, 2026
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>
@mtfishman mtfishman enabled auto-merge (squash) May 30, 2026 00:29
@mtfishman mtfishman merged commit 3feb997 into main May 30, 2026
22 checks passed
@mtfishman mtfishman deleted the mf/gram-eigh-full branch May 30, 2026 00:57
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