-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Implements torch.isclose for complex tensors #36456
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
💊 Build failures summary and remediationsAs of commit f2a1779 (more details on the Dr. CI page): 💚 💚 Looks good so far! There are no failures yet. 💚 💚 This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions on the GitHub issue tracker. This comment has been revised 11 times. |
|
Record from offline conversation: @ngimel and I are considering whether to implement this behavior which is more like cmath/NumPy or perform a component-wise comparison of complex values. The latter is probably more pragmatically useful. We'll extend that discussion with an issue. Update: the issue is #36462. |
e08ecb1 to
43aeaf9
Compare
ngimel
left a comment
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.
facebook-github-bot
left a comment
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.
@mruberry has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Previously torch.isclose would RuntimeError when called on complex tensors. This update updates torch.isclose to run on complex tensors and be consistent with NumPy. However, NumPy's handling of NaN, -inf, and inf values is odd, so I adopted Python's cmath.isclose behavior when dealing with them. See numpy/numpy#15959 for more on NumPy's behavior.
While implementing complex isclose I also simplified the isclose algorithm to:
abs(a - b) <= (atol + abs(rtol * b))This PR also documents torch.isclose, since it was undocumented, and adds multiple tests for its behavior to test_torch.py since it had no dedicated tests.
The PR leaves equal_nan=True with complex inputs an error for now, pending the outcome of numpy/numpy#15959.