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
BUG: masked array division should ignore all FPEs in mask calculation #26135
Conversation
fc2111f
to
c30dd94
Compare
numpy/ma/tests/test_core.py
Outdated
@@ -2581,6 +2581,14 @@ def test_no_masked_nan_warnings(self): | |||
# also check that allclose uses ma ufuncs, to avoid warning | |||
allclose(m, 0.5) | |||
|
|||
def test_masked_array_underflow(self): | |||
np.seterr(under="raise") |
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.
Please make sure to use with np.errstate()
, this will otherwise affect later tests randomly. Otherwise, LGTM, no need to insert those newlines, but they seem fine.
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 feedback, I'll send right away the new PR
c30dd94
to
e940868
Compare
Hi @seberg , I've fixed the test as you requested and also removed the extra spaces that I forgot to remove before. |
numpy/ma/tests/test_core.py
Outdated
X = np.ma.array(x) | ||
x2 = x/2.0 # <- works | ||
X2 = X/2.0 | ||
assert(X2.all() == X.all() / 2.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.
What does this assert test?
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.
The purpose is to make sure that the division occured fine without the multiply underflow error
numpy/ma/tests/test_core.py
Outdated
@@ -2581,6 +2581,14 @@ def test_no_masked_nan_warnings(self): | |||
# also check that allclose uses ma ufuncs, to avoid warning | |||
allclose(m, 0.5) | |||
|
|||
def test_masked_array_underflow(self): | |||
with(np.errstate(under="raise")): | |||
x = np.arange(0, 3, 0.1) |
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.
Maybe move this line and the next two or of the with context, as the test is about the masked array.
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.
Ok i'll do so
e940868
to
3d47b3f
Compare
numpy/ma/tests/test_core.py
Outdated
X = np.ma.array(x) | ||
with(np.errstate(under="raise")): | ||
X2 = X/2.0 | ||
assert(X2.all() == X.all() / 2.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.
assert(X2.all() == X.all() / 2.0) | |
np.testing.assert_array_equal(X2, x/2) |
The X.all()
and X2.all()
are both False. Perhaps you wanted to write assert np.all(X2==x/2.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.
Thank you for the correction, at the time I wasn't 100% sure how I would test the value of the array but I'll change to that as it makes more sense.
3d47b3f
to
3b252c5
Compare
Hi @seberg @eendebakpt, is everything correct now in the new PR? |
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.
This PR fixes the bug #25810 where an internal multiplication underflow occured with np.seterr(under="raise")