perf: Various improvements to chisquare#336
Merged
YeungOnion merged 3 commits intostatrs-dev:masterfrom Jul 25, 2025
Merged
Conversation
- avoid allocations (-> no_std) - reduce number of .iter()
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #336 +/- ##
==========================================
- Coverage 95.01% 94.99% -0.02%
==========================================
Files 60 61 +1
Lines 13529 13615 +86
==========================================
+ Hits 12854 12934 +80
- Misses 675 681 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
|
whoops! used the web editor for the merge and missed the closing brace. Will fix and retry. |
Contributor
|
oh man, I boofed it. I think I'll need you to fix it. Missing semicolon closing src/stats_tests/chisquare.rs:90 |
Contributor
Author
|
No worries |
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.
The current code always allocates a new
f_exp: Vec<f64>just to iterate through it later. This is not necessary:Some(..), we can iterate through the slice itselfNone, we don't need to iterate anything. we can just set a fixed value foreand use that.This has the added benefit of being
no_std-compatible.The amount of iterations through
f_obscan also be reduced in some cases. If we need tof_obs.iter().zip(f_exp)anyways, there's no reason to dof_obs.iter().sum()beforehand. We can just calculate the sum "on the way", so to speak. The same goes forf_exp.EDIT: I used
approx::relative_eqsince nothing comparable exists incrate::precyet (on master). When #325 is merged, this should be updated to use theprecequivalent ofrelative_eq.