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

np.testing.assert_array_equal() not compatible with bfloat16 when the value is nan #206

Open
ayaka14732 opened this issue Sep 23, 2024 · 1 comment

Comments

@ayaka14732
Copy link

import numpy as np
import jax.numpy as jnp

a = jnp.array([jnp.nan], dtype=jnp.float32)
np.testing.assert_array_equal(a, a)  # No error

a = jnp.array([jnp.nan], dtype=jnp.bfloat16)
np.testing.assert_array_equal(a, a)  # AssertionError

The cause is that np.testing.assert_array_equal() does not recognise bfloat16 as a "number" type: https://github.com/numpy/numpy/blob/b3ddf2fd33232b8939f48c7c68a61c10257cd0c5/numpy/testing/_private/utils.py#L773

@jakevdp
Copy link
Collaborator

jakevdp commented Sep 23, 2024

This is one of the many examples you can probably find of where NumPy hard-codes logic about its built-in set of dtypes. There's nothing that downstream dtype implementations like ml_dtypes can do to change this. We might think about raising this issue upstream in the NumPy package.

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

2 participants