`np.testing.assert_array_equal()` not compatible with bfloat16 when the value is `nan`
- Dominant language
- C++
- Stars
- 361
- Forks
- 60
- Avg merge
- 18h 41m
- Merged PRs (30d)
- 3
Description
```python
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
Contributor guide
Research direction
Reproduce the two examples in the issue, then read NumPy's numpy/testing/_private/utils.py at the referenced type-checking code to understand the bfloat16 mismatch. Done means the bfloat16 NaN comparison no longer raises an AssertionError while the existing float32 behavior remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- data, testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100