未验证 提交 f98b19a9 编写于 作者: C Chun-Wei Chen 提交者: GitHub

Check negative index for attributes of Slice-1 (#3810)

* check negative value
Signed-off-by: NChun-Wei Chen <jacky82226@gmail.com>

* only perform rank inference
Signed-off-by: NChun-Wei Chen <jacky82226@gmail.com>

* resolve warning
Signed-off-by: NChun-Wei Chen <jacky82226@gmail.com>

* fix warning
Signed-off-by: NChun-Wei Chen <jacky82226@gmail.com>

* starts + ends
Signed-off-by: NChun-Wei Chen <jacky82226@gmail.com>

* change if; any_of; update comments
Signed-off-by: NChun-Wei Chen <jacky82226@gmail.com>
Co-authored-by: NAshwini Khade <askhade@microsoft.com>
上级 94fb4925
......@@ -3192,8 +3192,8 @@ ONNX_OPERATOR_SET_SCHEMA(
starts.size() != ends.size()) {
fail_shape_inference(
"Incorrect or missing attribute value for starts and ends");
;
}
std::vector<int64_t> axes;
if (!getRepeatedAttribute(ctx, "axes", axes)) {
for (int i = 0; (size_t)i < starts.size(); ++i) {
......@@ -3201,12 +3201,28 @@ ONNX_OPERATOR_SET_SCHEMA(
}
} else if (axes.size() != starts.size()) {
fail_shape_inference("Attribute axes has incorrect length");
;
} else if (!std::is_sorted(axes.begin(), axes.end())) {
// TODO support shape inference for unsorted axes
return;
}
auto is_negative = [](int64_t index) {
return index < 0;
};
if (std::any_of(starts.begin(), starts.end(), is_negative) ||
std::any_of(ends.begin(), ends.end(), is_negative) ||
std::any_of(axes.begin(), axes.end(), is_negative)) {
// Negative axes were not explicitly discussed in the spec before opset-10.
// Hence, they are officially not part of the spec, but some models/runtimes may use them.
// So we perform simple rank inference in this case.
for (size_t i = 0; (int64_t)i <
ctx.getInputType(0)->tensor_type().shape().dim_size();
++i) {
ctx.getOutputType(0)->mutable_tensor_type()->mutable_shape()->add_dim();
}
return;
}
ctx.getOutputType(0)->mutable_tensor_type()->mutable_shape();
for (size_t i = 0, j = 0; (int64_t)i <
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册