Skip to content
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

Added support for negative numbers in reciprocal method #4048 #4065

Merged
merged 5 commits into from
Aug 23, 2020

Conversation

addy369
Copy link
Contributor

@addy369 addy369 commented Aug 22, 2020

Description

This PR fixes #4048
Added support for negative numbers when use different methods in Reciprocal.
Uses a signum function to achieve this
Suggestions are welcome!

Affected Dependencies

  • None

How has this been tested?

  • No additional tests are needed. Changed the default value in test_reciprocal(): function to include negative numbers too
  • Ran pytest test/torch/tensors/test_precision.py without issue

Checklist

@addy369 addy369 requested a review from a team as a code owner August 22, 2020 13:44
@codecov
Copy link

codecov bot commented Aug 22, 2020

Codecov Report

Merging #4065 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #4065   +/-   ##
=======================================
  Coverage   94.77%   94.78%           
=======================================
  Files         205      205           
  Lines       21187    21195    +8     
=======================================
+ Hits        20081    20089    +8     
  Misses       1106     1106           
Impacted Files Coverage Δ
...ft/frameworks/torch/tensors/interpreters/native.py 91.48% <100.00%> (ø)
...frameworks/torch/tensors/interpreters/precision.py 96.85% <100.00%> (+0.05%) ⬆️
test/torch/tensors/test_additive_shared.py 100.00% <100.00%> (ø)
test/torch/tensors/test_precision.py 100.00% <100.00%> (ø)

Copy link
Member

@marload marload left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! But I would like to request some changes.

@@ -468,7 +468,7 @@ def matmul(self, *args, **kwargs):
__matmul__ = matmul
mm = matmul

def reciprocal(self, method="NR", nr_iters=10):
def reciprocal(self, method="division", nr_iters=10):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, NR is much faster than division. Is there a reason for changing this? 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#4036 (comment)... I saw this and made a change. I think now keeping it as NR should not be a problem.

pos = sgn
neg = sgn - 1
sgn = pos + neg
self = sgn * self
Copy link
Member

@marload marload Aug 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part duplicates many parts with NR. Can you remove this duplication? 😎

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes will do that!!

@addy369
Copy link
Contributor Author

addy369 commented Aug 22, 2020

Can you have a look again @marload ? I have added a modulus and signum function instead

Copy link
Member

@marload marload left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@addy369
Copy link
Contributor Author

addy369 commented Aug 23, 2020

@marload it showing that I still need a review from openmined/cryptography! So that means anyone from that team can review right?

Comment on lines +511 to +512
result = 2 * result - result * result * new_self
return result * self.signum()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

Copy link
Member

@Syzygianinfern0 Syzygianinfern0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very well implemented. Just a few code-quality comments. 😄

Copy link
Member

@Syzygianinfern0 Syzygianinfern0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

Also check out this

@Syzygianinfern0 Syzygianinfern0 merged commit 20e36d8 into OpenMined:master Aug 23, 2020
rav1kantsingh pushed a commit to rav1kantsingh/PySyft that referenced this pull request Oct 29, 2020
* Support for negative numbers

* negative numbers support

* Negative numbers support for reciprocal

* negative nums support for reciprocal method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reciprocal test enchantment negative numbers
3 participants