Skip to content

Add named directsum for tensors#220

Merged
mtfishman merged 4 commits into
mainfrom
mf/directsum
Jul 14, 2026
Merged

Add named directsum for tensors#220
mtfishman merged 4 commits into
mainfrom
mf/directsum

Conversation

@mtfishman

@mtfishman mtfishman commented Jul 13, 2026

Copy link
Copy Markdown
Member

Summary

Adds a name-aware directsum for tensors, building on the general directsum in 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.

@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.07%. Comparing base (a300d28) to head (56eed4e).

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

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.

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>
mtfishman and others added 2 commits July 14, 2026 13:04
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>
@mtfishman mtfishman changed the title [WIP] Add named directsum for tensors Add named directsum for tensors Jul 14, 2026
@mtfishman mtfishman marked this pull request as ready for review July 14, 2026 18:09
@mtfishman mtfishman enabled auto-merge (squash) July 14, 2026 18:09
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>
@mtfishman mtfishman merged commit 69bea45 into main Jul 14, 2026
18 checks passed
@mtfishman mtfishman deleted the mf/directsum branch July 14, 2026 19:04
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