@@ -722,6 +722,58 @@ def test_accuracy_trunc_divide_scalar_scalar(dtype):
722722 gems_assert_close (res_out , ref_out , dtype )
723723
724724
725+ @pytest .mark .div
726+ @pytest .mark .parametrize ("shape" , POINTWISE_SHAPES )
727+ @pytest .mark .parametrize ("dtype" , INT_DTYPES + [torch .int64 ])
728+ def test_trunc_div_int (shape , dtype ):
729+ # Regression test: integer types must be dispatched at Python layer to avoid
730+ # passing int tensors to div_rz which only supports floating point.
731+ inp1 = torch .randint (1 , 100 , shape , dtype = dtype , device = flag_gems .device )
732+ inp2 = torch .randint (1 , 100 , shape , dtype = dtype , device = flag_gems .device )
733+ ref_inp1 = to_reference (inp1 , False )
734+ ref_inp2 = to_reference (inp2 , False )
735+
736+ ref_out = torch .div (ref_inp1 , ref_inp2 , rounding_mode = "trunc" )
737+ with flag_gems .use_gems ():
738+ res_out = torch .div (inp1 , inp2 , rounding_mode = "trunc" )
739+
740+ gems_assert_equal (res_out , ref_out )
741+
742+
743+ @pytest .mark .div
744+ @pytest .mark .parametrize ("shape" , POINTWISE_SHAPES )
745+ @pytest .mark .parametrize ("dtype" , INT_DTYPES + [torch .int64 ])
746+ def test_trunc_div_tensor_scalar_int (shape , dtype ):
747+ # Regression test: integer types must be dispatched at Python layer to avoid
748+ # passing int tensors to div_rz which only supports floating point.
749+ inp1 = torch .randint (1 , 100 , shape , dtype = dtype , device = flag_gems .device )
750+ scalar = random .randint (1 , 10 )
751+ ref_inp1 = to_reference (inp1 , False )
752+
753+ ref_out = torch .div (ref_inp1 , scalar , rounding_mode = "trunc" )
754+ with flag_gems .use_gems ():
755+ res_out = torch .div (inp1 , scalar , rounding_mode = "trunc" )
756+
757+ gems_assert_equal (res_out , ref_out )
758+
759+
760+ @pytest .mark .div
761+ @pytest .mark .parametrize ("shape" , POINTWISE_SHAPES )
762+ @pytest .mark .parametrize ("dtype" , INT_DTYPES + [torch .int64 ])
763+ def test_trunc_div_scalar_tensor_int (shape , dtype ):
764+ # Regression test: integer types must be dispatched at Python layer to avoid
765+ # passing int tensors to div_rz which only supports floating point.
766+ inp2 = torch .randint (1 , 100 , shape , dtype = dtype , device = flag_gems .device )
767+ scalar = random .randint (1 , 100 )
768+ ref_inp2 = to_reference (inp2 , False )
769+
770+ ref_out = torch .div (scalar , ref_inp2 , rounding_mode = "trunc" )
771+ with flag_gems .use_gems ():
772+ res_out = torch .div (scalar , inp2 , rounding_mode = "trunc" )
773+
774+ gems_assert_equal (res_out , ref_out )
775+
776+
725777# TODO: failed at large size, eg. (65536 * 2048,)
726778@pytest .mark .floor_divide
727779@pytest .mark .parametrize ("shape" , POINTWISE_SHAPES )
0 commit comments