-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[math] make KahanSum::operator+= and -= consistent #11940
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
Conversation
The behavior of -= and += on a KahanSum were not symmetric, leading to slight bit-wise inaccuracies. In fits, where such operations are done a lot of times (e.g. through the offsetting mechanism in RooFit which subtracts a constant KahanSum term after each likelihood evaluation), this can add up to significant numerical divergence. This in turn makes it hard to test the accuracy of new numerical implementations. This commit adds test cases around the precision limits, making sure that all behavior is now symmetric and internally consistent. To aid in the test cases and also make the KahanSum objects more versatile, the commit also adds some extra - and + operators. Using these, we verify some additional desirable symmetry properties: that x - x = 0, and y + (-x) = y - x. The improved implementation is based on an algorithm for combining Kahan sums and carry terms used in literature (citation in comments).
|
Starting build on |
lmoneta
left a comment
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.
Nice improvement. Looks good, just a comment on the += and -= operators
The KahanSum operators +, -, +=, -= and unary - can all be used for any number of accumulators, even mixing two KahanSums with different numbers of accumulators. This works fine, because on the left hand side only the first accumulator is modified,so the exact number doesn't matter, and on the right hand side only Sum and Carry are ever called, and those internally already accumulate over whatever number of accumlators it has, so there it also doesn't matter. This commit extends the template parameters to include all these possibilities that were restricted before to only certain combinations (mostly with N=1).
|
Starting build on |
lmoneta
left a comment
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 Patrick for updating!
I think it looks fine now
|
Build failed on windows10/cxx14. Failing tests: |
|
Build failed on ROOT-performance-centos8-multicore/cxx17. Warnings:
And 366 more Failing tests:
|
This Pull request:
Changes or fixes:
The behavior of
-=and+=on aKahanSumwere not symmetric, leading to slight bit-wise inaccuracies. In fits, where such operations are done a lot of times (e.g. through the offsetting mechanism in RooFit which subtracts a constantKahanSumterm after each likelihood evaluation), this can add up to significant numerical divergence. This in turn makes it hard to test the accuracy of new numerical implementations. In particular, we are trying to fix a bug inMultiProcess::LikelihoodJob, which builds on thisKahanSumfix.This commit adds test cases around the precision limits, making sure that all behavior is now symmetric and internally consistent.
To aid in the test cases and also make the
KahanSumobjects more versatile, the commit also adds some extra-and+operators. Using these, we verify some additional desirable symmetry properties: that x - x = 0, and y + (-x) = y - x.The improved implementation is based on an algorithm for combining Kahan sums and carry terms used in literature (citation in comments).
Checklist: