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

test_util: avoid overflow errors in NumPy 2.0 #19701

Merged
merged 1 commit into from
Feb 8, 2024

Conversation

jakevdp
Copy link
Collaborator

@jakevdp jakevdp commented Feb 7, 2024

Part of #19246.

NumPy 2.0 added OverflowErrors on array creation if the input is not representable under the requested dtype. For example:

>>> np.array(1000, dtype='uint8')
---------------------------------------------------------------------------
OverflowError                             Traceback (most recent call last)
Cell In[2], line 1
----> 1 np.array(1000, dtype='uint8')

OverflowError: Python integer 1000 out of bounds for uint8

This can be prevented by explicitly calling astype:

>>> np.array(1000).astype('uint8')
array(232, dtype=uint8)

This PR fixes a number of test failures under NumPy 2.0 that are related to this NumPy 2.0 behavior.

@jakevdp jakevdp requested a review from yashk2810 February 7, 2024 20:27
@jakevdp jakevdp self-assigned this Feb 7, 2024
@jakevdp jakevdp added the pull ready Ready for copybara import and testing label Feb 7, 2024
@copybara-service copybara-service bot merged commit bbeddbd into jax-ml:main Feb 8, 2024
13 checks passed
@jakevdp jakevdp deleted the fix-jtu branch February 8, 2024 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pull ready Ready for copybara import and testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant