-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
ENH: stats.alexandergovern
: vectorize calculation for n-D arrays
#21089
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
Conversation
if np.any([(sample == sample[0]).all() for sample in samples]): | ||
msg = "An input array is constant; the statistic is not defined." | ||
warnings.warn(stats.ConstantInputWarning(msg), stacklevel=2) | ||
return AlexanderGovernResult(np.nan, np.nan) |
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.
See " Special case: statistic is NaN when variance is zero" below.
To produce a warning, I was thinking I'd replace means - var_w
with _demean(means, var_w)
when gh-21068 merges.
scipy/stats/_stats_py.py
Outdated
warnings.warn(stats.ConstantInputWarning(msg), stacklevel=2) | ||
return AlexanderGovernResult(np.nan, np.nan) | ||
samples = _alexandergovern_input_validation(samples, nan_policy, axis) | ||
samples = [np.moveaxis(sample, axis, -1) for sample in samples] |
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.
Important for the rest of the calculation:
axis
0 corresponds with separate samplesaxis
-1 is along a given sample- any other axes are batch dimensions.
raise ValueError("Input sample size must be greater than one.") | ||
if np.isinf(sample).any(): | ||
raise ValueError("Input samples must be finite.") |
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.
Don't want to error out for inf
s in a single slice. Instead, the user will get a warning and NaN.
args_int16 = [np.asarray(arg, dtype=np.int16) for arg in args] | ||
args_int32 = [np.asarray(arg, dtype=np.int32) for arg in args] | ||
args_uint8 = [np.asarray(arg, dtype=np.uint8) for arg in args] | ||
args_float64 = [np.asarray(arg, dtype=np.float64) for arg in args] |
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.
Arrays happen to be the same size, but conceptually there are several separate samples.
@lucascolley re #21097 (comment), here's an example of adding |
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.
LGTM, one small question left.
Thanks @mdhaber . |
Reference issue
Toward gh-20544
What does this implement/fix?
Vectorizes
alexandergovern
for n-D arrays (i.e. adds nativeaxis
support).Additional information
I've also made some tweaks here that will reduce the diff when we add array API support.