Skip to content

test_clip: make sure min and max have the same dtype as x #360

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

Merged
merged 1 commit into from
Apr 15, 2025

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

@ev-br
Copy link
Member Author

ev-br commented Apr 15, 2025

Okay, let's merge this as approved for this seems to fix rather annoying failures.
I've added a bullet point in #301 to track the "int min, float array" case.
Thanks @ndgrigorian @crusaderky for the reviews.

@ev-br ev-br merged commit 31eec9d into data-apis:master Apr 15, 2025
4 of 5 checks passed
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