Skip to content

Special case when NaNs present in statistical functions #335

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 3 commits into from
Dec 6, 2021

Conversation

honno
Copy link
Member

@honno honno commented Nov 15, 2021

Adds a special case for the two functions that any NaNs present in computed elements should result in NaN. Hopefully I've used the correct language here.

Per discussion with @kgryte, this is expected behaviour.

>>> min([0., float("nan")])
0.0
>>> np.min(np.asarray([0., float("nan")]))
nan
>>> torch.min(torch.as_tensor([0., float("nan")]))
tensor(nan)

@rgommers
Copy link
Member

Do note this does mean PyTorch is wrong.

I don't see that in the example. tensor(nan) (as a 0-D array) looks like the expected answer to me (reduction over 1-D array -> 0-D array). The numpy.array_api answer should match that, but it may not (?).

@honno
Copy link
Member Author

honno commented Nov 15, 2021

Do note this does mean PyTorch is wrong.

I don't see that in the example. tensor(nan) (as a 0-D array) looks like the expected answer to me (reduction over 1-D array -> 0-D array). The numpy.array_api answer should match that, but it may not (?).

Oops I was thinking of a different discussion—I didn't even read my own example! PR description updated accordingly.

@honno
Copy link
Member Author

honno commented Nov 15, 2021

@kgryte I suppose this special case applies to all statistical functions? If that's the case, I can update this PR.

@kgryte
Copy link
Contributor

kgryte commented Nov 15, 2021

@honno Yes, that is correct. NaN values should propagate for the other statistical functions. Feel free to update this PR. Thanks!

@honno honno changed the title Special case when NaNs present in min() and max() Special case when NaNs present in statistical functions Nov 16, 2021
@honno honno requested a review from kgryte November 16, 2021 11:16
@kgryte kgryte added this to the v2021 milestone Nov 29, 2021
@kgryte kgryte added Maintenance Bug fix, typo fix, or general maintenance. topic: Statistics Statistics. labels Nov 29, 2021
This commit brings the formatting and language in-line with element-wise and array object methods.
Copy link
Contributor

@kgryte kgryte left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks, @honno!

@kgryte kgryte merged commit 545d7f1 into data-apis:main Dec 6, 2021
@honno honno deleted the minmax-special branch November 1, 2022 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Maintenance Bug fix, typo fix, or general maintenance. topic: Statistics Statistics.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants