Add named directsum for tensors#220
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #220 +/- ##
==========================================
+ Coverage 75.92% 76.07% +0.15%
==========================================
Files 29 29
Lines 1682 1693 +11
==========================================
+ Hits 1277 1288 +11
Misses 405 405
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:
|
Adds `directsum` for `AbstractNamedTensor`, extending the TensorAlgebra function with two forms. `directsum(A => inds_A, B => inds_B, ...)` mints fresh summed indices and returns `S => out_inds`, mirroring the `tensor => indices` inputs, while `directsum(out_inds, A => inds_A, ...)` names the summed axes with the supplied indices (names or `NamedUnitRange`s) and returns just `S`. The indices paired with each tensor are concatenated block-diagonally while the remaining shared indices are aligned by name and carried through unchanged, so the result has the shared indices first and the summed indices trailing. The implementation aligns each tensor to `(shared, summed)` order and delegates the concatenation to `TensorAlgebra.directsum`, so graded tensors get direct sums once GradedArrays is loaded. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Match the `directsum(dims, as...)` signature introduced in ITensor/TensorAlgebra.jl#210. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
TensorAlgebra 0.17.5 is registered, so resolve it from the registry. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The `jldoctest` used `directsum` without bringing it into scope, so the Documentation doctests failed. Import it from TensorAlgebra and `Index` from ITensorBase, matching the other doctests in the file. Co-Authored-By: Claude Opus 4.8 (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
Adds a name-aware
directsumfor tensors, building on the generaldirectsumin TensorAlgebra (ITensor/TensorAlgebra.jl#210). It aligns the arguments by index name, sums them over a chosen set of indices, and returns a single tensor with the summed indices trailing. Two forms are provided, one taking the output indices explicitly and one minting fresh indices for the summed dimensions.