@@ -1831,6 +1831,24 @@ def sample_repeat_tile(op_info, device, dtype, requires_grad, **kwargs):
1831
1831
1832
1832
return samples
1833
1833
1834
+
1835
+ def sample_inputs_narrow (op_info , device , dtype , requires_grad , ** kwargs ):
1836
+ shapes_and_args = (
1837
+ ((S , S , S ), (1 , 2 , 2 )),
1838
+ ((S , S , S ), (- 1 , 2 , 2 )),
1839
+ ((S , S , S ), (1 , 0 , 0 )),
1840
+ ((S , S , S ), (- 1 , 0 , 0 )),
1841
+ )
1842
+
1843
+ def generator ():
1844
+ for shape , args in shapes_and_args :
1845
+ tensor = make_tensor (shape , device , dtype , low = None , high = None ,
1846
+ requires_grad = requires_grad )
1847
+ yield SampleInput (tensor , args = args )
1848
+
1849
+ return list (generator ())
1850
+
1851
+
1834
1852
def sample_unsqueeze (op_info , device , dtype , requires_grad , ** kwargs ):
1835
1853
shapes_and_axes = [
1836
1854
((3 , 4 , 5 ), 0 ),
@@ -4974,6 +4992,10 @@ def gradcheck_wrapper_triangular_input(op, input, *args, upper=False, **kwargs):
4974
4992
dtypes = all_types_and_complex_and (torch .bool , torch .bfloat16 , torch .float16 ),
4975
4993
supports_autograd = False ,
4976
4994
sample_inputs_func = sample_inputs_comparison_ops ),
4995
+ OpInfo ('narrow' ,
4996
+ dtypes = all_types_and_complex_and (torch .bool , torch .bfloat16 , torch .float16 ),
4997
+ supports_out = False ,
4998
+ sample_inputs_func = sample_inputs_narrow ),
4977
4999
UnaryUfuncInfo ('neg' ,
4978
5000
aliases = ('negative' , ),
4979
5001
ref = np .negative ,
@@ -6347,8 +6369,6 @@ def method_tests():
6347
6369
('fill_' , (S , S , S ), (1 ,), 'number' ),
6348
6370
('fill_' , (), (1 ,), 'number_scalar' ),
6349
6371
('fill_' , (S , S , S ), ((),), 'variable' ),
6350
- ('narrow' , (S , S , S ), (1 , 2 , 2 ), 'dim' , (), [0 ]),
6351
- ('narrow' , (S , S , S ), (1 , 0 , 0 ), 'empty_dim' , (), [0 ]),
6352
6372
('squeeze' , (S , 1 , S , 1 ), NO_ARGS , '' , (True ,)),
6353
6373
('squeeze' , (1 , 1 , 1 , 1 ), NO_ARGS , 'input_sizes_are_ones' , (True ,)),
6354
6374
('squeeze' , (S , 1 , S , 1 ), (1 ,), '1_dim' , (True ,), [0 ]),
0 commit comments