Skip to content

Conversation

@inducer
Copy link
Owner

@inducer inducer commented Dec 28, 2021

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 initial to array reductions to match the numpy interface for empty min/max reductions. This only adds very minimal support for supplying initial, 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

Copy link
Collaborator

@kaushikcfd kaushikcfd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be _NoValue as well? Numpy does it, see https://numpy.org/doc/stable/reference/generated/numpy.prod.html#numpy.prod.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@inducer inducer force-pushed the reduction-op-obj branch 2 times, most recently from 8c02222 to 0a348e1 Compare December 29, 2021 14:12
@inducer inducer requested a review from kaushikcfd December 29, 2021 14:12
Copy link
Collaborator

@kaushikcfd kaushikcfd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found out some more places where the implementation disagrees Numpy, good to go after that.

@inducer inducer enabled auto-merge (rebase) December 29, 2021 17:32
@inducer inducer merged commit 8cf2575 into main Dec 29, 2021
@inducer inducer deleted the reduction-op-obj branch December 29, 2021 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants