-
Couldn't load subscription status.
- Fork 25.7k
Use std::isnan instead of self-comparison. #18021
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
Signed-off-by: Edward Z. Yang <ezyang@fb.com>
aten/src/ATen/native/Sorting.cpp
Outdated
| 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)); |
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.
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.
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.
Looks like you're right: https://godbolt.org/z/HhgWIu
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 believe you should be able to use numeric traits to test if scalar_t is a floating point type.
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.
It looks like someone already wrote a function do this, I'm going to use it.
|
LGTM |
|
But it doesn't work on Windows XD |
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.
Looks good to me, thanks!
|
@pytorchbot merge this please |
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
|
This pull request has been merged in d3e3b24. |
Stack:
Signed-off-by: Edward Z. Yang ezyang@fb.com
Differential Revision: D14460699