Repository navigation
BUG,MAINT: Fix issues with non-reduce broadcasting axes #15162
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
11 commits
Select commit
Hold shift + click to select a range
d3bfaf8
MAINT: Simplify undoing of iter-axis-perm in nditer
seberg 407f626
MAINT: (nditer) move duplicated reduce axis check into helper func
seberg f31aeef
MAINT: Simplify signature of npyiter_replace_axisdata
seberg 07ea525
MAINT: Simplify strides and axis check in npyiter_new_temp_array
seberg 7f8dc86
ENH: Allow specifying reduction axis in nditer/NpyIter
seberg 87cb35f
MAINT: Use reduction axis marker for einsum
seberg b5c2f94
BUG: Avoid incorrect broadcasts on non-core outputs in gufuncs
seberg 729b9ca
BUG,MAINT: Simplify reduction result creation using reduce axis
seberg c65acda
DOC: Slightly improve error message on incorrectly shaped reductions
seberg 153376f
MAINT: Address review comments related to NPY_ITER_REDUCTION_AXIS
seberg 8da4fba
BUG: The reduction output must not cause the input to be broadcast
seberg 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
Oops, something went wrong.
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.
Will this change make
np.einsum("...i,...i->...i", np.arange(3), np.array([1]))an error? That is, should named dimensions in einsum be viewed as non-broadcastable?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.
Yes, it changes that. I can undo. But einsum does not really have
keepdimssemantics nor is that notation einsum notation AFAIK.Completely changing the resul behaviour by providing (a potentially wrong) output array seems undesirable to me?
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.
What's the resulting error look like with this branch?
Not sure what you mean by that not being einsum notation - that notation works for me
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.
Sorry, this is unchanged, I thought you had
np.einsum("...i->...i", np.arange(3), out=np.array([1]))If you do not provide an out array, no semantics are ever changed here.
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.
OK, sorry... I do not think anything changed at all. Since opposite broadcasting should be the only thing that changed (since only
np.newaxisis marked here). But einsum specifically checks forouthaving too many dimensions.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.
That sounds good. But as a check, would one or the other solve the no-input-but-have-output case discussed in #15140?
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.
OK, I had a quick look and this PR does not address #15140, so no worries about it!
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.
Hmmmm. I am wondering if we could mark an operand as output to indicate that it should not affect shape (or maybe using the WRITABLE flag is OK, but I fear that is a bit of a potential regression).
I suppose when there is no shape, the shape is just should be
()(and if there are reduce, but keepdims, axis, they are always inserted with size 1 right now).With your gufunc the question is whether you actually want the output to define the size in that case. Technically, that could be nice in some cases, unless you argue that the user should somehow provide
shape=...in that case.Although, for the iterator maybe that would be the same, and the gufunc machinery would just not pass the flag if there are no inputs?
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.
Oh, I am conflating two issues there. With no arguments we could already simply default to a 0-D iterator without much hassle probably...
How/if the output argument can affect the iterator shape is another issue.
(edit, but for another PR.)
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.
Indeed, for my strange case I do not think the output shape has to affect the iterator; it was about automatically allocating gufunc dimensions if needed, even if there are no inputs.