Commit f561c937 authored by Adam Procter's avatar Adam Procter

Simple DynElimination test (not passing yet)

parent d96482a5
......@@ -84,3 +84,50 @@ TEST(dyn_elimination, transpose_dyn_shape)
ASSERT_TRUE(new_transpose->get_output_partial_shape(0).relaxes(
PartialShape{Dimension::dynamic(), 8, 4, 2}));
}
TEST(dyn_elimination, slice)
{
// input has shape [2,4,6,8,2,2,2]
// slice in numpy syntax is [0:,:4,2:6:2,7:3:-2,np.newaxis,...,1]
// shape should be [2,4,2,2,1,2,2] (so sayeth numpy!)
Shape shape_in{2, 4, 6, 8, 2, 2, 2};
auto input = make_shared<op::Parameter>(element::f32, shape_in);
auto constant_lb =
make_shared<op::Constant>(element::i64, Shape{7}, vector<int64_t>{0, 3, 2, 7, 0, 0, 1});
auto constant_ub =
make_shared<op::Constant>(element::i64, Shape{7}, vector<int64_t>{0, 4, 6, 3, 0, 0, 0});
auto constant_strides =
make_shared<op::Constant>(element::i64, Shape{7}, vector<int64_t>{1, 1, 2, -2, 0, 0, 0});
AxisSet lower_bounds_mask{1};
AxisSet upper_bounds_mask{0};
AxisSet new_axis_mask{4};
AxisSet shrink_mask{6};
AxisSet ellipsis_mask{5};
auto sl = make_shared<op::DynSlice>(input,
constant_lb,
constant_ub,
constant_strides,
lower_bounds_mask,
upper_bounds_mask,
new_axis_mask,
shrink_mask,
ellipsis_mask);
ASSERT_EQ(sl->get_element_type(), element::f32);
ASSERT_EQ(sl->get_shape(), (Shape{2, 4, 2, 2, 1, 2, 2}));
auto f = make_shared<Function>(sl, ParameterVector{input});
pass::Manager pass_manager;
pass_manager.register_pass<pass::DynElimination>();
pass_manager.run_passes(f);
ASSERT_EQ(count_ops_of_type<op::DynSlice>(f), 0);
ASSERT_EQ(count_ops_of_type<op::Slice>(f), 1);
ASSERT_EQ(count_ops_of_type<op::Reshape>(f), 1);
ASSERT_EQ(count_ops_of_type<op::Reverse>(f), 1);
ASSERT_EQ(f->get_results().at(0)->get_element_type(), element::f32);
ASSERT_EQ(f->get_results().at(0)->get_shape(), (Shape{2, 4, 2, 2, 1, 2, 2}));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment