Skip to content

Make contraction label derivation type-stable#192

Merged
mtfishman merged 2 commits into
mainfrom
mf/typestable-biperms
Jun 30, 2026
Merged

Make contraction label derivation type-stable#192
mtfishman merged 2 commits into
mainfrom
mf/typestable-biperms

Conversation

@mtfishman

Copy link
Copy Markdown
Member

Summary

Derives the bipartitioned permutations for contract as concretely-typed tuples behind a single Val function-barrier on the contracted count, rather than building them by converting runtime-length Vectors into abstract-typed tuples. The abstract tuples defeated the type stability of the downstream matricize pipeline, which is built around statically-sized tuples and Val barriers, so the per-call bookkeeping for a small contraction boxed heavily.

This is a second pass on the label-derivation layer, after #190 removed the Set and Dict hashing from the same path. For a 4x4 matrix multiply the per-call cost drops from 51 allocations to 17 and is several times faster, landing just above the floor set by the lower-level entry point that takes the permutations directly. The remaining allocations are the output array temporaries and the destination-label Vector.

The public biperms and biperm signatures are unchanged. The type-stable core is a new Val-parameterized method of biperms, and the two label entry points cross into Val-specialized helpers so the contraction itself runs type-stably.

Derives the bipartitioned permutations for `contract` as concretely-typed tuples behind a single `Val` function-barrier on the contracted count, rather than building them by converting runtime-length `Vector`s into abstract-typed tuples. The abstract tuples defeated the type stability of the downstream `matricize` pipeline, which is built around statically-sized tuples and `Val` barriers, so the per-call bookkeeping for a small contraction boxed heavily.

This is a second pass on the label-derivation layer, after #190 removed the `Set` and `Dict` hashing from the same path. For a 4x4 matrix multiply the per-call cost drops from 51 allocations to 17 and is several times faster, landing just above the floor set by the lower-level entry point that takes the permutations directly. The remaining allocations are the output array temporaries and the destination-label `Vector`.

The public `biperms` and `biperm` signatures are unchanged. The type-stable core is a new `Val`-parameterized method of `biperms`, and the two label entry points cross into `Val`-specialized helpers so the contraction itself runs type-stably.
@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.69%. Comparing base (e9318c9) to head (94a551d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #192      +/-   ##
==========================================
+ Coverage   82.46%   82.69%   +0.23%     
==========================================
  Files          22       22              
  Lines         616      630      +14     
==========================================
+ Hits          508      521      +13     
- Misses        108      109       +1     
Flag Coverage Δ
docs 28.76% <65.51%> (-0.25%) ⬇️

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 enabled auto-merge (squash) June 30, 2026 01:38
@mtfishman mtfishman merged commit 8c48b01 into main Jun 30, 2026
21 checks passed
@mtfishman mtfishman deleted the mf/typestable-biperms branch June 30, 2026 01:49
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