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
enable equal_nan for complex values in isclose #63571
Conversation
[ghstack-poisoned]
ghstack-source-id: 3bbc12174311b6cac6628a047b8fdd018823a471 Pull Request resolved: #63571
|
if (equal_nan && self.is_floating_point()) { | ||
close.__ior__((self != self).__iand__(other != other)); | ||
if (equal_nan && (self.is_floating_point() || self.is_complex())) { | ||
close.__ior__(self.isnan().__iand__(other.isnan())); |
Although it is functionally equal, self.isnan()
is a lot more legible than self != self
I guess so. The compiler can probably optimize away the extra function call.
tests = ( | ||
(complex(1, 1), complex(1, float('nan')), False), | ||
(complex(1, 1), complex(float('nan'), 1), False), | ||
(complex(float('nan'), 1), complex(float('nan'), 1), True), | ||
(complex(float('nan'), 1), complex(1, float('nan')), False), | ||
(complex(float('nan'), float('nan')), complex(float('nan'), float('nan')), True), | ||
) |
The test cases will be merged into the ones above later in the stack (#63572), when TestCase.assertEqual
stops treating complex components separately.
if dtype.is_floating_point: | ||
a = b = torch.nan | ||
else: | ||
a = complex(torch.nan, 0) | ||
b = complex(0, torch.nan) |
We can also split this into two tests for float and complex.
[ghstack-poisoned]
Cool! And it looks like the docs don't need to be updated, either.
@mruberry has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
Summary: Pull Request resolved: pytorch#63571 Test Plan: Imported from OSS Reviewed By: malfet, ngimel Differential Revision: D30560127 Pulled By: mruberry fbshipit-source-id: 8958121ca24e7c139d869607903aebbe87bc0740
Stack from ghstack:
Differential Revision: D30560127
The text was updated successfully, but these errors were encountered: