Skip to content

Commit 32c2717

Browse files
zyfncgAnnaTrainingG
authored andcommitted
Change the invoking method of settiem from numpy to set_value op when value isn't tensor (PaddlePaddle#35701)
* Change the invoking method of settiem from numpy to set_value op when value is not tensor * fix the check logic for inplace in setitem * fix the unittest problem caused by setitem doesn't support fp16 * modify some code format in setitem
1 parent b04b36c commit 32c2717

File tree

6 files changed

+303
-165
lines changed

6 files changed

+303
-165
lines changed

paddle/fluid/operators/slice_utils.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,18 @@ inline void CheckAndUpdateSliceAttrs(const framework::DDim in_dims,
3636
if (infer_flags != nullptr && (*infer_flags)[i] == -1) {
3737
continue;
3838
}
39-
T start = (*starts)[i] < 0 ? ((*starts)[i] + dim_value) : (*starts)[i];
40-
start = std::max(start, static_cast<T>(0));
41-
42-
T end = (*ends)[i] < 0 ? ((*ends)[i] + dim_value) : (*ends)[i];
43-
end = std::min(end, dim_value);
44-
4539
T step = steps == nullptr ? 1 : (*steps)[i];
4640
PADDLE_ENFORCE_NE(
4741
step, 0, platform::errors::InvalidArgument(
4842
"Step should not be 0, but received step = %d.", step));
4943

44+
T start = (*starts)[i] < 0 ? ((*starts)[i] + dim_value) : (*starts)[i];
45+
start = std::max(start, static_cast<T>(0));
46+
47+
T end =
48+
0 < step && (*ends)[i] < 0 ? ((*ends)[i] + dim_value) : (*ends)[i];
49+
end = std::min(end, dim_value);
50+
5051
if (step > 0) {
5152
start = std::min(start, dim_value);
5253
end = std::max(end, static_cast<T>(0));

0 commit comments

Comments
 (0)