Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep strided_slice op behavior consistent with slice op when starts input is less than -rank #39066

Merged
merged 14 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions paddle/fluid/operators/strided_slice_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ static void StridedSliceFunctor(int64_t* starts, int64_t* ends,
// stride must not be zero
if (starts[axis_index] < 0) {
starts[axis_index] = starts[axis_index] + axis_size;
starts[axis_index] = std::max<int64_t>(starts[axis_index], 0);
}
if (ends[axis_index] < 0) {
if (!(ends[axis_index] == -1 &&
Expand All @@ -139,11 +140,6 @@ static void StridedSliceFunctor(int64_t* starts, int64_t* ends,
}
}

if ((starts[axis_index] < 0) && (axis_size > 0)) {
starts[axis_index] += axis_size;
starts[axis_index] = std::max<int64_t>(starts[axis_index], 0);
}

if (strides[axis_index] < 0) {
reverse_axis[axis_index] = 1;
strides[axis_index] = -strides[axis_index];
Expand Down
10 changes: 10 additions & 0 deletions python/paddle/fluid/tests/unittests/test_strided_slice_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ def initTestCase(self):
self.infer_flags = [1, 1, 1, 1, 1]


class TestStrideSliceOp14(TestStrideSliceOp):
def initTestCase(self):
self.input = np.random.rand(4, 4, 4, 4)
self.axes = [1, 2, 3]
self.starts = [-5, 0, -7]
self.ends = [-1, 2, 4]
self.strides = [1, 1, 1]
self.infer_flags = [1, 1, 1]


class TestStrideSliceOpBool(TestStrideSliceOp):
def test_check_grad(self):
pass
Expand Down