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

Failing np.clip() on float32 #339

Open
crusaderky opened this issue Jan 30, 2025 · 0 comments
Open

Failing np.clip() on float32 #339

crusaderky opened this issue Jan 30, 2025 · 0 comments

Comments

@crusaderky
Copy link

e.g. https://github.com/data-apis/array-api-compat/actions/runs/13060007276/job/36440413878?pr=247

FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_clip - AssertionError: out[()]=-16777216.0 but should be -16777217.0 [clip()]
  x[()]=0.0, min[()]=None, max[()]=-16777217.0
assert -16777216.0 == np.float64(-16777217.0)
Falsifying example: test_clip(
    x=array(0., dtype=float32),
    data=data(...),
)
Draw 1 (min.shape, max.shape): ((), ())
Draw 2 (min): None
Draw 3 (max): np.float64(-16777217.0)
Draw 4 (kwargs): {'max': np.float64(-16777217.0)}

The problem is somehow caused by the fact that np.float32(-16777217.0) == -16777216.0.
However I can't reproduce the error on numpy 2.0.2:

>>> np.clip(np.asarray(0, dtype=np.float32), None, -16777217.0)
np.float32(-16777216.0)  # Correctly follows rule about binops mixing pure python and arrays

>>> np.clip(np.asarray(0, dtype=np.float32), None, np.float32(-16777217.0))
np.float32(-16777216.0)

>>> np.clip(np.asarray(0, dtype=np.float32), None, np.float64(-16777217.0))
np.float64(-16777217.0)
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

1 participant