-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix: Fix stddev indeterministically producing NAN #13248
fix: Fix stddev indeterministically producing NAN #13248
Conversation
82219b5
to
2580bcc
Compare
In the VarianceGroupAccumulator we were missing a `count == 0` check that is present in the normal Accumulator. This mostly does not matter except for the case where the first state to be merged has `count == 0` then the `merge` function will incorrectly calculate a new m2 of NAN which will propagate to the final result. This fixes the bug bu adding the missing `count == 0` check.
2580bcc
to
3265483
Compare
@@ -316,6 +316,7 @@ fn merge( | |||
mean2: f64, | |||
m22: f64, | |||
) -> (u64, f64, f64) { | |||
debug_assert!(count != 0 || count2 != 0, "Cannot merge two empty states"); |
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.
I don't exactly know how it works. Is supporting this not needed?
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.
It is a precondition of using this function. So support is not needed here, but expected to be handled by callers. When both counts are 0 then also mean
and m2
is 0 and the correct result would also be all 0.
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.
i should have checked the callers. thanks. 👍
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.
Thank you @eejbyfeldt and @findepi
Which issue does this PR close?
Closes #13247
Rationale for this change
In the VarianceGroupAccumulator we were missing a
count == 0
checkthat is present in the normal Accumulator. This mostly does not matter
except for the case where the first state to be merged has
count == 0
then the
merge
function will calculate a new m2 of NAN which willpropagate to the final result.
What changes are included in this PR?
This fixes the bug bu adding the missing
count == 0
check.Are these changes tested?
New and existing tests.
Are there any user-facing changes?
Correctness issue is fixed.