8000 ENH: stats.tvar/tstd/tsem: add array API support by mdhaber · Pull Request #21036 · scipy/scipy · GitHub
[go: up one dir, main page]

Skip to content

ENH: stats.tvar/tstd/tsem: add array API support #21036

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

Merged
merged 8 commits into from
Jun 25, 2024
Merged

Conversation

mdhaber
Copy link
Contributor
@mdhaber mdhaber commented Jun 24, 2024

Reference issue

Toward gh-20544

What does this implement/fix?

Adds array API support to tvar, tstd, and tsem.

@mdhaber mdhaber added scipy.stats enhancement A new feature or improvement array types Items related to array API support and input array validation (see gh-18286) labels Jun 24, 2024
Copy link
Member
@lucascolley lucascolley left a comment

Choose a reason for hiding this comment

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

can take a closer look later but all looks good from a scan

@mdhaber
Copy link
Contributor Author
mdhaber commented Jun 24, 2024

I will push again once I fix the torch issues and confirm locally. (I have torch and JAX set up on my Mac, not this Windows machine, which has CuPy.)

Copy link
Member
@j-bowhay j-bowhay left a comment

Choose a reason for hiding this comment

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

Thanks LGTM!

The comment on line 63 of test_stats.py is somewhat amusing!

def test_tmean(self, xp):
x = xp.asarray(X)
x = xp.asarray(X.tolist()) # use default dtype of xp
Copy link
Member

Choose a reason for hiding this comment

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

This is a neat trick I hadn't thought of doing this

Copy link
Member

Choose a reason for hiding this comment

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

How portable is this out of interest?

Copy link
Contributor Author
@mdhaber mdhaber Jun 25, 2024

Choose a reason for hiding this comment

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

tolist says it converts NumPy scalars to Python scalars, and it sounds like a Python float is all but guaranteed to be an IEEE 754 double (also here). I know the standard doesn't specify everything, so maybe that's not enough to guarantee portability, but hopefully it's good enough for the precision we look for in the tests.

@j-bowhay j-bowhay merged commit fffcaa8 into scipy:main Jun 25, 2024
34 checks passed
@j-bowhay j-bowhay added this to the 1.15.0 milestone Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
array types Items related to array API support and input array validation (see gh-18286) enhancement A new feature or improvement scipy.stats
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0