Remove python bindings for `torch.slice` (#7924)
* skip python bindings for slice
* remove tests
* convert slice test to indexing
diff --git a/test/test_autograd.py b/test/test_autograd.py
index 54dcca3..0c19e24 100644
--- a/test/test_autograd.py
+++ b/test/test_autograd.py
@@ -2931,7 +2931,6 @@
('select', (S, S, S), (1, 2), 'dim', [0]),
('select', (S,), (0, 2), '1d'),
('narrow', (S, S, S), (1, 2, 2), 'dim', [0]),
- ('slice', (S, S, S), (-2, 1, -1, 2)),
('squeeze', (S, 1, S, 1), NO_ARGS),
('squeeze', (1, 1, 1, 1), NO_ARGS, 'input_sizes_are_ones'),
('squeeze', (S, 1, S, 1), (1,), '1_dim', [0]),
diff --git a/test/test_torch.py b/test/test_torch.py
index 2d87d6b..49e468d 100644
--- a/test/test_torch.py
+++ b/test/test_torch.py
@@ -3318,20 +3318,20 @@
def test_slice(self):
empty = torch.Tensor()
x = torch.arange(0., 16).view(4, 4)
- self.assertEqual(x.slice(), x)
- self.assertEqual(x.slice(0, 0, 4), x)
+ self.assertEqual(x[:], x)
+ self.assertEqual(x[:4], x)
# start and stop are clamped to the size of dim
- self.assertEqual(x.slice(0, 0, 5), x)
+ self.assertEqual(x[:5], x)
# if start >= stop then the result is empty
- self.assertEqual(x.slice(0, 2, 1), empty)
- self.assertEqual(x.slice(0, 2, 2), empty)
+ self.assertEqual(x[2:1], empty)
+ self.assertEqual(x[2:2], empty)
# out of bounds is also empty
- self.assertEqual(x.slice(0, 10, 12), empty)
+ self.assertEqual(x[10:12], empty)
# additional correctness checks
- self.assertEqual(x.slice(0, 0, 1).data.tolist(), [[0, 1, 2, 3]])
- self.assertEqual(x.slice(0, 0, -3).data.tolist(), [[0, 1, 2, 3]])
- self.assertEqual(x.slice(start=-2, end=3, dim=1).data.tolist(), [[2], [6], [10], [14]])
- self.assertEqual(x.slice(0, 0, -1, 2).data.tolist(), [[0, 1, 2, 3], [8, 9, 10, 11]])
+ self.assertEqual(x[:1].data.tolist(), [[0, 1, 2, 3]])
+ self.assertEqual(x[:-3].data.tolist(), [[0, 1, 2, 3]])
+ self.assertEqual(x[:, -2:3].data.tolist(), [[2], [6], [10], [14]])
+ self.assertEqual(x[0:-1:2].data.tolist(), [[0, 1, 2, 3], [8, 9, 10, 11]])
def test_is_signed(self):
self.assertEqual(torch.IntTensor(5).is_signed(), True)
diff --git a/tools/autograd/gen_python_functions.py b/tools/autograd/gen_python_functions.py
index c89a4ea..34b06d4 100644
--- a/tools/autograd/gen_python_functions.py
+++ b/tools/autograd/gen_python_functions.py
@@ -22,7 +22,7 @@
'index',
'_indexCopy_', 'max_values', 'min_values', 'argmax', 'argmin',
'_cumsum.*', '_cumprod.*', '_sum.*', '_prod.*', '_th_sum.*', '_th_prod.*',
- 'arange.*', 'range.*', '_gesv.*',
+ 'arange.*', 'range.*', '_gesv.*', 'slice',
]
PY_VARIABLE_METHODS_CPP = CodeTemplate.from_file(template_path + '/python_variable_methods.cpp')