@@ -513,6 +513,29 @@ def test_accuracy_nonzero(shape, dtype):
513513 gems_assert_equal (res_out , ref_out )
514514
515515
516+ @pytest .mark .nonzero_numpy
517+ @pytest .mark .parametrize ("shape" , NONZERO_SHAPES )
518+ @pytest .mark .parametrize ("dtype" , FLOAT_DTYPES + INT_DTYPES + [torch .bool ])
519+ def test_accuracy_nonzero_numpy (shape , dtype ):
520+ if dtype == torch .bool :
521+ inp = torch .randint (0 , 2 , shape , dtype = torch .int , device = flag_gems .device ).to (
522+ dtype
523+ )
524+ elif dtype in INT_DTYPES :
525+ inp = torch .randint (- 3 , 3 , shape , device = flag_gems .device ).to (dtype )
526+ else :
527+ inp = torch .randn (shape , dtype = dtype , device = flag_gems .device )
528+ ref_inp = to_reference (inp , False )
529+
530+ ref_out = torch .ops .aten .nonzero_numpy (ref_inp )
531+ with flag_gems .use_gems ():
532+ res_out = torch .ops .aten .nonzero_numpy (inp )
533+
534+ assert len (res_out ) == len (ref_out ), "Number of output tensors should match"
535+ for res_t , ref_t in zip (res_out , ref_out ):
536+ gems_assert_equal (res_t , ref_t )
537+
538+
516539@pytest .mark .count_nonzero
517540@pytest .mark .parametrize ("shape" , REDUCTION_SHAPES )
518541@pytest .mark .parametrize ("dtype" , FLOAT_DTYPES + INT_DTYPES + [torch .bool ])
0 commit comments