Repository navigation
Conversation
…d clear in place check_shape accepts exactly the shapes new builds (positive width and depth, a representable cell count, an odd CountSketch depth), and check_weight exactly the weights update takes (finite; nonnegative for CMS). A caller can reject a configuration or an input before it builds or touches a state, instead of repeating these rules. new, update and from_bytes now call them, so the rules live in one place. clear empties the counters and candidates in place and keeps the shape, so a caller can reuse a state for the next window without remembering its dimensions.
This was referenced Oct 15, 2026
Contributor
Author
|
Closing: |
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.
Why
A caller that sizes a
WeightedFrequencyfrom configuration has to reject a bad shape or a bad weight before it builds or updates a state. Today the only check is to try:newallocateswidth * depthcells, andupdatemutates. So ASAPPlanner's executor restates the kernel's rules itself: an odd CountSketch depth and positive dimensions in its plan validation, its cost-evidence check and its family mapping, and "finite, nonnegative for CMS" in its input validation. It also stores(algorithm, width, depth, capacity)next to every state only to rebuild an empty one at each window.What
WeightedFrequency::check_shape(algorithm, width, depth): accepts exactly the shapesnewbuilds, without allocating.WeightedFrequency::check_weight(&self, weight): accepts exactly the weightsupdatetakes, without touching the state.WeightedFrequency::clear(&mut self): empties the counters and candidates in place, keeping the shape and allocation.new,updateandfrom_bytesnow call the two checks, so the rules live in one place. No behavior changes for existing callers.Stacked on #225 (and so on #160). Retarget to
mainafter those merge.How
The shape test that
newandfrom_byteseach inlined moves intocheck_shape; the weight test at the top ofupdatemoves intocheck_weight.clearzero-fillscellsand clears the candidate heap.Key code interfaces added / modified
src/sketches/weighted_frequency.rsUsage, end to end (checked by a scratch test at the head commit):
Before this PR
A caller either built a state to learn whether a shape was valid (allocating
width * depthcells) or copied the rules. ASAPPlanner copied them in four places and kept the shape beside each state to rebuild it.After this PR
The caller asks the kernel. ASAPPlanner's companion PR deletes its copies and calls
check_shape,check_weightandclear.Verification
shape_and_weight_checks_match_construction_and_update(seven shapes, including even CountSketch depth, zero dimensions andusize::MAXwidth, agree withnew; five weights agree withupdatefor both algorithms) andclear_empties_in_place_and_keeps_the_shape(a cleared state equals a fresh one byte for byte).cargo fmt --all -- --check;cargo clippy --workspace --all-targets --all-features --locked -- -D warnings;cargo test --all-features --locked weightedand theWeightedFrequencydoc test pass.asap-physical-operators(212 tests) andasap-aware-mapping(581 tests) pass against a pin that includes this commit.Limitations
The error strings are unchanged. The checks return the existing
WeightedFrequencyErrorvariants (Invalidfor shapes,Updatefor weights).