Skip to content
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

"invalid value encountered in left_shift" for broadcasted int16 array #18986

Open
asmeurer opened this issue May 10, 2021 · 4 comments
Open

"invalid value encountered in left_shift" for broadcasted int16 array #18986

asmeurer opened this issue May 10, 2021 · 4 comments

Comments

@asmeurer
Copy link
Member

Reproducing code example:

For some reason, np.left_shift(np.array([0], dtype=np.int16), np.array([[31, 31, 31], [31, 31, 31], [31, 31, 31]], dtype=np.int16)) gives a floating point warning, but similar function calls do not.

>>> np.seterr(all='raise')
{'divide': 'warn', 'over': 'warn', 'under': 'ignore', 'invalid': 'warn'}
>>> np.left_shift(np.array([0], dtype=np.int8), np.array([31], dtype=np.int16))
array([0], dtype=int16)
>>> np.left_shift(np.array([0], dtype=np.int16), np.array([31], dtype=np.int16))
array([0], dtype=int16)
>>> np.left_shift(np.array([0], dtype=np.int16), np.array([[31, 31, 31]], dtype=np.int16))
array([[0, 0, 0]], dtype=int16)
>>> np.left_shift(np.array([0], dtype=np.int16), np.array([[31, 31, 31], [31, 31, 31]], dtype=np.int16))
array([[0, 0, 0],
       [0, 0, 0]], dtype=int16)
>>> np.left_shift(np.array([0], dtype=np.int16), np.array([[31, 31, 31], [31, 31, 31], [31, 31, 31]], dtype=np.int16))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FloatingPointError: invalid value encountered in left_shift
>>> np.left_shift(np.array([0], dtype=np.int16), np.array([[30, 30, 30], [30, 30, 30], [30, 30, 30]], dtype=np.int16))
array([[0, 0, 0],
       [0, 0, 0],
       [0, 0, 0]], dtype=int16)

Error message:

NumPy/Python version information:

>>> np.__version__
'1.21.0.dev0+1549.g7c4b2482a'
>>> import sys
>>> sys.version
'3.9.2 | packaged by conda-forge | (default, Feb 21 2021, 05:02:20) \n[Clang 11.0.1 ]'
@seberg
Copy link
Member

seberg commented May 10, 2021

This sounds either like a clang bug, or a duplicate of #18005.

EDIT: Unless we have SIMD here and that is related, but I doubt it?

@asmeurer
Copy link
Member Author

I just tested on Linux (3.7.8 | packaged by conda-forge | (default, Jul 31 2020, 02:25:08) \n[GCC 7.5.0]) and didn't get the error, so that seems plausible.

@asmeurer
Copy link
Member Author

#19049 doesn't seem to have fixed this, so I guess it was a different issue.

@r-devulap
Copy link
Member

I confirmed that clang-10 also sets the invalid flag with this code. It is coming from a cvttps2dq %xmm2,%xmm5 instruction within the SHORT_left_shift_avx2 function. I have no idea why clang uses a floating point instruction for integers (the generated assembly is insanely long to understand), but the code comments indicate this isn't the first time this is happening, see:

// For some reason, our macOS CI sets an "invalid" flag here, but only

The invalid flag is currently suppressed for INT and UINT. Would it be appropriate to extend this to other integer types as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants