-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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: Architecture-inconsistent behaviour casting negative integers to unsigned integers (MacOS ARM) #22951
Comments
NumPy inherits the C99 behavior, which is undefined for out-of-bounds float values when cast to integers. That means, you sometimes get On NumPy 1.24.1 you should probably be seeing a warning ("invalid value") indicating undefined behavior. NumPy could certainly clean this up to some degree. But some tries to speed up casting would more likely increase how often you get the undefined behavior. |
@seberg Thanks a lot for your quick reply. Stating that this is undefined behaviour is completely fine, and 1.24 does indeed add a warning, but the 1.24 release docs seem to contradict this:
Maybe this document should be updated or clarified? |
You are looking at the wrong part of the release note, it talks about Python object conversion/integer conversion. There is a chunk about the new warning here: https://numpy.org/devdocs/release/1.24.0-notes.html#numpy-now-gives-floating-point-errors-in-casts If it is very confusing, maybe you have an improvement suggestion? The tip I can give is that the casts between integers are (at least in practice) well defined:
will work as expected so long the first cast has all numbers within range. That is also the reason why you get sometimes correct "overflow" behavior: The C compiler is translating it to such a cast effectively. |
You are of course correct that my issue is related to conversion of floats, not ints. Thanks a lot for the clarification, closing as this is undefined behaviour. |
Describe the issue:
Converting a negative integer with dtype
float
,float32
, orfloat64
touint32
oruint64
gives zero on MacOS ARM machines.uint8
andunint16
This exact operation is discussed in the 1.24 release notes, and the provided example does work. However, it fails when the input has dtype
float
, and conversion is to 32- or 64-bit unsigned integers.Reproduce the code example:
Error message:
No response
Runtime information:
1.23.2
3.10.5 | packaged by conda-forge | (main, Jun 14 2022, 07:07:06) [Clang 13.0.1 ]
-and-
1.24.1
3.9.13 | packaged by conda-forge | (main, May 27 2022, 17:00:33)
[Clang 13.0.1 ]
[{'simd_extensions': {'baseline': ['NEON', 'NEON_FP16', 'NEON_VFPV4', 'ASIMD'],
'found': ['ASIMDHP', 'ASIMDDP'],
'not_found': ['ASIMDFHM']}}]
Context for the issue:
This breaks correct matrix building for the Brightway life cycle assessment framework.
The text was updated successfully, but these errors were encountered: