-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: floating point errors with np.cos #23773
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
Comments
The fun part is, that this was quite for off even before if a machine at AVX512 (typically one less ULP, but that if would be randomly wrong on such a machine in a range where it should round to 1! The linked PR is the wrong one, that just fixes a small unrelated issue, gh-23399 is the relevant one and has more discussion, also ping @Mousius. TBH, I would prefer higher precision around these special values, and that includes the old SVML fallback (which not super many users end up with anyway). This is all very hard to make clear cut calls on though, since I also think a check like the one you said is dubious. (I also am surprised that the functions are non-monotenous, TBH. For these fast vectorized algorithms at least, results fluctuate randomly by 1-2 ULPs in regions where they should be numerically constant.) |
#23399 indeed provides much more context, thank you ! |
I am not sure that |
The question is whether a pattern of a decent fraction of large scientific downstream packages noticing this (most will only test after the release), should worry us... |
I'm getting |
Is this issue still open? Happy to pick up if not worked on yet |
@bb-ssaxena99 It's more of a policy discussion, not a work item at this time. Check the |
I guess the discussion may not be over, but for this specific issue it is (its precise in 1.25 for the moment and maybe its more likely we go the context manager opt-in route, or maybe not...). |
Describe the issue:
#23695 affects the precision of
cos
(and presumablysin
), in a way that may break downstream code:np.cos(0) == 0.9999999999999999
on the dev branch. I've tested this on Linux and MacOSHere's a real life example https://github.com/SAIL-Labs/AMICAL/blob/97dffe6671babdfc71ac830610c0b7b8c5093f25/amical/analysis/fitting.py#L54-L60
This function relies on
np.cos(0)
being exactly1.0
because its job is to invalidate inclination angles that havenp.cos(angle) < 1.0
.I'm aware this function is intrinsically sensitive to floating point errors (arguably it shouldn't) and I would be okay with having to fix the regression on the user side, but I thought I would first open a discussion here as I imagine this could affect many downstream packages.
Reproduce the code example:
Error message:
Runtime information:
1.25.0.dev0+1456.g0200e4a00
3.11.0 (main, Nov 13 2022, 10:50:04) [Clang 14.0.0 (clang-1400.0.29.202)]
Context for the issue:
No response
The text was updated successfully, but these errors were encountered: