-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
FIX sparse arrays not included in array API dispatch #29476
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
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d5e5d02
FIX sparse arrays not included in array API dispatch
adrinjalali 7470ea5
Merge remote-tracking branch 'upstream/main' into array_api/sparse
adrinjalali 97ad774
remove remove_sparse
adrinjalali 2e98424
make device and namespace_and_device consistent
adrinjalali bf4805c
docstring
adrinjalali fe86568
add test
adrinjalali a7ef3d3
Update sklearn/utils/tests/test_array_api.py
adrinjalali 92acfa4
Update sklearn/utils/tests/test_array_api.py
adrinjalali 4b4fa24
missing import
adrinjalali 9f1ee5e
fix comment
adrinjalali c1086ca
Merge remote-tracking branch 'upstream/main' into array_api/sparse
adrinjalali 131eba9
Merge remote-tracking branch 'upstream/main' into array_api/sparse
adrinjalali 03d6372
Merge remote-tracking branch 'upstream/main' into array_api/sparse
adrinjalali File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the
Returns
section of the docstring needs to be updated to mention this case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I we might argue that returning
None
in this case can be quite confusing.When reviewing, this PR, I found out that
get_namespace_and_device
is not even consistent withdevice
(independently of the changes in this PR).Consider the following code on a single non-array input that is not filtered out by any of the
remove_
arguments (note that the array API dispatch is never enabled) .I think we should at least make the output of
device(some_list)
andget_namespace_and_device(some_list)
consistent, either by returningNone
in both cases, or by returning "cpu" consistently as is done for NumPy arrays, either with thesklearn.utils._array_api._NumPyAPIWrapper
when array API dispatch is disabled, or when using thearray_api_compat.numpy
wrapper for numpy 1.x or when using numpy 2 arrays who naturally expose a.device == "cpu"
attribute (at least in the dev version).Returning
None
for non-array inputs (such as lists or scipy sparse matrices when accepted) would be the cleanest. However that might render our code more verbose by having to scatter aroundif device_ is not None
in various places. So maybe, always returning"cpu"
, both indevice(...)
andget_namespace_and_device(...)
for non-arrays inputs might be more pragmatic.