Fix compatibility with nightly numpy #22257
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Numpy recently merged support for the 2023.12 revision of the Array API: numpy/numpy#26724
This breaks two of our tests:
The first breakage was caused by differences in how numpy and JAX cast negative floats to
uint8
. Specificallynp.float32(-1).astype(np.uint8)
returnsnp.uint8(255)
whereasjnp.float32(-1).astype(jnp.uint8)
producesArray(0, dtype=uint8)
. We don't make any promises about consistency with casting floats to ints, noting that this can even be backend dependent.I don't believe this failure is identifying any unexpected behavior, and we test many other dtypes properly so I'm not concerned about skipping this test.To fix our test, we now only generate positive inputs when the output dtype is unsigned.The second failure was caused by the fact that the approach we took in Update
jnp.clip
to Array API 2023 standard and introducesjax.experimental.array_api.clip
#20550 to support backwards compatibility and the Array API forclip
differs from the one used in ENH: Add Array API 2023.12 version support numpy/numpy#26724. Again, the behavior is consistent, but it produces a different signature. I've skipped checkingclip
's signature, but we should revisit it once thea_min
anda_max
parameters have been removed from JAX.Fixes #22251