Skip to content

Write each graded block straight into its coupled-sector matrix slice#203

Merged
mtfishman merged 7 commits into
mainfrom
mf/graded-contraction-profiling
Jul 2, 2026
Merged

Write each graded block straight into its coupled-sector matrix slice#203
mtfishman merged 7 commits into
mainfrom
mf/graded-contraction-profiling

Conversation

@mtfishman

@mtfishman mtfishman commented Jul 2, 2026

Copy link
Copy Markdown
Member

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 graded matricize gather and unmatricizeperm! scatter no longer build a permuted-and-reshaped copy per block. Each block's data is wrapped as a StridedView, 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 a view rather than the block getindex, which materialized a copy.

A factorization can produce non-strided matrix blocks, such as a Diagonal S. 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.

@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 81.77%. Comparing base (f045de6) to head (208bf84).
⚠️ Report is 1 commits behind head on main.

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     
Flag Coverage Δ
docs 0.00% <0.00%> (ø)

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 force-pushed the mf/graded-contraction-profiling branch 2 times, most recently from c10f7f1 to 3d43664 Compare July 2, 2026 17:00
@mtfishman mtfishman enabled auto-merge (squash) July 2, 2026 17:00
mtfishman added 7 commits July 2, 2026 13:01
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.
@mtfishman mtfishman force-pushed the mf/graded-contraction-profiling branch from 3d43664 to 208bf84 Compare July 2, 2026 17:03
@mtfishman mtfishman merged commit f6e4d2f into main Jul 2, 2026
18 checks passed
@mtfishman mtfishman deleted the mf/graded-contraction-profiling branch July 2, 2026 17:13
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