Introduce ReductionOperation class, accept 'initial' in reductions#238
Merged
Introduce ReductionOperation class, accept 'initial' in reductions#238
ReductionOperation class, accept 'initial' in reductions#238Conversation
This was referenced Dec 28, 2021
0c4efb9 to
01f5f0f
Compare
kaushikcfd
approved these changes
Dec 28, 2021
Collaborator
kaushikcfd
left a comment
There was a problem hiding this comment.
This almost looks great! Found some minor numpy compat issues, feel free to merge after that.
Thanks!
|
|
||
| def prod(a: Array, axis: Optional[Union[int, Tuple[int]]] = None) -> Array: | ||
| def prod(a: Array, axis: Optional[Union[int, Tuple[int]]] = None, | ||
| initial: Any = 1) -> Array: |
Collaborator
There was a problem hiding this comment.
Should this be _NoValue as well? Numpy does it, see https://numpy.org/doc/stable/reference/generated/numpy.prod.html#numpy.prod.
Owner
Author
There was a problem hiding this comment.
I think this is OK. Numpy will return 1 for an empty prod. I think for an immutable object like 1 it does not matter whether that's done via _NoValue and then setting internally, or directly like this.
8c02222 to
0a348e1
Compare
0a348e1 to
acf72ae
Compare
kaushikcfd
approved these changes
Dec 29, 2021
Collaborator
kaushikcfd
left a comment
There was a problem hiding this comment.
Found out some more places where the implementation disagrees Numpy, good to go after that.
acf72ae to
b3e359c
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This replaces the strings we used to use to identify reductions with something a bit more structured. The impulse for this came from inducer/arraycontext#129, which needs to supply
initialto array reductions to match thenumpyinterface for empty min/max reductions. This only adds very minimal support for supplyinginitial, in that it allows the neutral element to be passed (and obtaining that is what led to the structured reduction op types), and it better mimics numpy's behavior for empty reductions.cc @majosm