Repository navigation
Slice dense block tensors without allocating blocks - #88
Merged
Merged
Conversation
Slicing a `BlockTensorMap` allocated every block of the destination through `similar`, only for `_copyslice!` to replace each of them by the block of the source it selects. Build the slice directly from the sliced parent array instead: the result shares the blocks of the source, as before, without allocating new ones. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
lkdvos
referenced
this pull request
Oct 29, 2026
Co-Authored-By: Claude Opus 5.5 <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.
Slicing a dense
BlockTensorMap(e.g.t[2:(end - 1)]) allocated every block of the destination throughsimilar, and_copyslice!then replaced each of them by the source block it selects. The result already shares its blocks with the source, so the allocated blocks were thrown away.This builds a dense slice directly from the sliced parent array. The result is identical to before, including sharing blocks with the source, but no blocks are allocated. Sparse block tensors are unchanged.
In MPSKit, slicing the continuing channels out of an MPO environment is on the hot path of every effective Hamiltonian built from a
MPOHamiltonian(GL[2:(end - 1)]). For a chemistry-like Hamiltonian at χ = 64, one such slice drops from 0.93 MiB to 4 KiB._copyslice!did.BlockTensorMapavoids an ambiguity with the existing one that returns a single block.🤖 Generated with Claude Code