Repository: OpenMined/PySyft

Issue:
Fix precision with large storage fails
**Describe the bug**
The following operation fails

`lpt = torch.Tensor([-2., 4]).fix_prec(storage="large")`

**To Reproduce**
Steps to reproduce the behavior:
Use the above expression in a test and see the result:
`TypeError`
**Expected behavior**
The expression should not crash
**Screenshots**

**Desktop (please complete the following information):**

**Additional context**


Discussion:

Patch:
diff --git a/syft/frameworks/torch/tensors/interpreters/large_precision.py b/syft/frameworks/torch/tensors/interpreters/large_precision.py
index f836022c4e..bbc46e6b7f 100644
--- a/syft/frameworks/torch/tensors/interpreters/large_precision.py
+++ b/syft/frameworks/torch/tensors/interpreters/large_precision.py
@@ -74,7 +74,8 @@ class LargePrecisionTensor(AbstractTensor):
 
         # floor is applied otherwise, long float is not accurate
         self_scaled = np.vectorize(math.floor)(self_scaled)
-        self_scaled %= self.field
+        # https://github.com/numpy/numpy/issues/6464
+        self_scaled = np.remainder(self_scaled, np.array(self.field), casting="unsafe")
 
         # self_scaled can be an array of floats. As multiplying an array of int with an int
         # still gives an array of int, I think it should be because self.child is a float tensor at this point.


Test patch:
diff --git a/test/torch/tensors/test_large_precision.py b/test/torch/tensors/test_large_precision.py
index 74dc415f37..6eabf814f6 100644
--- a/test/torch/tensors/test_large_precision.py
+++ b/test/torch/tensors/test_large_precision.py
@@ -283,6 +283,14 @@ def test_share_sub(workers):
     assert torch.all(torch.eq(expected, y))
 
 
+def test_storage():
+    x = torch.tensor([1.0, 2.0, 3.0])
+    enlarged = x.fix_prec(storage="large")
+    restored = enlarged.float_precision()
+    # And now x and restored must be the same
+    assert torch.all(torch.eq(x, restored))
+
+
 # def test_share_mul(workers):
 #     alice, bob, james = (workers["alice"], workers["bob"], workers["james"])
 #