Skip to content

blockwise _transpose! - #95

Merged
lkdvos merged 2 commits into
mainfrom
bd/transpose
Nov 27, 2026
Merged

lkdvos merged 2 commits into
mainfrom
bd/transpose

Conversation

@borisdevos

Copy link
Copy Markdown
Member

Follow-up to #94. I got lazy writing PR descriptions so I asked 🤖 to summarise for me.

BlockTensorKit overloaded the public transpose! directly, which covers every route except a destination wrapped as AdjointTensorMap(D): none of the overloads accept it, so TensorKit unwraps it and calls its generic _transpose! on the block tensor. For a sparse D that's wrong (the same missing-block issue as in #94), for a dense one it's correct but slow (6–50×).

This PR replaces the transpose! overloads by blockwise TK._transpose! methods, like _braid! and _twist!, with two small additions to keep everything else as fast as on main:

  • transpose! has no twist mask, so destination blocks that are AdjointTensorMaps (e.g. writing into t') can be unwrapped as well. Without this, those were 2–5× slower than on main.
  • @inbounds inside the _addblock! closure of the sparse loop, since it doesn't reach into the closure. Without this, every block got an extra space check, making sparse transposes of small blocks ~5–10% slower. There's no benefit for doing the same for the sparse loops of _braid! and _twist! (tested locally).

Against main, all other cases run at the same speed with identical allocations.

I added a test for permute!, braid! and transpose! into an AdjointTensorMap destination, which currently fails on main for transpose! with a sparse destination.

@codecov

codecov Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 52.94118% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/tensors/indexmanipulations.jl 52.94% 8 Missing ⚠️
Files with missing lines Coverage Δ
src/tensors/indexmanipulations.jl 63.46% <52.94%> (-1.49%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lkdvos
lkdvos enabled auto-merge (squash) November 27, 2026 17:06
@lkdvos
lkdvos merged commit 1048ff1 into main Nov 27, 2026
27 of 28 checks passed
@lkdvos
lkdvos deleted the bd/transpose branch November 27, 2026 17:30
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.

2 participants