Repository: OpenMined/PySyft

Issue:
Implement Default geometric Functionality for Base Tensor Type
**User Story A:** As a Data Scientist using Syft's Base Tensor type, we want to implement a default method for computing operations on a Tensor of arbitrary type. For this ticket to be complete, geometric_() should perform the operation inline. For a reference on the operation this performs check out [PyTorch](http://pytorch.org/docs/master/tensors.html)'s documentation.

**Acceptance Criteria:**
- If the Base Tensor type's attribute "encrypted" is set to True, it should return a NotImplemented error.
- a unit test demonstrating the correct operation on the Base Tensor type implemented over int and float Tensors.
- inline documentation in the python code. For inspiration on inline documentation, please check out [PyTorch](http://pytorch.org/docs/master/tensors.html)'s documentation for this operator.

Discussion:
nish21: @bharathgs addressed the review, thank you.
nish21: @bharathgs please take a look now

Patch:
diff --git a/syft/tensor.py b/syft/tensor.py
index b2142167d4..6d040cf1ed 100644
--- a/syft/tensor.py
+++ b/syft/tensor.py
@@ -862,6 +862,25 @@ class TensorBase(object):
         out = np.random.uniform(low=low, high=high, size=self.shape())
         return TensorBase(out)
 
+    def geometric_(self, p):
+        """Fills the given tensor in-place with samples from a geometric distribution
+        with given probability of success of an individual trial.
+
+        Parameters
+        ----------
+        p: float
+            Probability of success of an individual trial
+
+        Returns
+        -------
+        TensorBase
+            Caller with values in-place
+        """
+        if self.encrypted:
+            return NotImplemented
+        self.data = np.random.geometric(p, size=self.shape())
+        return self
+
     def cauchy_(self, median=0, sigma=1):
         """Fills the tensor in-place with numbers drawn from the Cauchy distribution:
 


Test patch:
diff --git a/tests/test_tensor.py b/tests/test_tensor.py
index 4c5598db5b..d2b2240133 100644
--- a/tests/test_tensor.py
+++ b/tests/test_tensor.py
@@ -716,6 +716,14 @@ class uniformTests(unittest.TestCase):
         self.assertTrue(np.all(t1.data > 0) and np.all(t1.data < 3))
 
 
+class geometricTests(unittest.TestCase):
+    def test_geometric_(self):
+        t1 = TensorBase(np.zeros((4, 4)))
+        out = t1.geometric_(p=0.5)
+        self.assertTupleEqual(t1.data.shape, out.data.shape)
+        self.assertTrue(np.all(out.data > 0))
+
+
 class fillTests(unittest.TestCase):
     def test_fill_(self):
         t1 = TensorBase(np.array([1, 2, 3, 4]))