@@ -3318,20 +3318,20 @@ def test_randn(self):
33183318 def test_slice (self ):
33193319 empty = torch .Tensor ()
33203320 x = torch .arange (0. , 16 ).view (4 , 4 )
3321- self .assertEqual (x . slice () , x )
3322- self .assertEqual (x . slice ( 0 , 0 , 4 ) , x )
3321+ self .assertEqual (x [:] , x )
3322+ self .assertEqual (x [: 4 ] , x )
33233323 # start and stop are clamped to the size of dim
3324- self .assertEqual (x . slice ( 0 , 0 , 5 ) , x )
3324+ self .assertEqual (x [: 5 ] , x )
33253325 # if start >= stop then the result is empty
3326- self .assertEqual (x . slice ( 0 , 2 , 1 ) , empty )
3327- self .assertEqual (x . slice ( 0 , 2 , 2 ) , empty )
3326+ self .assertEqual (x [ 2 : 1 ] , empty )
3327+ self .assertEqual (x [ 2 : 2 ] , empty )
33283328 # out of bounds is also empty
3329- self .assertEqual (x . slice ( 0 , 10 , 12 ) , empty )
3329+ self .assertEqual (x [ 10 : 12 ] , empty )
33303330 # additional correctness checks
3331- self .assertEqual (x . slice ( 0 , 0 , 1 ) .data .tolist (), [[0 , 1 , 2 , 3 ]])
3332- self .assertEqual (x . slice ( 0 , 0 , - 3 ) .data .tolist (), [[0 , 1 , 2 , 3 ]])
3333- self .assertEqual (x . slice ( start = - 2 , end = 3 , dim = 1 ) .data .tolist (), [[2 ], [6 ], [10 ], [14 ]])
3334- self .assertEqual (x . slice ( 0 , 0 , - 1 , 2 ) .data .tolist (), [[0 , 1 , 2 , 3 ], [8 , 9 , 10 , 11 ]])
3331+ self .assertEqual (x [: 1 ] .data .tolist (), [[0 , 1 , 2 , 3 ]])
3332+ self .assertEqual (x [: - 3 ] .data .tolist (), [[0 , 1 , 2 , 3 ]])
3333+ self .assertEqual (x [:, - 2 : 3 ] .data .tolist (), [[2 ], [6 ], [10 ], [14 ]])
3334+ self .assertEqual (x [ 0 : - 1 : 2 ] .data .tolist (), [[0 , 1 , 2 , 3 ], [8 , 9 , 10 , 11 ]])
33353335
33363336 def test_is_signed (self ):
33373337 self .assertEqual (torch .IntTensor (5 ).is_signed (), True )
0 commit comments