refactor: Categorical now stores normalized values#396
Merged
Conversation
norm_pmf (probabilities) was already normalized before storing, but cdf and sf weren't. Instead, they were normalized on every API call. The refactor also reduces the amount of vec/slice iterations in `new` from 4 to 2.
YeungOnion
force-pushed
the
cherry-pick-37f8fdf
branch
from
July 20, 2026 01:31
e90e861 to
9030bd7
Compare
…of categorical-style draw-and-scan
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #396 +/- ##
==========================================
+ Coverage 94.67% 94.89% +0.21%
==========================================
Files 61 61
Lines 13322 13344 +22
==========================================
+ Hits 12613 12663 +50
+ Misses 709 681 -28 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
YeungOnion
marked this pull request as ready for review
July 20, 2026 03:03
Contributor
Author
|
GoF tests for sampling will still be a good idea |
This was referenced Jul 20, 2026
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.
Cherry-pick of 37f8fdf (FreezyLemon) onto current main. The original commit predates the rand 0.9/0.10 migration and the
std/coresplit, so it conflicted on:::rand::distr::Distribution(vs. oldrand::distributions::Distributionalias)RngExt::random(vs. oldrng.gen)Categoricalnow storesnorm_cdf/norm_sfdirectly instead of normalizing on everycdf/sf/inverse_cdfcall, andinverse_cdfusesbinary_search_byinstead of a hand-rolledbinary_index. The now-unusedsample_unchecked/prob_mass_to_cdf/cdf_to_sf/binary_indexhelpers are removed;Multinomial::sample, which depended oncategorical::prob_mass_to_cdf/sample_unchecked, now computes its cdf inline instead.Test plan
cargo build --all-featurescargo test --all-features(192 passed)cargo clippy --all-features