[WIP] Named-operator constructors, projection verbs, and balanced gram_eigh_full#229
Draft
mtfishman wants to merge 9 commits into
Draft
[WIP] Named-operator constructors, projection verbs, and balanced gram_eigh_full#229mtfishman wants to merge 9 commits into
mtfishman wants to merge 9 commits into
Conversation
Match TensorAlgebra's switch to A ≈ X * X' for gram_eigh_full: relabel X with the domain dimension names (rank trailing) so it mirrors V_R from eigh. The companion left inverse Y from gram_eigh_full_with_pinv likewise carries the domain names with the rank axis leading. Pin the matching TensorAlgebra branch via [sources] until that patch is registered.
- `Base.one(::AbstractNamedDimsArray, codomain, domain)` and `Base.one(::AbstractNamedDimsOperator)` build identity-shaped named arrays/operators by dispatching to `TensorAlgebra.one` on the underlying raw storage. The result sits in canonical (codomain, domain) name order. - `similar_operator(prototype, [T,] axes, [codomain_names,] domain_names)` allocates an operator with the user-supplied side as the domain and the codomain derived by `conj`-ing the domain axes; codomain names default to fresh `randname` outputs. Exported. - `Random.randn!` / `Random.rand!` peel down to the concrete storage, working around the ITensor `eltype(::Type) === Any` issue.
Previously `domain(::Bijection)` returned `values(::OrderedDict)`, a `Base.ValueIterator` that compares by object identity. Switching it to `keys` of the reverse dict gives a `Base.KeySet` whose `==` matches elementwise, so `domainnames(op1) == domainnames(op2)` does what one would expect. The two dicts are constructed from the same pairs in the same order, so `codomain(b)[i]` and `domain(b)[i]` remain in lock-step positional order. Also reworks the `Base.one` docstring examples to use `apply` (which renames the codomain back to the domain), replacing the matricize + identity-matrix check that's better suited to tests than docs.
1 task
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #229 +/- ##
===========================================
- Coverage 71.77% 25.10% -46.68%
===========================================
Files 20 19 -1
Lines 992 1000 +8
===========================================
- Hits 712 251 -461
- Misses 280 749 +469
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:
|
Centralizes the linear-map allocation primitive in TensorAlgebra so backends only need to overload `similar_map`, while `similar_operator` keeps the named-axis wrapping. Also drops the redundant `[sources.TensorAlgebra]` pin from `docs/`, `examples/`, and `test/Project.toml`; the workspace root `Project.toml` already pins the upstream feature branch for all subprojects.
`TensorAlgebra.similar_map` now flips the domain direction itself when laying out storage (ITensor/TensorAlgebra.jl#177), so the wrapper passes both sides in the same direction and lets the primitive handle the bra/ket flip.
Without this, `Base.conj(::AbstractArray{<:Real})` short-circuits on a `NamedUnitRange` (element type `NamedInteger{Int, Name}` is a `Real` subtype) and returns the wrapper unchanged — never touching the inner range. That's a no-op for plain ranges but wrong for graded axes, where the inner conj needs to flip sector arrows.
`Base.conj`, `Base.:*(::, ::Number)`, `Base.:/(::, ::Number)`, and `LinearAlgebra.normalize` are overloaded for `AbstractNamedDimsArray` to delegate to the underlying array rather than the default broadcast path. Broadcast on a `NamedDimsArrayStyle` reaches into the storage via scalar `getindex`, which is unsupported on block-structured arrays such as `AbelianGradedArray` (and would round-trip through scalar slots even when the storage could handle the op block-wise). `denamed(a, inds)` also short-circuits when the requested order already matches `dimnames(a)`, returning `denamed(a)` directly. The previous path always wrapped in a `PermutedDimsArray` for the identity permutation, which hid the storage type from downstream dispatch (`LinearAlgebra.dot` is the visible case). Co-authored-by: Claude <noreply@anthropic.com>
`TensorAlgebra.projectto!(::AbstractNamedDimsArray, ::AbstractArray)` delegates to the underlying-storage `projectto!`, so a named operator allocated via `similar_map(prototype, T, named_codomain, named_domain)` can be filled from raw dense data uniformly across backends. The named layer doesn't need to know which storage the named array wraps. Co-authored-by: Claude <noreply@anthropic.com>
Mirrors the existing `projectto!` forwarder, so backend specializations (e.g. `AbelianGradedArray`'s materialize-and-compare check) are reachable through the named layer with their tolerance defaults intact. Co-authored-by: Claude <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
Base.one(::AbstractNamedDimsOperator)andBase.one(::AbstractNamedDimsArray, codomain, domain)similar_operator(prototype, [T,] axes, [codomain_names,] domain_names), routed throughTensorAlgebra.similar_mapRandom.randn!andRandom.rand!onAbstractNamedDimsOperatorBase.conj(::AbstractNamedUnitRange), forwarded through the underlying range so graded-axis conjugation flips sector arrowsgram_eigh_fullaligned with the balanced convention from Balanced gram_eigh_full convention, add one and operator-construction primitives TensorAlgebra.jl#177domain(::Bijection)returns aBase.KeySet, so equal-pairBijections compare equalBase.conj,Base.:*/Base.:/by a scalar, andLinearAlgebra.normalizeonAbstractNamedDimsArray, routed throughdenamedto avoid the broadcast-scalar-indexing pathTensorAlgebra.projectto!andTensorAlgebra.checked_projectto!forwarded to the underlying storageTODO
[sources]pin onTensorAlgebraonce the matching version (0.9.5) registers.