prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Implement Default sum Functionality for Base Tensor Type
  **User Story A:** As a Data Scientist using Syft's Base Tensor type, I want to leverage a default method for computing operations on a Tensor of arbitrary type. For this ticket to be complete, sum() should return a new tensor. 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.
  
  </issue>
  <code>
  [start of syft/tensor.py]
  1 import numpy as np
  2 
  3 def _ensure_ndarray(arr):
  4     if not isinstance(arr, np.ndarray):
  5         arr = np.array(arr)
  6 
  7     return arr
  8 
  9 class TensorBase(object):
  10     """
  11     A base tensor class that perform basic element-wise operation such as 
  12     addition, subtraction, multiplication and division
  13     """
  14 
  15     def __init__(self, arr_like, encrypted=False):
  16         self.data = _ensure_ndarray(arr_like)
  17         self.encrypted = encrypted
  18 
  19     def __add__(self, arr_like):
  20         """Performs element-wise addition between two array like objects"""
  21         if self.encrypted:
  22             return NotImplemented
  23 
  24         arr_like = _ensure_ndarray(arr_like)
  25         return self.data + arr_like
  26 
  27     def __iadd__(self, arr_like):
  28         """Performs in place element-wise addition between two array like objects"""
  29         if self.encrypted:
  30             return NotImplemented
  31 
  32         arr_like = _ensure_ndarray(arr_like)
  33         self.data = self.data + arr_like
  34         return self.data
  35 
  36     def __sub__(self, arr_like):
  37         """Performs element-wise subtraction between two array like objects"""
  38         if self.encrypted:
  39             return NotImplemented
  40 
  41         arr_like = _ensure_ndarray(arr_like)
  42         return self.data - arr_like
  43 
  44     def __isub__(self, arr_like):
  45         """Performs in place element-wise subtraction between two array like objects"""
  46         if self.encrypted:
  47             return NotImplemented
  48 
  49         arr_like = _ensure_ndarray(arr_like)
  50         self.data = self.data - arr_like
  51         return self.data
  52 
  53     def __mul__(self, arr_like):
  54         """Performs element-wise multiplication between two array like objects"""
  55         if self.encrypted:
  56             return NotImplemented
  57 
  58         arr_like = _ensure_ndarray(arr_like)
  59         return self.data * arr_like
  60 
  61     def __imul__(self, arr_like):
  62         """Performs in place element-wise multiplication between two array like objects"""
  63         if self.encrypted:
  64             return NotImplemented
  65 
  66         arr_like = _ensure_ndarray(arr_like)
  67         self.data = self.data * arr_like
  68         return self.data
  69 
  70     def __truediv__(self, arr_like):
  71         """Performs element-wise division between two array like objects"""
  72         if self.encrypted:
  73             return NotImplemented
  74 
  75         arr_like = _ensure_ndarray(arr_like)
  76         return self.data / arr_like
  77 
  78     def __itruediv__(self, arr_like):
  79         """Performs in place element-wise subtraction between two array like objects"""
  80         if self.encrypted:
  81             return NotImplemented
  82 
  83         arr_like = _ensure_ndarray(arr_like)
  84         self.data = self.data / arr_like
  85         return self.data
  86
  [end of syft/tensor.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/syft/tensor.py b/syft/tensor.py
  --- a/syft/tensor.py
  +++ b/syft/tensor.py
  @@ -8,7 +8,7 @@
   
   class TensorBase(object):
       """
  -    A base tensor class that perform basic element-wise operation such as 
  +    A base tensor class that perform basic element-wise operation such as
       addition, subtraction, multiplication and division
       """
   
  @@ -83,3 +83,20 @@
           arr_like = _ensure_ndarray(arr_like)
           self.data = self.data / arr_like
           return self.data
  +
  +    def shape(self):
  +        """Returns a tuple of input array dimensions."""
  +        if self.encrypted:
  +            return NotImplemented
  +
  +        return self.data.shape
  +
  +    def sum(self, dim=None):
  +        """Returns the sum of all elements in the input array."""
  +        if self.encrypted:
  +            return NotImplemented
  +
  +        if dim is None:
  +            return self.data.sum()
  +        else:
  +            return self.data.sum(axis=dim)
  
verification_info: {"golden_diff": "diff --git a/syft/tensor.py b/syft/tensor.py\n--- a/syft/tensor.py\n+++ b/syft/tensor.py\n@@ -8,7 +8,7 @@\n \n class TensorBase(object):\n     \"\"\"\n-    A base tensor class that perform basic element-wise operation such as \n+    A base tensor class that perform basic element-wise operation such as\n     addition, subtraction, multiplication and division\n     \"\"\"\n \n@@ -83,3 +83,20 @@\n         arr_like = _ensure_ndarray(arr_like)\n         self.data = self.data / arr_like\n         return self.data\n+\n+    def shape(self):\n+        \"\"\"Returns a tuple of input array dimensions.\"\"\"\n+        if self.encrypted:\n+            return NotImplemented\n+\n+        return self.data.shape\n+\n+    def sum(self, dim=None):\n+        \"\"\"Returns the sum of all elements in the input array.\"\"\"\n+        if self.encrypted:\n+            return NotImplemented\n+\n+        if dim is None:\n+            return self.data.sum()\n+        else:\n+            return self.data.sum(axis=dim)\n", "issue": "Implement Default sum Functionality for Base Tensor Type\n**User Story A:** As a Data Scientist using Syft's Base Tensor type, I want to leverage a default method for computing operations on a Tensor of arbitrary type. For this ticket to be complete, sum() should return a new tensor. For a reference on the operation this performs check out [PyTorch](http://pytorch.org/docs/master/tensors.html)'s documentation.\r\n\r\n**Acceptance Criteria:**\r\n- If the Base Tensor type's attribute \"encrypted\" is set to True, it should return a NotImplemented error.\r\n- a unit test demonstrating the correct operation on the Base Tensor type implemented over int and float Tensors.\r\n- 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.\n", "before_files": [{"content": "import numpy as np\n\ndef _ensure_ndarray(arr):\n    if not isinstance(arr, np.ndarray):\n        arr = np.array(arr)\n\n    return arr\n\nclass TensorBase(object):\n    \"\"\"\n    A base tensor class that perform basic element-wise operation such as \n    addition, subtraction, multiplication and division\n    \"\"\"\n\n    def __init__(self, arr_like, encrypted=False):\n        self.data = _ensure_ndarray(arr_like)\n        self.encrypted = encrypted\n\n    def __add__(self, arr_like):\n        \"\"\"Performs element-wise addition between two array like objects\"\"\"\n        if self.encrypted:\n            return NotImplemented\n\n        arr_like = _ensure_ndarray(arr_like)\n        return self.data + arr_like\n\n    def __iadd__(self, arr_like):\n        \"\"\"Performs in place element-wise addition between two array like objects\"\"\"\n        if self.encrypted:\n            return NotImplemented\n\n        arr_like = _ensure_ndarray(arr_like)\n        self.data = self.data + arr_like\n        return self.data\n\n    def __sub__(self, arr_like):\n        \"\"\"Performs element-wise subtraction between two array like objects\"\"\"\n        if self.encrypted:\n            return NotImplemented\n\n        arr_like = _ensure_ndarray(arr_like)\n        return self.data - arr_like\n\n    def __isub__(self, arr_like):\n        \"\"\"Performs in place element-wise subtraction between two array like objects\"\"\"\n        if self.encrypted:\n            return NotImplemented\n\n        arr_like = _ensure_ndarray(arr_like)\n        self.data = self.data - arr_like\n        return self.data\n\n    def __mul__(self, arr_like):\n        \"\"\"Performs element-wise multiplication between two array like objects\"\"\"\n        if self.encrypted:\n            return NotImplemented\n\n        arr_like = _ensure_ndarray(arr_like)\n        return self.data * arr_like\n\n    def __imul__(self, arr_like):\n        \"\"\"Performs in place element-wise multiplication between two array like objects\"\"\"\n        if self.encrypted:\n            return NotImplemented\n\n        arr_like = _ensure_ndarray(arr_like)\n        self.data = self.data * arr_like\n        return self.data\n\n    def __truediv__(self, arr_like):\n        \"\"\"Performs element-wise division between two array like objects\"\"\"\n        if self.encrypted:\n            return NotImplemented\n\n        arr_like = _ensure_ndarray(arr_like)\n        return self.data / arr_like\n\n    def __itruediv__(self, arr_like):\n        \"\"\"Performs in place element-wise subtraction between two array like objects\"\"\"\n        if self.encrypted:\n            return NotImplemented\n\n        arr_like = _ensure_ndarray(arr_like)\n        self.data = self.data / arr_like\n        return self.data\n", "path": "syft/tensor.py"}]}