-
-
Notifications
You must be signed in to change notification settings - Fork 26.1k
Fix _fill_or_add_to_diagonal
when reshape
returns copy
#31445
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
25 commits
Select commit
Hold shift + click to select a range
f954d45
wip
lucyleeow 230c9b5
wip
lucyleeow 70d46ff
wip
lucyleeow 7976488
fix fill or add diagonal
lucyleeow 5155245
merge main
lucyleeow 2f2fcec
Update sklearn/utils/tests/test_array_api.py
lucyleeow e44e527
Update sklearn/utils/_array_api.py
lucyleeow e7ceb53
format
lucyleeow 7e59fe6
review
lucyleeow 86bde6c
format
lucyleeow bc75c42
wip
lucyleeow ad49cc4
wip
lucyleeow 2e10b83
add back wrap to make tests pass
lucyleeow 0d0b4cb
fix default add_value True
lucyleeow 7c237dc
linalg diagonal
lucyleeow 47824d8
wip
lucyleeow 77869de
wip test
lucyleeow 958e18a
add test
lucyleeow fe97489
fix param
lucyleeow a36e0b1
use flat for add to
lucyleeow a3d452d
improve test
lucyleeow 493b0f6
add comment
lucyleeow a587d0d
review
lucyleeow 780c86e
Merge branch 'main' into aapi_fill_diag
lucyleeow b5633a1
merge main
lucyleeow 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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
While it's not possible to inspect memory layout in a library agnostic way, the array API standardize the
copy=False
argument andValueError
exception to detect whether it's possible to perform the more efficient, no-copy sliced assignment:I have not tested this solution locally with PyTorch or any other supported libraries, but if the tests pass with this suggestion on the CI,
_add_to_diagonal
could be updated similarly.Uh oh!
There was an error while loading. Please reload this page.
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.
.reshape(copy=False)
does not exist for PyTorch: pytorch/pytorch#150368. Actually it did not even exist for numpy until quite recently: numpy/numpy#26292.I think we should fix the bug and leave potential improvements for later, if the need ever arises ...
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.
This is a nice suggestion @ogrisel , I actually initially tried to 'fix' the problem by adding
copy=False
.Why don't I add a note to amend implementation once more array libraries support
copy
since it is technically in the spec.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.
My guess is that it was added to the array API standard only in a recent revision. Which is why not all libraries implement it. (Which minimum array API version we require is yet another discussion to have, but not in this PR)