mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-30 20:18:08 +00:00
Fix bug in Slice helper when dim value is zero (#9492)
* Don't clamp if dim_value is zero as that will set `step` to an invalid value.
This commit is contained in:
parent
dbe1b57a71
commit
39d1b9e1c1
2 changed files with 32 additions and 2 deletions
|
|
@ -88,11 +88,22 @@ inline Status PrepareForComputeHelper(const std::vector<int64_t>& raw_starts,
|
|||
|
||||
// process step
|
||||
auto step = axis_index < raw_steps.size() ? raw_steps[axis_index] : 1;
|
||||
if (step == 0)
|
||||
return Status(common::ONNXRUNTIME, common::INVALID_ARGUMENT, "'step' value cannot be 0");
|
||||
|
||||
if (dim_value == 0) {
|
||||
// shape with empty dim. only output_dims_ matters but set everything for completeness
|
||||
compute_metadata.steps_[axis] = step;
|
||||
compute_metadata.starts_[axis] = 0;
|
||||
compute_metadata.ends_[axis] = 0;
|
||||
compute_metadata.output_dims_[axis] = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
// clamp step to avoid overflow if there's a stupidly large value (which will be multiplied in SliceImpl)
|
||||
// as long as the clamped value is >= the size of the dimension a single step will push us past the end
|
||||
step = std::clamp(step, -dim_value, dim_value);
|
||||
if (step == 0)
|
||||
return Status(common::ONNXRUNTIME, common::INVALID_ARGUMENT, "'step' value cannot be 0");
|
||||
|
||||
compute_metadata.steps_[axis] = step;
|
||||
|
||||
// process start
|
||||
|
|
|
|||
|
|
@ -630,5 +630,24 @@ TEST(SliceTest, Slice5D_LargeStep) {
|
|||
{kNupharExecutionProvider});
|
||||
}
|
||||
|
||||
TEST(SliceTest, EmptyDim) {
|
||||
RunSliceTest<float>({0, 6}, // empty dim in shape
|
||||
{},
|
||||
{0}, // starts
|
||||
{1}, // ends
|
||||
{0}, // axes
|
||||
{}, // steps
|
||||
{0, 6},
|
||||
{});
|
||||
|
||||
RunSliceTest<float>({0, 6},
|
||||
{},
|
||||
{1}, // starts
|
||||
{0}, // ends
|
||||
{0}, // axes
|
||||
{-1}, // steps
|
||||
{0, 6},
|
||||
{});
|
||||
}
|
||||
} // namespace test
|
||||
} // namespace onnxruntime
|
||||
|
|
|
|||
Loading…
Reference in a new issue