@@ -4012,6 +4012,44 @@ def _visit(expr):
40124012 assert seen_resize3d
40134013
40144014
4015+ @pytest .mark .parameterize (
4016+ "coord_mode, method" ,
4017+ [
4018+ ("half_pixel" , "nearest" ),
4019+ ("pytorch_half_pixel" , "nearest" ),
4020+ ("asymmetric" , "nearest" ),
4021+ ("half_pixel" , "linear" ),
4022+ ],
4023+ )
4024+ def test_resize_noninteger_scales_2d (coord_mode , method ):
4025+ """Non-integer scales must use the original scale in coordinate transformation.
4026+
4027+ floor(3 * 2.5) = 7, so the recomputed ratio 3/7 = 0.4286 differs from 1/2.5 = 0.4,
4028+ causing wrong pixel mapping at boundary positions before the fix.
4029+ """
4030+ nearest_mode_kwargs = {}
4031+ if method == "nearest" :
4032+ nearest_mode_kwargs ["nearest_mode" ] = "round_prefer_floor"
4033+ resize_node = helper .make_node (
4034+ "Resize" ,
4035+ ["X" , "" , "scales" ],
4036+ ["Y" ],
4037+ mode = method ,
4038+ coordinate_transformation_mode = coord_mode ,
4039+ ** nearest_mode_kwargs ,
4040+ )
4041+ graph = helper .make_graph (
4042+ [resize_node ],
4043+ "resize_noninteger_2d" ,
4044+ inputs = [helper .make_tensor_value_info ("X" , TensorProto .FLOAT , [1 , 1 , 3 , 3 ])],
4045+ initializer = [
4046+ helper .make_tensor ("scales" , TensorProto .FLOAT , [4 ], [1.0 , 1.0 , 2.5 , 2.5 ])
4047+ ],
4048+ outputs = [helper .make_tensor_value_info ("Y" , TensorProto .FLOAT , [1 , 1 , 7 , 7 ])],
4049+ )
4050+ check_correctness (helper .make_model (graph ), opset = 18 )
4051+
4052+
40154053def test_einsum ():
40164054 eqn = "ij->i"
40174055 einsum_node = helper .make_node ("Einsum" , ["x" ], ["y" ], equation = eqn )
0 commit comments