Make contraction label derivation type-stable#192
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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
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:
|
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
Derives the bipartitioned permutations for
contractas concretely-typed tuples behind a singleValfunction-barrier on the contracted count, rather than building them by converting runtime-lengthVectors into abstract-typed tuples. The abstract tuples defeated the type stability of the downstreammatricizepipeline, which is built around statically-sized tuples andValbarriers, 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
SetandDicthashing 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-labelVector.The public
bipermsandbipermsignatures are unchanged. The type-stable core is a newVal-parameterized method ofbiperms, and the two label entry points cross intoVal-specialized helpers so the contraction itself runs type-stably.