@@ -55,6 +55,10 @@ def __init__(self,
5555 "AddBcast2" : (self .test_AddBcast2 , Y , Y , Y , N , Y , Y ),
5656 "AddBcast3" : (self .test_AddBcast3 , N , N , N , N , N , N ), # failed cases
5757 "AddBcast4" : (self .test_AddBcast4 , N , Y , Y , N , N , N ),
58+ "AddNoRearrange" : (self .test_AddNoRearrange , N , Y , Y , N , Y , N ),
59+ "AddRearrange_1d" : (self .test_AddRearrange_1d , N , Y , Y , N , Y , N ),
60+ "AddRearrange_2d" : (self .test_AddRearrange_2d , N , Y , Y , N , Y , N ),
61+ "AddRearrange_3d" : (self .test_AddRearrange_3d , N , Y , Y , N , Y , N ),
5862 "Acos" : (self .test_Arccos , Y , Y , Y , N , Y , Y ),
5963 "Atan" : (self .test_Arctan , N , Y , Y , N , Y , Y ),
6064 "Atanh" : (self .test_Arctanh , Y , Y , Y , N , Y , Y ),
@@ -4387,6 +4391,106 @@ def test_AddBcast4(self, case_name):
43874391
43884392 self .onnx_and_test (graph_def , name = sub_case_name )
43894393
4394+ def test_AddRearrange_1d (self , case_name ):
4395+ test_cases = [
4396+ ([200 ], [1 ]),
4397+ ([65536 ], [1 ]),
4398+ ([4096 , 16 ], [1 , 1 ]),
4399+ ([2 , 20 , 5 ], [1 , 1 , 1 ]),
4400+ ([2 , 10 , 2 , 5 ], [1 , 1 , 1 , 1 ]),
4401+ ]
4402+
4403+ for shape_a , shape_b in test_cases :
4404+ shape_a_str = ',' .join (map (str , shape_a ))
4405+ shape_b_str = ',' .join (map (str , shape_b ))
4406+
4407+ graph_txt = """
4408+ %s_row (float[%s] a, float[%s] b) => (float[%s] output)
4409+ {
4410+ output = Add(a, b)
4411+ }
4412+ """ % (case_name , shape_a_str , shape_b_str , shape_a_str )
4413+ graph_def = onnx .parser .parse_graph (graph_txt )
4414+ self .onnx_and_test (graph_def )
4415+
4416+ def test_AddRearrange_2d (self , case_name ):
4417+ test_cases = [
4418+ ([128 , 64 ], [128 , 1 ]),
4419+ ([512 , 128 ], [512 , 1 ]),
4420+ ([4 , 128 , 128 ], [4 , 128 , 1 ]),
4421+ ([2 , 2 , 128 , 128 ], [2 , 2 , 128 , 1 ]),
4422+ ([320 , 192 ], [1 , 192 ]),
4423+ ([512 , 128 ], [1 , 128 ]),
4424+ ([4 , 128 , 128 ], [1 , 128 , 128 ]),
4425+ ([320 , 1 ], [1 , 192 ]),
4426+ ([512 , 1 ], [1 , 128 ]),
4427+ ]
4428+
4429+ for shape_a , shape_b in test_cases :
4430+ shape_a_str = ',' .join (map (str , shape_a ))
4431+ shape_b_str = ',' .join (map (str , shape_b ))
4432+
4433+ graph_txt = """
4434+ %s_row (float[%s] a, float[%s] b) => (float[%s] output)
4435+ {
4436+ output = Add(a, b)
4437+ }
4438+ """ % (case_name , shape_a_str , shape_b_str , shape_a_str )
4439+ graph_def = onnx .parser .parse_graph (graph_txt )
4440+ self .onnx_and_test (graph_def )
4441+
4442+ def test_AddRearrange_3d (self , case_name ):
4443+ test_cases = [
4444+ ([128 , 50 , 64 ], [128 , 1 , 64 ]),
4445+ ([2 , 64 , 50 , 32 ], [2 , 64 , 1 , 32 ]),
4446+ ([128 , 6400 , 64 ], [1 , 6400 , 1 ]),
4447+ ([256 , 128 , 32 ], [1 , 128 , 1 ]),
4448+ ([128 , 50 , 1 ], [128 , 1 , 64 ]),
4449+ ([128 , 6400 , 1 ], [1 , 6400 , 64 ]),
4450+ ([256 , 128 , 1 ], [1 , 128 , 32 ]),
4451+ ([128 , 1 , 64 ], [1 , 50 , 64 ]),
4452+ ([2 , 64 , 1 , 32 ], [1 , 50 , 32 ]),
4453+ ([128 , 1 , 64 ], [1 , 50 , 1 ]),
4454+ ]
4455+
4456+ for shape_a , shape_b in test_cases :
4457+ shape_a_str = ',' .join (map (str , shape_a ))
4458+ shape_b_str = ',' .join (map (str , shape_b ))
4459+
4460+ graph_txt = """
4461+ %s_row (float[%s] a, float[%s] b) => (float[%s] output)
4462+ {
4463+ output = Add(a, b)
4464+ }
4465+ """ % (case_name , shape_a_str , shape_b_str , shape_a_str )
4466+ graph_def = onnx .parser .parse_graph (graph_txt )
4467+ self .onnx_and_test (graph_def )
4468+
4469+ def test_AddNoRearrange (self , case_name ):
4470+ test_cases = [
4471+ ([1 , 96 , 1 , 1 ], [65536 , 96 , 1 , 1 ], "unsupported_2d_cross" ),
4472+ ([1 , 64 , 1 ], [128 , 1 , 32 ], "unsupported_3d_cross" ),
4473+ ([10 , 10 ], [1 , 10 ], "small_elements_1d" ),
4474+ ([8 , 8 , 8 ], [1 , 8 , 8 ], "small_elements_2d" ),
4475+ ([4 , 4 , 4 , 4 ], [1 , 4 , 4 , 4 ], "small_elements_3d" ),
4476+ ([360 , 11 , 12 , 7 ], [360 , 1 , 12 , 7 ], "a_not_divisible" ),
4477+ ([100 , 50 , 32 ], [100 , 1 , 32 ], "3d_a_not_divisible" ),
4478+ ([4 , 9 , 10 , 11 , 12 , 7 ], [4 , 1 , 10 , 1 , 12 , 7 ], "6d_input" ),
4479+ ]
4480+
4481+ for shape_a , shape_b , desc in test_cases :
4482+ shape_a_str = ',' .join (map (str , shape_a ))
4483+ shape_b_str = ',' .join (map (str , shape_b ))
4484+
4485+ graph_txt = """
4486+ %s_%s (float[%s] a, float[%s] b) => (float[%s] output)
4487+ {
4488+ output = Add(a, b)
4489+ }
4490+ """ % (case_name , desc , shape_a_str , shape_b_str , shape_a_str )
4491+ graph_def = onnx .parser .parse_graph (graph_txt )
4492+ self .onnx_and_test (graph_def )
4493+
43904494 def test_AddWeight2 (self , case_name ):
43914495 input_shape = [1 , 16 , 8 , 8 ]
43924496 wshape = [16 , 1 , 1 ]
0 commit comments