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
ENH: stats.variation: add array-API support #20647
Conversation
# torch | ||
sup.filter(UserWarning, "std*") | ||
y = variation(x) | ||
xp_assert_equal(y, xp.asarray(xp.nan, dtype=x.dtype)) |
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.
Not a big deal, but you could change np.zeros(5)
to [0.]*5
to avoid the explicit dtype, if we prefer testing the default type. Then again, one could argue that now this tests both the default type and float64
(if they are different), and coverage is a good thing. Either way; just an observation.
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.
I meant that since you changed np.zeros
to [0.]*
, you should be able to do:
xp_assert_equal(y, xp.asarray(xp.nan, dtype=x.dtype)) | |
xp_assert_equal(y, xp.asarray(xp.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.
Seems straightforward, and I'm not seeing anything wrong. I'll take another pass after the merge conflict is resolved and we hear back about what we should do with the JAX-incompatible code.
scipy/stats/_variation.py
Outdated
result[i] = np.copysign(result[i], mean_a[i]) | ||
return result[()] | ||
std_a = xp.std(a, axis=axis, correction=0) | ||
result = xp.where(std_a > 0, xp.copysign(xp.asarray(xp.inf), mean_a), 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.
Oops. Looks like we need an xp_copysign
in the meantime (j-bowhay#4). I'd recommend installing array_api_strict
.
towards #20544