@@ -2656,6 +2656,38 @@ def test_accuracy_floor_(shape, dtype):
26562656 gems_assert_equal (res_out , ref_out )
26572657
26582658
2659+ ROLL_SHIFTS_DIMS = [
2660+ (1 , 0 ),
2661+ (- 1 , 0 ),
2662+ (2 , - 1 ),
2663+ (3 , 1 ),
2664+ ]
2665+
2666+
2667+ @pytest .mark .roll
2668+ @pytest .mark .parametrize ("shape" , POINTWISE_SHAPES )
2669+ @pytest .mark .parametrize ("dtype" , FLOAT_DTYPES + ALL_INT_DTYPES )
2670+ @pytest .mark .parametrize ("shifts_dims" , ROLL_SHIFTS_DIMS )
2671+ def test_accuracy_roll_single_dim (shape , dtype , shifts_dims ):
2672+ shifts , dims = shifts_dims
2673+ ndim = len (shape )
2674+ # Adjust dims if it's out of range for this shape
2675+ if dims >= ndim or dims < - ndim :
2676+ pytest .skip (f"dims { dims } out of range for shape { shape } " )
2677+
2678+ if dtype in ALL_FLOAT_DTYPES :
2679+ inp = torch .randn (shape , dtype = dtype , device = flag_gems .device )
2680+ else :
2681+ inp = torch .randint (- 1000 , 1000 , shape , device = flag_gems .device ).to (dtype )
2682+ ref_inp = to_reference (inp , False )
2683+
2684+ ref_out = torch .roll (ref_inp , shifts , dims )
2685+ with flag_gems .use_gems ():
2686+ res_out = torch .roll (inp , shifts , dims )
2687+
2688+ gems_assert_equal (res_out , ref_out )
2689+
2690+
26592691@pytest .mark .special_i0e
26602692@pytest .mark .parametrize ("shape" , [(2 , 3 ), (128 , 256 ), (512 , 512 )])
26612693@pytest .mark .parametrize ("dtype" , FLOAT_DTYPES )
@@ -2690,3 +2722,72 @@ def test_accuracy_special_i0e_out(shape, dtype):
26902722 act_out = torch .ops .aten .special_i0e .out (x , out = out_act )
26912723 gems_assert_close (act_out , ref_out , dtype )
26922724 gems_assert_close (out_act , out_ref , dtype )
2725+
2726+
2727+ ROLL_MULTI_DIMS = [
2728+ ((1 , 2 ), (0 , 1 )),
2729+ ((- 1 , 1 ), (0 , - 1 )),
2730+ ((2 , - 2 ), (- 2 , - 1 )),
2731+ ]
2732+
2733+
2734+ @pytest .mark .roll
2735+ @pytest .mark .parametrize ("shape" , POINTWISE_SHAPES )
2736+ @pytest .mark .parametrize ("dtype" , FLOAT_DTYPES )
2737+ @pytest .mark .parametrize ("shifts_dims" , ROLL_MULTI_DIMS )
2738+ def test_accuracy_roll_multi_dims (shape , dtype , shifts_dims ):
2739+ shifts , dims = shifts_dims
2740+ ndim = len (shape )
2741+ # Check all dims are valid for this shape
2742+ for d in dims :
2743+ if d >= ndim or d < - ndim :
2744+ pytest .skip (f"dims { d } out of range for shape { shape } " )
2745+
2746+ inp = torch .randn (shape , dtype = dtype , device = flag_gems .device )
2747+ ref_inp = to_reference (inp , False )
2748+
2749+ ref_out = torch .roll (ref_inp , shifts , dims )
2750+ with flag_gems .use_gems ():
2751+ res_out = torch .roll (inp , shifts , dims )
2752+
2753+ gems_assert_equal (res_out , ref_out )
2754+
2755+
2756+ ROLL_FLATTEN_SHIFTS = [1 , - 1 , 5 , - 3 ]
2757+
2758+
2759+ @pytest .mark .roll
2760+ @pytest .mark .parametrize ("shape" , POINTWISE_SHAPES )
2761+ @pytest .mark .parametrize ("dtype" , FLOAT_DTYPES )
2762+ @pytest .mark .parametrize ("shifts" , ROLL_FLATTEN_SHIFTS )
2763+ def test_accuracy_roll_flatten (shape , dtype , shifts ):
2764+ inp = torch .randn (shape , dtype = dtype , device = flag_gems .device )
2765+ ref_inp = to_reference (inp , False )
2766+
2767+ # Roll without specifying dims (flatten case)
2768+ ref_out = torch .roll (ref_inp , shifts )
2769+ with flag_gems .use_gems ():
2770+ res_out = torch .roll (inp , shifts )
2771+
2772+ gems_assert_equal (res_out , ref_out )
2773+
2774+
2775+ @pytest .mark .roll
2776+ @pytest .mark .parametrize ("shape" , POINTWISE_SHAPES )
2777+ @pytest .mark .parametrize ("dtype" , FLOAT_DTYPES )
2778+ def test_accuracy_roll_with_non_dense_input (shape , dtype ):
2779+ if len (shape ) < 2 :
2780+ pytest .skip ("Need at least 2D for non-dense test" )
2781+
2782+ shape_dilated = tuple (item * 2 for item in shape )
2783+ inp = torch .randn (shape_dilated , dtype = dtype , device = flag_gems .device )[::2 , ::2 ]
2784+ ref_inp = to_reference (inp , False )
2785+
2786+ shifts = 2
2787+ dims = 0
2788+
2789+ ref_out = torch .roll (ref_inp , shifts , dims )
2790+ with flag_gems .use_gems ():
2791+ res_out = torch .roll (inp , shifts , dims )
2792+
2793+ gems_assert_equal (res_out , ref_out )
0 commit comments