-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
FIX np.divide undefined behaviour with where in gaussian processes #24245
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
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.
Thanks for the PR and the explanation!
Besides a minor comment on the whats new placement, LGTM
@@ -198,6 +198,13 @@ Changelog | |||
:mod:`sklearn.feature_selection` | |||
................................ | |||
|
|||
:mod:`sklearn.gaussian_process` |
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.
This section seems to be out of place in the whats new.
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.
LGTM, thanks @lesteve. We should almost always be using the out
arg of divide.
Triggered by investigating #24221.
We are using code like:
result[denominator == 0]
values are undefined when using this. For CPython it seems like thenp.empty
allocated for the return value reuses a temporary array created in a previous line that computes(X[:, np.newaxis, :] - X[np.newaxis, :, :]) ** 2
so thatresult[denominator == 0]
only contains 0. For PyPy this is not the case and at one point we get a 4. rather than a 0. (don't ask me where the 4. comes from ...).A snippet to reproduce a similar behaviour:
Output with CPython (address is the same so the -999. of the
tmp
array is reused):Output with pypy (address is not the same first value is random):