-
Notifications
You must be signed in to change notification settings - Fork 22.9k
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
Returns float from complex angle #36896
Conversation
Tensor result = at::empty({0}, self.options()); | ||
return out_impl(result, self); |
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.
why do we need this? don't we only call this function for complex tensors?
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.
ahhh I see. you are calling this method from abs for non complex tensors as well. I think it's a little misleading to call this method for non complex inputs because of its name. So, I think we can do two things here:
- change the name of the function to make it more generic.
- call this method for only complex inputs.
Whatever you prefer.
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.
maybe just add a word or two like
unary_op_impl_with_complex_to_float
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.
Good idea.
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 still think it will not be intuitive to a developer who is not familiar with this PR and looks at this code and it could be confusing. I would caution on the side of either removing "complex_to_float" from the name or adding descriptive comments specifically mentioning this function is also being used for real values.
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 updated the comment.
@@ -53,6 +80,18 @@ static inline Tensor unary_op_impl(const Tensor& self, OutImpl& out_impl) { | |||
return out_impl(result, self); | |||
} | |||
|
|||
template <typename OutImpl> | |||
static inline Tensor unary_op_impl_complex_to_float(const Tensor& self, OutImpl& out_impl) { | |||
if (self.is_complex()) { |
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.
maybe add TORCH_INTERNAL_ASSERT(self.is_complex());
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.
Left some minor comments but looks good otherwise :)
💊 Build failures summary and remediationsAs of commit 5ee8db2 (more details on the Dr. CI page):
🕵️ 2 new failures recognized by patternsThe following build failures do not appear to be due to upstream breakages: pytorch_linux_xenial_py3_6_gcc5_4_build (1/2)Step: "Build" (full log | pattern match details | 🔁 rerun)
|
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.
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.
Updates angle to return a float tensor, by default, when given complex inputs. This behavior is compatible with Python, NumPy, and C++. The implementation follows the former implementation for complex abs, extracting the logic into a common function for both abs and angle.
The test for complex abs's behavior in test_type_promotion.py is updated to also test the behavior of complex angle by comparing its results to NumPy's.