Introduce ReductionOperation class, accept 'initial' in reductions - #238
Conversation
0c4efb9 to
01f5f0fCompare
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!
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| 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: |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
8c02222 to
0a348e1Compare0a348e1 to
acf72aeCompare
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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
acf72ae to
b3e359cCompare
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