Skip to content

Add out-of-place permutedims with an optional bipartition#202

Merged
mtfishman merged 2 commits into
mainfrom
mf/permutedims
Jul 2, 2026
Merged

Add out-of-place permutedims with an optional bipartition#202
mtfishman merged 2 commits into
mainfrom
mf/permutedims

Conversation

@mtfishman

@mtfishman mtfishman commented Jul 2, 2026

Copy link
Copy Markdown
Member

Summary

Adds TensorAlgebra.permutedims and TensorAlgebra.permutedims!, out-of-place and in-place permutation with an optional codomain/domain bipartition, mirroring TensorKit.permute. The single-permutation form reorders all dimensions into one permutation, giving an all-codomain result. The two-permutation form additionally splits them into a codomain/domain bipartition, including the degenerate case of an empty codomain that sends every dimension to the domain. Both go through the existing bipermutedimsopadd! interface (the out-of-place form allocating its destination with similar_map), so any operand implementing that interface, whether a dense array, a graded array, or a TensorMap, is permuted with no dedicated method. A dense operand ignores the bipartition and stores the result flat.

@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.28%. Comparing base (48ea23e) to head (6b3e622).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #202      +/-   ##
==========================================
+ Coverage   84.16%   84.28%   +0.11%     
==========================================
  Files          24       24              
  Lines         758      770      +12     
==========================================
+ Hits          638      649      +11     
- Misses        120      121       +1     
Flag Coverage Δ
docs 24.29% <7.69%> (-0.40%) ⬇️

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.

@mtfishman mtfishman changed the title [WIP] Add out-of-place permutedims with an optional bipartition Add out-of-place permutedims with an optional bipartition Jul 2, 2026
@mtfishman mtfishman marked this pull request as ready for review July 2, 2026 20:53
@mtfishman mtfishman enabled auto-merge (squash) July 2, 2026 20:54
@mtfishman mtfishman disabled auto-merge July 2, 2026 21:04
mtfishman and others added 2 commits July 2, 2026 18:19
@mtfishman mtfishman enabled auto-merge (squash) July 2, 2026 22:26
@mtfishman mtfishman merged commit 81ca02d into main Jul 2, 2026
21 checks passed
@mtfishman mtfishman deleted the mf/permutedims branch July 2, 2026 22:51
mtfishman added a commit to ITensor/ITensorBase.jl that referenced this pull request Jul 3, 2026
…207)

## Summary

Map-shaped construction now forwards a codomain/domain split down to the
backing storage instead of flattening. `randn`, `rand`, and `zeros` take
a codomain and a domain index tuple (`randn((i,), (j,))`), and the
`rand_map`/`randn_map`/`zeros_map` hooks on indices build a backing
object partitioned accordingly: a TensorKit `TensorMap` stores a
`codomain ← domain` map, a dense backend stores flat. Following the
`similar_map` convention the domain is conjugated in the flattened view,
so the result is an ordinary tensor over the codomain indices and the
duals of the domain indices. This fixes `rand_map((i,), (j,))` on
TensorMap-backed indices, which previously flattened everything into the
codomain.

`aligndims` gains a map form `aligndims(a, codomain, domain)` that both
repartitions and permutes, and its existing single-tuple form now routes
through `TensorAlgebra.permutedims` so a `TensorMap`-backed tensor
permutes correctly (a `TensorMap` has no flat `permutedims`). Both ride
the `permutedims` seam from
ITensor/TensorAlgebra.jl#202, so any backend
implementing it works with no dedicated method, and a dense backend
ignores the split and stores flat.

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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