Write each graded block straight into its coupled-sector matrix slice#203
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #203 +/- ##
==========================================
- Coverage 81.83% 81.77% -0.06%
==========================================
Files 24 24
Lines 1877 1888 +11
==========================================
+ Hits 1536 1544 +8
- Misses 341 344 +3
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:
|
c10f7f1 to
3d43664
Compare
Fold each stored block's permute, reshape, `op`, and fermion sign into a single in-place strided write, dropping the per-block permuted-and-reshaped intermediate. Roughly halves the matricize allocation.
The gather only reads each stored block, so take it with `view` instead of the block `getindex`, which materializes a copy. Removes the largest remaining per-block allocation in matricize.
The unmatricize gather wrapped every matrix slice in a `StridedView`, forcing a dense `Array` copy for non-strided blocks like a `Diagonal` `S`. The no-reshape, no-permute case (a rank-2 factor whose axes already match) now writes through a plain type-preserving broadcast, keeping such blocks on their own array type.
…rd strided inputs Rename the per-block helpers to `matricizeopperm_block!` and `unmatricizeperm_block!` after the functions they factor out, rename their `biperm` argument to `perm`, and load `StridedView` into scope so it need not be qualified. Use `reshape` and `op` directly on the `StridedView` (both are lazy) rather than `sreshape` and a broadcast branch. The strided assumption is now an explicit `isstrided` check with a clear error instead of a cryptic `StridedView` failure.
Use `dst`/`src` for the destination and source of `matricizeopperm_block!` and `unmatricizeperm_block!`, matching the `copyto!` convention, and rename the grouped-shape argument to `grouped_dims`.
The N-D grouping shape for reshaping the matrix slice is `size(dst)` under `invperm(perm)`, so `unmatricizeperm_block!` recovers it from `dst` and `perm` rather than taking it as an argument.
3d43664 to
208bf84
Compare
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
Folds each stored block's permute, reshape,
op, and fermion sign into a single in-place strided write directly into its coupled-sector matrix slice, so the gradedmatricizegather andunmatricizeperm!scatter no longer build a permuted-and-reshaped copy per block. Each block's data is wrapped as aStridedView, lazily permuted into codomain/domain order, and broadcast into a reshaped view of its(rows, cols)slice, with the block's ±1 fermion sign carried as a scalar factor. The gather also reads each source block through aviewrather than the blockgetindex, which materialized a copy.A factorization can produce non-strided matrix blocks, such as a
DiagonalS. Those only arise in the structure-preserving case, where the block needs no reshape or permute, so they write through a plain type-preserving broadcast instead of the strided path and keep their own array type.Together these cut the matricize allocation in half and shave a few percent off symmetric contraction time, building on the array-level permute folds in #196 and #197.