Skip to content

MAINT: remove outdated xp_ functions, xp.asarray on elementwise function args #22683

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 2 commits into from
Mar 14, 2025

Conversation

mdhaber
Copy link
Contributor

@mdhaber mdhaber commented Mar 14, 2025

Reference issue

gh-22680

What does this implement/fix?

Now that the 2024.12 standard is out and array-api-compat supports it, I thought it was time for a cleanup of some artifacts from the old days of array API translations.

One of the things we used to have to do was convert arguments to xp.where, xp.minimum, etc., into arrays rather than leaving them as scalars. Even if we were careful to use the correct dtype, I don't think anyone ensured that the array ended up on the correct device. Use of a Python scalar avoids both of these gotchas.

This cleans up most of the now-unnecessary array conversions in the context of xp.where, xp.minimum, xp.clip, and some other elementwise functions mentioned in data-apis/array-api#807 (comment). I also noticed some old custom xp_ functions that we no longer need since they are provided by array-api-compat.

Lots of lines and files are changed, but it should be pretty straightforward.

Additional information

Based on gh-22680, I think that anywhere we create an array within a function, we need to pay attention to the device. This only avoids some of those places. To resolve that issue, we really should test with non-default devices (and make the required changes).

There may be some test skips we can remove now. I think we can do that as part of follow-up to gh-22609/gh-22677.

Use of result_type needs very special attention; see data-apis/array-api-compat#223 (comment). Now that it's possible, we need to make sure we pass the arguments to result_type before they become arrays.

@mdhaber mdhaber added maintenance Items related to regular maintenance tasks array types Items related to array API support and input array validation (see gh-18286) labels Mar 14, 2025
@mdhaber
Copy link
Contributor Author

mdhaber commented Mar 14, 2025

Failures are due to data-apis/array-api-compat#271 and data-apis/array-api-strict#131.

Copy link
Member

@j-bowhay j-bowhay left a comment

Choose a reason for hiding this comment

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

Thanks for the tidy up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
array types Items related to array API support and input array validation (see gh-18286) maintenance Items related to regular maintenance tasks scipy._lib
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants