Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
attila-dusnoki-htec committed Oct 3, 2023
1 parent d543a26 commit 0363676
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 0 deletions.
87 changes: 87 additions & 0 deletions test/onnx/gen_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -4880,6 +4880,19 @@ def pad_asym_test():
return ([node], [x], [y])


@onnx_test()
def pad_asym_invalid_pads_error_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [1, 3, 4, 5])
y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [1, 6, 4, 12])

node = onnx.helper.make_node('Pad',
inputs=['0'],
pads=[0, 1, 0, 3, 0, 2],
outputs=['1'])

return ([node], [x], [y])


@onnx_test()
def pad_3arg_test():
values = np.array([1])
Expand Down Expand Up @@ -4953,6 +4966,47 @@ def pad_4arg_axes_test():
return ([arg_axes, arg_val, arg_pad, node], [x], [y])


@onnx_test()
def pad_4arg_invalid_axes_error_test():
values = np.array([1])
val_tensor = helper.make_tensor(name='val',
data_type=TensorProto.FLOAT,
dims=values.reshape(()).shape,
vals=values.astype(float))
arg_val = onnx.helper.make_node('Constant',
inputs=[],
outputs=['arg_val'],
value=val_tensor)

sizes = np.array([1, 3, 2, 4])
pad_tensor = helper.make_tensor(name='pad_size',
data_type=TensorProto.INT32,
dims=sizes.shape,
vals=sizes.astype(int))
arg_pad = onnx.helper.make_node('Constant',
inputs=[],
outputs=['arg_pad'],
value=pad_tensor)

axes = np.array([1, 2, 3])
axes_tensor = helper.make_tensor(name='pad_axes',
data_type=TensorProto.INT32,
dims=axes.shape,
vals=axes.astype(int))
arg_axes = onnx.helper.make_node('Constant',
inputs=[],
outputs=['arg_axes'],
value=axes_tensor)

x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [1, 3, 4, 5])
y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [1, 6, 4, 12])

node = onnx.helper.make_node(
'Pad', inputs=['0', 'arg_pad', 'arg_val', 'arg_axes'], outputs=['1'])

return ([arg_axes, arg_val, arg_pad, node], [x], [y])


@onnx_test()
def pad_4arg_neg_axes_test():
values = np.array([1])
Expand Down Expand Up @@ -5017,6 +5071,39 @@ def pad_reflect_test():
return ([arg_pad, node], [x], [y])


@onnx_test()
def pad_reflect_with_axes_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 2])
y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [2, 5])

sizes = np.array([2, 1])
pad_tensor = helper.make_tensor(name='pad_size',
data_type=TensorProto.INT32,
dims=sizes.shape,
vals=sizes.astype(int))
arg_pad = onnx.helper.make_node('Constant',
inputs=[],
outputs=['arg_pad'],
value=pad_tensor)

axes = np.array([1])
axes_tensor = helper.make_tensor(name='pad_axes',
data_type=TensorProto.INT32,
dims=axes.shape,
vals=axes.astype(int))
arg_axes = onnx.helper.make_node('Constant',
inputs=[],
outputs=['arg_axes'],
value=axes_tensor)

node = onnx.helper.make_node('Pad',
mode='reflect',
inputs=['0', 'arg_pad', 'arg_axes'],
outputs=['1'])

return ([arg_axes, arg_pad, node], [x], [y])


@onnx_test()
def pad_reflect_multiaxis_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 3])
Expand Down
31 changes: 31 additions & 0 deletions test/onnx/onnx_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4672,6 +4672,11 @@ TEST_CASE(pad_asym_test)
EXPECT(p == prog);
}

TEST_CASE(pad_asym_invalid_pads_error_test)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("pad_asym_invalid_pads_error_test.onnx"); }));
}

TEST_CASE(pad_3arg_test)
{
migraphx::program p;
Expand Down Expand Up @@ -4708,6 +4713,11 @@ TEST_CASE(pad_4arg_axes_test)
EXPECT(p == prog);
}

TEST_CASE(pad_4arg_invalid_axes_error_test)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("pad_4arg_invalid_axes_error_test.onnx"); }));
}

TEST_CASE(pad_4arg_neg_axes_test)
{
migraphx::program p;
Expand Down Expand Up @@ -4786,6 +4796,27 @@ TEST_CASE(pad_reflect_test)
EXPECT(p == prog);
}

TEST_CASE(pad_reflect_with_axes_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, {2, 2}});
mm->add_literal({migraphx::shape{migraphx::shape::int32_type, {1}}, {1}});
mm->add_literal({migraphx::shape{migraphx::shape::int32_type, {2}}, {2, 1}});
auto l1 = mm->add_instruction(
migraphx::make_op("slice", {{"axes", {0, 1}}, {"starts", {0, 1}}, {"ends", {2, 2}}}), l0);
auto l2 = mm->add_instruction(
migraphx::make_op("slice", {{"axes", {0, 1}}, {"starts", {0, 0}}, {"ends", {2, 1}}}), l0);
auto l3 = mm->add_instruction(
migraphx::make_op("slice", {{"axes", {0, 1}}, {"starts", {0, 0}}, {"ends", {2, 1}}}), l0);
auto r = mm->add_instruction(migraphx::make_op("concat", {{"axis", 1}}), l2, l1, l0, l3);
mm->add_return({r});

auto prog = migraphx::parse_onnx("pad_reflect_with_axes_test.onnx");

EXPECT(p == prog);
}

TEST_CASE(pad_reflect_multiaxis_test)
{
migraphx::program p;
Expand Down
Binary file added test/onnx/pad_4arg_invalid_axes_error_test.onnx
Binary file not shown.
Binary file added test/onnx/pad_asym_invalid_pads_error_test.onnx
Binary file not shown.
18 changes: 18 additions & 0 deletions test/onnx/pad_reflect_with_axes_test.onnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
 pad_reflect_with_axes_test:�
3arg_axes"Constant*
value**Bpad_axes�
3arg_pad"Constant*
value**Bpad_size�
2
0
arg_pad
arg_axes1"Pad*
mode"reflect�pad_reflect_with_axes_testZ
0


b
1


B

0 comments on commit 0363676

Please sign in to comment.