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_clip: make sure min and max have the same dtype as x #360

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ev-br
Copy link
Member

@ev-br ev-br commented Apr 8, 2025

closes gh-359, closes gh-339

Per the spec: 'should have the same dtype as x': https://data-apis.org/array-api/latest/API_specification/generated/array_api.clip.html

The spec is not very clear on whether min and max can be int scalars for a real-valued x array, should probably clarify in the spec:

@ev-br ev-br mentioned this pull request Apr 8, 2025
Per the spec: 'should have the same dtype as x'
@ev-br
Copy link
Member Author

ev-br commented Apr 8, 2025

Run tests with array_api_compat.{numpy,torch} and jax.numpy with 50_000 examples locally.

@ndgrigorian
Copy link

Tested the branch (running with 2_000 examples) locally and can verify that it resolves gh-359 for dpctl.tensor

@crusaderky
Copy link
Contributor

The spec is not very clear on whether min and max can be int scalars for a real-valued x array, should probably clarify in the spec:

Definitely the spec should clarify that int scalars should be cast to float.

@crusaderky
Copy link
Contributor

data-apis/array-api#925

@@ -987,17 +987,15 @@ def test_clip(x, data):
base_shape=x.shape),
label="min.shape, max.shape")

dtypes = hh.real_floating_dtypes if dh.is_float_dtype(x.dtype) else hh.int_dtypes

min = data.draw(st.one_of(
st.none(),
hh.scalars(dtypes=st.just(x.dtype)),
Copy link
Contributor

@crusaderky crusaderky Apr 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: this misses out on the use case clip(Array[float], int)
#364

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

Successfully merging this pull request may close these issues.

Issue with test_clip Failing np.clip() on float32
4 participants