-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: Fix crash on 0d return value in apply_along_axis #8441
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
8 commits
Select commit
Hold shift + click to select a range
52988ea
BUG: Fix crash on 0d return value in apply_along_axis
eric-wieser 5307aed
MAINT: Use np.ndindex, which seems just as efficient
eric-wieser b10b6c2
BUG: Call __array_prepare__ before __array_wrap__
eric-wieser 9f362bf
BUG: Work around evil matrix.__array_prepare__
eric-wieser c8efc57
MAINT: Transpose the result, rather than working with a transposed view
eric-wieser ff9c363
TST: Verify apply_along_axis now works on masked arrays
eric-wieser 78084ee
MAINT: Improve error-checking of axis argument
eric-wieser d4bce01
DOC: Update 1.13.0 release notes with apply_along_axis changes
eric-wieser 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.
When I looked at this first, I thought you might consider using the (relatively new)
np.moveaxis
, i.e.,This will not be any faster (as it just sets up a
transpose
, like here), but is perhaps clearer. As a side benefit, you can remove above the checks on the validity ofaxis
, asmoveaxis
does those anyway.However, looking further down, it is not obvious
moveaxis
would work there, sinceres.ndim
could in principle be >1-d (for which your code adds support, which I think is very nice!). But one could steal a bit from themoveaxis
code and write hereThere 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.
Oh, good point.
moveaxis
works with multiple axes too, so should work in both cases.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.
For restoring axes, you could maybe write something like:
I think this is a slight improvement in clarity over building up the permutation axes for transpose directly.
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.
I think
moveaxis
should learn a shorthand for dest such that this would work:Ie, if dest is a scalar, move all the source axes to that location, in the order they were passed in src
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.
@shoyer: Based on @mhvk's revised opinion, are you happy for this to remain as it is? Any further pain-points blocking this being merged?