inducer / pytato

Lazily evaluated arrays in Python
Other
9 stars 16 forks source link

Miscomputes some values involving unsigned integers #509

Closed inducer closed 3 months ago

inducer commented 3 months ago

Example:

array([1, 2, 3, 4, 5], dtype=np.uint32)  - np.int32(7)

currently gives

array([4294967290, 4294967291, 4294967292, 4294967293, 4294967294], dtype=np.int64)

I believe that this used to be masked before numpy2 by the result being a 32-bit value.

matthiasdiener commented 3 weeks ago

Numpy 1 also seems to mess this up:

import numpy as np

print("numpy", np.__version__)

a = np.array([1, 2, 3], dtype=np.uint32)

print(a - np.int32(7))
print(np.result_type(a, np.int32(7)))
numpy 2.1.1
[-6 -5 -4]
int64
numpy 1.26.4
[4294967290 4294967291 4294967292]
uint32