-
Notifications
You must be signed in to change notification settings - Fork 430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rounding error fix on WeightedIndex::update_weights() #955
Conversation
WeightedIndex::update_weights() uses subtraction on old_w. Rounding errors, particularly on f32, may bring total_weight to below 0. This PR makes sure this situation results in an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to add a test demonstrating this rounding error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a sensible change to me. I don't see the need for an extra test.
I think this would be nice to have, but the change certainly can be merged as is. This needs to be rebased on master, because #945 was merged. |
If you want, you can just enter the change by hand and commit to master, it might amount to less work than rebasing. Thanks for your approval! |
@facorread you can probably just do:
|
I am not authorized, sorry |
WeightedIndex::update_weights() uses subtraction on old_w. Rounding errors, particularly on f32, may bring total_weight to below 0. This PR makes sure a negative total_weight results in an error. This replaces PR rust-random#955 which was invalidated after a merge. Thanks for your consideration!
I wanted to leave this example for future reference, for anyone who needs to understand this rounding error. Thank you. |
WeightedIndex::update_weights() uses subtraction on old_w. Rounding errors, particularly on f32, may bring total_weight to below 0. This PR makes sure a negative total_weight results in an error.