Repository: OpenMined/PySyft

Issue:
1dim TensorBase slice returns ndarray instead of TensorBase
Currently a slice of TensorBase returns an ndarray if `dim() == 1`. This is not the behavior expected in PyTorch

Example pytorch session:
```python
t1 = Tensor([1,2,3,4])
t1[1:]
 2
 3
 4
[torch.FloatTensor of size 3]
```

Same with TensorBase
```python
t2 = TensorBase([1,2,3,4])
t2[1:]
array([2, 3, 4])
```

see https://github.com/OpenMined/PySyft/commit/7fb592dcd4ede5b0d0cc6bdc50b98a0445ad77c0#diff-796d7f13fb1460eef9cffdccebd38faeR148

Is this a bug or expected ? 


Discussion:
codecov[bot]: # [Codecov](https://codecov.io/gh/OpenMined/PySyft/pull/314?src=pr&el=h1) Report
> Merging [#314](https://codecov.io/gh/OpenMined/PySyft/pull/314?src=pr&el=desc) into [master](https://codecov.io/gh/OpenMined/PySyft/commit/543a66153c17d6e2885d6b7d571749fe02629ba5?src=pr&el=desc) will **increase** coverage by `0.04%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/OpenMined/PySyft/pull/314/graphs/tree.svg?token=W0kQS1vaXB&width=650&height=150&src=pr)](https://codecov.io/gh/OpenMined/PySyft/pull/314?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #314      +/-   ##
==========================================
+ Coverage   82.26%   82.31%   +0.04%     
==========================================
  Files          24       24              
  Lines        3243     3252       +9     
==========================================
+ Hits         2668     2677       +9     
  Misses        575      575
```


| [Impacted Files](https://codecov.io/gh/OpenMined/PySyft/pull/314?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [tests/test\_tensor.py](https://codecov.io/gh/OpenMined/PySyft/pull/314?src=pr&el=tree#diff-dGVzdHMvdGVzdF90ZW5zb3IucHk=) | `94.21% <100%> (+0.04%)` | :arrow_up: |
| [syft/tensor.py](https://codecov.io/gh/OpenMined/PySyft/pull/314?src=pr&el=tree#diff-c3lmdC90ZW5zb3IucHk=) | `77.82% <100%> (+0.02%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/OpenMined/PySyft/pull/314?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/OpenMined/PySyft/pull/314?src=pr&el=footer). Last update [543a661...65e98a9](https://codecov.io/gh/OpenMined/PySyft/pull/314?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/syft/tensor.py b/syft/tensor.py
index 081679d946..d374bb5ae0 100644
--- a/syft/tensor.py
+++ b/syft/tensor.py
@@ -449,7 +449,7 @@ class TensorBase(object):
             return NotImplemented
         else:
             out = self.data[position]
-            if (len(self.shape()) == 1):
+            if (len(self.shape()) == 1) and (type(position) != slice):
                 return out
             else:
                 return TensorBase(self.data[position], self.encrypted)


Test patch:
diff --git a/tests/test_tensor.py b/tests/test_tensor.py
index 5c46a87951..7ec07030c8 100644
--- a/tests/test_tensor.py
+++ b/tests/test_tensor.py
@@ -957,6 +957,17 @@ class IndexTests(unittest.TestCase):
         with pytest.raises(ValueError):
             t.index(3.5)
 
+    def test_index_slice_notation(self):
+        t1 = TensorBase(np.array([1, 2, 3, 4]))
+        expected1 = TensorBase(np.array([2, 3, 4]))
+        expected2 = type(t1[1:])
+        expected3 = 1
+
+        # Do not use "t.index" form in following test
+        self.assertEqual(expected1, t1[1:])
+        self.assertEqual(expected2, TensorBase)
+        self.assertEqual(expected3, t1[0])
+
     def test_index_add_(self):
         t1 = TensorBase(np.array([[0, 0, 0], [1, 1, 1], [1, 1, 1]]))
         t2 = TensorBase(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]))