Repository: OpenMined/PySyft

Issue:
AST dtype arg should only accept long and int
**Is your feature request related to a problem? Please describe.**
Currently the dtype arg for initialising AdditiveSharingTensor accepts None, "long", "int", "custom". But as an attempt for standardisation we don't want user to be able to call with arg "custom" it is there only for internal operations(like secureNN).

**Describe the solution you'd like**
Raise a ValueError with a response along the lines of "Invalid value for dtype arg, use long or int"

**Describe alternatives you've considered**

**Additional context**



Discussion:

Resolving patch:
diff --git a/syft/frameworks/torch/mpc/securenn.py b/syft/frameworks/torch/mpc/securenn.py
--- a/syft/frameworks/torch/mpc/securenn.py
+++ b/syft/frameworks/torch/mpc/securenn.py
@@ -70,6 +70,9 @@ def flip(x, dim, dtype):
     """
     Reverse the order of the elements in a tensor
     """
+    assert (
+        x.dtype != "custom"
+    ), "`custom` dtype shares are unsupported in SecureNN, use dtype = `long` or `int` instead"
     indices = torch.arange(x.shape[dim] - 1, -1, -1).type(dtype)
 
     if hasattr(x, "child") and isinstance(x.child, dict):
@@ -141,6 +144,10 @@ def select_share(alpha_sh, x_sh, y_sh):
     Return:
         z_sh = (1 - alpha_sh) * x_sh + alpha_sh * y_sh
     """
+    assert (
+        alpha_sh.dtype == x_sh.dtype == y_sh.dtype != "custom"
+    ), "`custom` dtype shares are unsupported in SecureNN, use dtype = `long` or `int` instead"
+
     alice, bob = alpha_sh.locations
     crypto_provider = alpha_sh.crypto_provider
     L = alpha_sh.field
@@ -343,6 +350,9 @@ def share_convert(a_sh):
         An additive sharing tensor with shares in field L-1
     """
     assert isinstance(a_sh, sy.AdditiveSharingTensor)
+    assert (
+        a_sh.dtype != "custom"
+    ), "`custom` dtype shares are unsupported in SecureNN, use dtype = `long` or `int` instead"
 
     workers = a_sh.locations
     crypto_provider = a_sh.crypto_provider
@@ -441,6 +451,9 @@ def relu_deriv(a_sh):
         1 if Dec(a_sh) > 0
         encrypted in an AdditiveSharingTensor
     """
+    assert (
+        a_sh.dtype != "custom"
+    ), "`custom` dtype shares are unsupported in SecureNN, use dtype = `long` or `int` instead"
 
     alice, bob = a_sh.locations
     crypto_provider = a_sh.crypto_provider
@@ -477,6 +490,9 @@ def relu(a_sh):
         Dec(a_sh) > 0
         encrypted in an AdditiveSharingTensor
     """
+    assert (
+        a_sh.dtype != "custom"
+    ), "`custom` dtype shares are unsupported in SecureNN, use dtype = `long` or `int` instead"
 
     alice, bob = a_sh.locations
     crypto_provider = a_sh.crypto_provider
@@ -499,6 +515,9 @@ def division(x_sh, y_sh, bit_len_max=None):
     Returns:
         element-wise integer division of x_sh by y_sh
     """
+    assert (
+        x_sh.dtype == y_sh.dtype != "custom"
+    ), "`custom` dtype shares are unsupported in SecureNN, use dtype = `long` or `int` instead"
     alice, bob = x_sh.locations
     crypto_provider = x_sh.crypto_provider
     L = x_sh.field
@@ -556,6 +575,10 @@ def maxpool(x_sh):
         maximum value as an AdditiveSharingTensor
         index of this value in the flattened tensor as an AdditiveSharingTensor
     """
+    assert (
+        x_sh.dtype != "custom"
+    ), "`custom` dtype shares are unsupported in SecureNN, use dtype = `long` or `int` instead"
+
     if x_sh.is_wrapper:
         x_sh = x_sh.child
     alice, bob = x_sh.locations
@@ -606,6 +629,10 @@ def maxpool_deriv(x_sh):
         an AdditiveSharingTensor of the same shape as x_sh full of zeros except for
         a 1 at the position of the max value
     """
+    assert (
+        x_sh.dtype != "custom"
+    ), "`custom` dtype shares are unsupported in SecureNN, use dtype = `long` or `int` instead"
+
     alice, bob = x_sh.locations
     crypto_provider = x_sh.crypto_provider
     L = x_sh.field
@@ -653,6 +680,9 @@ def maxpool2d(a_sh, kernel_size: int = 1, stride: int = 1, padding: int = 0):
         stride: the stride of the window
         padding: implicit zero padding to be added on both sides
     """
+    assert (
+        a_sh.dtype != "custom"
+    ), "`custom` dtype shares are unsupported in SecureNN, use dtype = `long` or `int` instead"
     assert len(a_sh.shape) == 4
 
     # Change to tuple if not one
diff --git a/syft/frameworks/torch/tensors/interpreters/additive_shared.py b/syft/frameworks/torch/tensors/interpreters/additive_shared.py
--- a/syft/frameworks/torch/tensors/interpreters/additive_shared.py
+++ b/syft/frameworks/torch/tensors/interpreters/additive_shared.py
@@ -64,12 +64,15 @@ def __init__(
                 raise ValueError("Field cannot be None for custom dtype")
             self.field = field
             self.torch_dtype = torch.int32 if field <= 2 ** 32 else torch.int64
-        elif dtype == "long":
+        elif dtype == "long" or dtype == "int64":
             self.field = 2 ** 64
             self.torch_dtype = torch.int64
-        elif dtype == "int":
+            self.dtype = "long"
+        elif dtype == "int" or dtype == "int32":
             self.field = 2 ** 32
             self.torch_dtype = torch.int32
+            self.dtype = "int"
+
         else:
             if dtype is not None:
                 raise ValueError("Invalid dtype value: " + dtype)


Test patch: