-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
feat(numpy): add signbit #23333
feat(numpy): add signbit #23333
Conversation
Thanks for contributing to Ivy! 😊👏 |
Hi @KareemMAX. One test Edit: PR failed after 72 minutes |
Frontend Task ChecklistIMPORTANT NOTICE 🚨:The Ivy Docs represent the ground truth for the task descriptions and this checklist should only be used as a supplementary item to aid with the review process. Please note that the contributor is not expected to understand everything in the checklist. It's mainly here for the reviewer to make sure everything has been done correctly 🙂 LEGEND 🗺:
CHECKS 📑:
|
No worries @RohitSgh, as the automatic comment has mentioned, feel free to ignore those tests. |
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.
Hey @RohitSgh,
Great work, I've pointed out a small detail that I think need to be made before we proceed with the final tests. Also if you can change the dtypes from float
to valid
. Otherwise LGTM 🚀 .
Thanks
ivy/functional/frontends/numpy/mathematical_functions/floating_point_routines.py
Outdated
Show resolved
Hide resolved
Thanks for the review @KareemMAX. By the way, is the implementation memory efficient? It uses |
if dtype is None: | ||
dtype = ivy.dtype(x) | ||
zero = ivy.zeros_like(x, dtype=dtype) | ||
return ivy.less(x, zero) |
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.
My bad 😅, I forgot to mention that as will.
if dtype is None: | |
dtype = ivy.dtype(x) | |
zero = ivy.zeros_like(x, dtype=dtype) | |
return ivy.less(x, zero) | |
return x < 0 |
I guess that would be a more efficient solution. I removed dtype
as it's supposed to be handled by ufunc
.
Also I'm not sure a bit about this implementation, as I've seen a case where the sign bit is toggled with the value 0 (-0
). Can you research about how this might impact this implementation? I believe it might
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.
These are my findings when I tried np.signbit
on my console
>>> numpy.signbit(-0.0)
True
>>> numpy.signbit(0.0)
False
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.
And
>>> numpy.signbit(-0)
False
Actually it was summarized here as well https://note.nkmk.me/en/python-numpy-sign-signbit-copysign/
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.
PR Compliance Checks Passed!
Tried to handle the situation by using https://numpy.org/doc/stable/reference/routines.logic.html and https://numpy.org/doc/stable/reference/generated/numpy.arctan2.html, @KareemMAX |
Hi @KareemMAX. Can you please review the changes? Thanks! |
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.
Hey @RohitSgh,
I've tried to add some fixes to your code. But we need to merge to main to ensure that you are not changing the demos submodule which looks like you have edited by mistake.
Also tests are failing, please look at them.
Hi @KareemMAX. The failing PR are of type |
Yes @RohitSgh, you should ignore pytest -v ivy_tests/test_ivy/test_frontends/test_numpy/test_mathematical_functions/test_floating_point_routines.py::test_numpy_signbit Also, demos seems to still be conflicting 😅 |
The test couldn't find Any idea on how to proceed, @KareemMAX ? Link |
@RohitSgh, the mentioned PR does add a numpy frontend function. You are trying to call an ivy function that doesn't exist |
|
This is numpy frontend, not an ivy function.
You can use |
But it is indeed an proposed function which is listed in #1525. Our Also, https://unify.ai/docs/ivy/overview/contributing/open_tasks.html#frontend-apis suggests that we can use composition of proposed function as well. Another query, if Regarding |
As I mentioned before, this list is for frontend functions. There is no
Yes, I guess you can use |
Earlier, the error were
Added two Is it fine? |
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.
Hey @RohitSgh, I requested the help of our team internally to know if you are doing the right thing. Here is what @AnnaTz thinks:
You shouldn't use
assume(casting == "same_kind")
, neitherassume(dtype != "bool")
. The latter should be avoided by adding@with_unsupported_dtypes
to the function. About thecasting
, your function implementation should be able to handle all casting modes. There are more arguments that are not being handled either, onlyx
is being used currently.
Also it seems like you removed docs/demos
, we can't merge your PR unless you revert back that change
Thank you for this PR, here is the CI results: This pull request does not result in any additional test failures. Congratulations! |
Completed in #26845 |
PR Description
Adding
signbit
https://numpy.org/doc/stable/reference/generated/numpy.signbit.html
Related Issue
Close #23332
Checklist
Socials:
https://x.com/iRohitSgh
https://www.linkedin.com/in/iRohitSgh