Skip to content

Return 'cpu' for device(numpy_array) when dispatch is enabled - #32705

Merged
ogrisel merged 3 commits into
scikit-learn:mainfrom
ogrisel:cpu-device-for-numpy
Nov 14, 2025
Merged

ogrisel merged 3 commits into
scikit-learn:mainfrom
ogrisel:cpu-device-for-numpy

Conversation

@ogrisel

@ogrisel ogrisel commented Nov 13, 2025

Copy link
Copy Markdown
Member

This PR will check using the CI whether we can change the current behavior for device to return "cpu" on numpy inputs when array_api_dispatch is True.

Context: #31829 (comment)

@github-actions

github-actions Bot commented Nov 13, 2025 •

Copy link
Copy Markdown

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 9f3c267. Link to the linter CI: here

@ogrisel
ogrisel marked this pull request as ready for review November 13, 2025 22:22
@ogrisel ogrisel added Quick Review For PRs that are quick to review Array API labels Nov 13, 2025
@ogrisel ogrisel changed the title Return 'cpu' for device(numpy_array) when dispatch is enabled Return 'cpu' for device(numpy_array) when dispatch is enabled Nov 13, 2025
Comment thread sklearn/utils/tests/test_array_api.py Resolved

@betatim betatim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I vote for this change. No opinion about including it in #31829 or merging this PR separately. Maybe separately makes it easier to understand why we made this change (for people from the future)?

@lucyleeow any opinions on this and where to include this change?

@lesteve

lesteve commented Nov 14, 2025

Copy link
Copy Markdown
Member

I pushed a small tweak in 9f3c267 (#32705). I slightly favour merging this PR separately from #31829.

@ogrisel

ogrisel commented Nov 14, 2025

Copy link
Copy Markdown
Member Author

LGTM as well. Let's merge.

@ogrisel
ogrisel merged commit b4238b2 into scikit-learn:main Nov 14, 2025
@ogrisel
ogrisel deleted the cpu-device-for-numpy branch November 14, 2025 17:04
@lucyleeow

lucyleeow commented Nov 15, 2025 •

Copy link
Copy Markdown
Member

Sorry I am late to the party, I did some (probably unnecessary digging into numpy) just to understand support for None vs 'cpu' and found this: https://github.com/numpy/numpy/pull/25233/files#r1453641211

tl;dr it seems the spec defines the default value for device to be None, which is what numpy have done, even though 'cpu' is the only supported device. (edit: so for any to numpy conversions, both would be fine)

Thanks for this! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Array API No Changelog Needed Quick Review For PRs that are quick to review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants