Repository navigation
Closes 4425 (adds axis handling to mean, var, std) - #4442
Merged
Merged
Conversation
drculhane
marked this pull request as ready for review
May 22, 2025 19:14
ajpotts
requested changes
May 23, 2025
ajpotts
left a comment
Contributor
There was a problem hiding this comment.
This looks great! Thank you for taking care of this!
However, I think we should refactor to match the other reduction functions by calling the _common_reduction function.
drculhane
force-pushed
the
Closes-4425
branch
5 times, most recently
from
May 28, 2025 11:12
6310d74 to
4bd39e5
Compare
ajpotts
approved these changes
May 30, 2025
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.
Closes #4425 and #4443
Addendum to addendum
Rebased to current master to eliminate conflicts.
Addendum
mean is now in common_reductions
std and var are now in common_stats_reductions. Another reduction function was needed because std and var have the ddof parameter, which the other functions don't have.
Chapel-side, the functions mean and meanReduce have been renamed to meanAll and mean.
The functions variance and varReduce have been renamed to varAll and varReduce ("var" is a reserved chapel keyword).
The functions std and stdReduce have been renamed to stdAll and stdReduce (because they have to use the same naming convention as var, since they're in the same reduction group).
Other python functions that call mean, var and std have had their interfaces updated to the names above.
This adds axis handling (including negative axis handling) to ak.mean, ak.var and ak.std in numpy/pdarrayclass.py, but not (yet) to similar functions in segarray, groupby and array_api.
Notes about the code:
ak.mean, ak.var and ak.std now allow axis and keepdims arguments. They all call utility functions to parse the axis, and to validate negative axes. If no axis slicing is required, they operate as they always did (calling the server functions mean, var, or std). If there is axis slicing, they call meanReduce, varReduce or stdReduce. Note that these Reduce functions were already there server-side, but weren't being used by ak.mean, ak.var, and ak.std.
Worth noting: the three python functions (mean, var, std) are almost identical. The only differences are (1) the chapel functions they call, and (2) mean doesn't have a ddof arg, while var and std do.
Also worth noting: timeclass.py includes a std function which calls ak.std, so I had to rewrite the interface to be compatible with ak.std.
Also also worth noting: similar to python side, the functions meanReduce, varReduce and stdReduce are almost identical.
I added a call to validateNegativeAxes to meanReduce, varReduce and stdReduce (even though we're now doing the check python-side) as we discussed.
The docstrings for all three functions have been updated to include descriptions of the added parameters and behavior, and examples with the axis arguments.
Unit tests have also been added that use the axis arguments.