-
-
Notifications
You must be signed in to change notification settings - Fork 11k
NaN comparison allowed on slices of N-D array with floating-point invlaid error set to 'raise' #12935
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
I cannot reproduce all of the above. E.g.,
From my quick tests, it seems the only ones that fail are those in which the indexing led to a scalar. |
My guess would have been that it fails fails for the contiguous fast path, which should be triggered on contiguous arrays, however, possibly it is also triggered on 1-D arrays in general and there may be a small chance that the fast path even broke there (leading to the difference in the last example). Of course it could also be SIMD related for similar reasons. |
Whoops, sorry, those are the scalar cases that fail. |
A slightly easier to run test: import numpy as np
to_try = [
"np.full(2, np.nan)[0]",
"np.full((2,2), np.nan)[:,0]",
"np.full((2,2), np.nan)[0,0]",
"np.full((2,2,2), np.nan)[:,:,0]",
"np.full((2,2,2), np.nan)[:,0,0]",
"np.full((2,2,2), np.nan)[0,0,0]",
"np.full((2,2,2), np.nan)[:,0,0].copy()[0]",
"np.full((2,2), np.nan)",
"np.full((2,2), np.nan)[0,:]",
"np.full((2,2,2), np.nan)[0,:,:]",
"np.full((2,2,2), np.nan)[0,0,:]",
"np.full((2,2,2), np.nan)[:,:,0].copy()",
]
np.seterr(invalid='raise')
raised = []
silent = []
for t in sorted(to_try):
try:
eval(t) < 0
except FloatingPointError:
raised.append(t)
else:
silent.append(t)
print("raised:")
for t in raised:
print(" {}".format(t))
print("silent:")
for t in silent:
print(" {}".format(t)) Which on my machine (windows 10 x64) gives:
The pattern there is that only the scalar cases are silent, which I think might be deliberate. Can you run the code above on your machine, @davcrom? |
@eric-wieser, the above code on my 64 bit Xubuntu 16.04 (Python 3.5.2, numpy 1.15.4) Thinkpad 6th gen i7 gives:
I can't pretend to understand what's going on, but it's clearly a different result from your windows machine.
|
It appears that comparison with NaN is allowed on certain array slices even when the floating-point error for invalid comparisons is set to 'raise'.
(may be related to #10370 and ultimately #11043)
Reproducing code example:
and
all return False (or arrays of False). However...
and
all raise the appropriate floating-point error.
Error message:
Traceback (most recent call last):
File "<stdin>", line 1, in
FloatingPointError: invalid value encountered in greater
Numpy/Python version information:
Numpy: 1.15.1
Python: 2.7.12 and 3.5.2
System: Ubuntu 16.04.5 LTS
The text was updated successfully, but these errors were encountered: