-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Implementing NumPy-like function torch.signbit() #41589
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
💊 CI failures summary and remediationsAs of commit 9db39c6 (more details on the Dr. CI page): ✅ None of the CI failures appear to be your fault 💚
🚧 3 fixed upstream failures:These were probably caused by upstream breakages that were already fixed.
Please rebase on the
|
eb278ce to
bd179e2
Compare
|
Hi, @mruberry ! I implemented the |
bd179e2 to
b65627a
Compare
Great! Thanks @Kiyosora! I'll take a look soon. |
ailzhang
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.
stamping for xla fix :D Thanks!
mruberry
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.
Thank you, @ailzhang, for helping with the XLA dispatch!
This is a well-written PR, @Kiyosora, thanks for submitting it!
I made a few comments about the test and docs, but also have a question about the design of this PR: does it need a new TensorIterator kernel, or can it be implemented using existing PyTorch functions? I'm curious to hear your thoughts.
7b76fb9 to
359d5d1
Compare
|
Hi, @mruberry ! Thank you so much for your advice & Sorry for my late reply. 😢 |
aten/src/ATen/native/UnaryOps.cpp
Outdated
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's true that clamp is not implemented for complex tensors, but this should probably say:
"signbit is not implemented for complex tensors."
No need for a "yet," either, since we have no plans to implement it in the future -- it's not even clear how to define a function like signbit on complex values. NumPy, for example, also throws an error when signbit is given a complex input.
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.
Also: better add a check that result is bool
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.
Addressed! Thanks for the correction.
aten/src/ATen/native/UnaryOps.cpp
Outdated
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.
This doesn't need to promote inputs or cast to an output. There's only one input and for this first iteration signbit doesn't need to support non-bool outputs.
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.
Got it! thanks for your explanation.
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.
(Tensor self), no star needed here
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.
Addressed!
torch/_torch_docs.py
Outdated
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.
\operatorname{signbit} ?
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.
The formulas has been deleted, Sorry for my carelessness.
test/test_torch.py
Outdated
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.
This regexes will need to be updated to refer to signbit
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.
Addressed!
mruberry
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.
Overall looks very good!
I made a few comments with updates/corrections.
5e95f7f to
775f095
Compare
|
Hi, @mruberry. I'm sorry that my carelessness caused some avoidable mistakes. |
775f095 to
9db39c6
Compare
mruberry
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.
Nice work, @Kiyosora!
Let me know if you're interested in implementing another function or would like to look at a different kind of issue.
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.
torch.signbit().