"...linux/git@developer.sourcefind.cn:OpenDAS/vision.git" did not exist on "fbc8ea477fec70ad51ee7f518f3d938cc0b55213"
Unverified Commit 878a7d09 authored by Shucai Xiao's avatar Shucai Xiao Committed by GitHub
Browse files

fixed a bug in parse_slice (#489)

* fixed a bug in parse_slice

* add a unit test

* clang format
parent e184395c
......@@ -797,7 +797,8 @@ struct onnx_parser
}
else if(contains(info.attributes, "ends"))
{
op.ends = get_indices(info.attributes.at("ends"));
literal s = parse_value(info.attributes.at("ends"));
s.visit([&](auto v) { copy(v, std::back_inserter(op.ends)); });
}
if(args.size() >= 2)
......@@ -1966,20 +1967,6 @@ struct onnx_parser
return result;
}
static std::vector<int64_t> get_indices(const onnx::AttributeProto& attr)
{
std::vector<int64_t> result;
literal s = parse_value(attr);
s.visit([&](auto v) { copy(v, std::back_inserter(result)); });
// Clamp large indices to -1
std::replace_if(
result.begin(),
result.end(),
[](auto x) { return x > int64_t{std::numeric_limits<std::int32_t>::max()} / 2; },
-1);
return result;
}
template <class T>
static literal from_repeated(shape::type_t t, const T& r)
{
......
......@@ -1836,6 +1836,21 @@ def slice_5arg_test():
return ([arg_step, arg_axis, arg_end, arg_start, node], [x], [y])
@onnx_test
def slice_max_end_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [10, 20])
y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [9, 17])
node = onnx.helper.make_node('Slice',
inputs=['0'],
axes=[0, 1],
starts=[1, 2],
ends=[3000000000, -1],
outputs=['1'])
return ([node], [x], [y])
@onnx_test
def slice_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [3, 2])
......
......@@ -1392,6 +1392,16 @@ TEST_CASE(slice_5arg_test)
EXPECT(p == prog);
}
TEST_CASE(slice_max_end_test)
{
migraphx::program p;
auto l0 = p.add_parameter("0", migraphx::shape{migraphx::shape::float_type, {10, 20}});
p.add_instruction(migraphx::op::slice{{0, 1}, {1, 2}, {3000000000, -1}}, l0);
auto prog = optimize_onnx("slice_max_end_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(slice_test)
{
migraphx::program p;
......
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