Skip to content

Conversation

@ezyang
Copy link
Contributor

@ezyang ezyang commented Mar 14, 2019

Stack:

Signed-off-by: Edward Z. Yang ezyang@fb.com

Differential Revision: D14460699

Signed-off-by: Edward Z. Yang <ezyang@fb.com>
@ezyang ezyang requested a review from t-vi March 14, 2019 16:45
k - 1,
[](scalar_t x, scalar_t y) -> bool {
return ((x != x && y == y) || (x > y));
return ((std::isnan(x) && !std::isnan(y)) || (x > y));
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this work correctly and efficiently when scalar_t is an integral type? I think this casts it to a double and still does a NaN check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like you're right: https://godbolt.org/z/HhgWIu

Copy link
Contributor

@resistor resistor Mar 14, 2019

Choose a reason for hiding this comment

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

I believe you should be able to use numeric traits to test if scalar_t is a floating point type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like someone already wrote a function do this, I'm going to use it.

@resistor
Copy link
Contributor

LGTM

@ezyang
Copy link
Contributor Author

ezyang commented Mar 14, 2019

But it doesn't work on Windows XD

Copy link
Collaborator

@t-vi t-vi left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks!

@t-vi
Copy link
Collaborator

t-vi commented Mar 14, 2019

@pytorchbot merge this please

@pytorchbot pytorchbot added the merge-this-please Was marked for merge with @pytorchbot merge this please label Mar 14, 2019
zdevito pushed a commit to zdevito/ATen that referenced this pull request Mar 15, 2019
Summary:
Pull Request resolved: pytorch/pytorch#18021
ghimport-source-id: 03423ba47ba5900c2b400c4457b148147ce8b35e

Stack:
* **#18021 Use std::isnan instead of self-comparison.**

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

Reviewed By: soumith

Differential Revision: D14460699

fbshipit-source-id: d8feb7f3f0e93996bd1b4f4aea163548b1d12437
@facebook-github-bot
Copy link
Contributor

This pull request has been merged in d3e3b24.

@zou3519 zou3519 deleted the gh/ezyang/16/head branch March 25, 2019 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-this-please Was marked for merge with @pytorchbot merge this please

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants