Skip to content

Commit

Permalink
Change the invoking method of settiem from numpy to set_value op when…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
zyfncg authored and AnnaTrainingG committed Sep 29, 2021
1 parent b04b36c commit 32c2717
Show file tree
Hide file tree
Showing 6 changed files with 303 additions and 165 deletions.
13 changes: 7 additions & 6 deletions paddle/fluid/operators/slice_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,18 @@ inline void CheckAndUpdateSliceAttrs(const framework::DDim in_dims,
if (infer_flags != nullptr && (*infer_flags)[i] == -1) {
continue;
}
T start = (*starts)[i] < 0 ? ((*starts)[i] + dim_value) : (*starts)[i];
start = std::max(start, static_cast<T>(0));

T end = (*ends)[i] < 0 ? ((*ends)[i] + dim_value) : (*ends)[i];
end = std::min(end, dim_value);

T step = steps == nullptr ? 1 : (*steps)[i];
PADDLE_ENFORCE_NE(
step, 0, platform::errors::InvalidArgument(
"Step should not be 0, but received step = %d.", step));

T start = (*starts)[i] < 0 ? ((*starts)[i] + dim_value) : (*starts)[i];
start = std::max(start, static_cast<T>(0));

T end =
0 < step && (*ends)[i] < 0 ? ((*ends)[i] + dim_value) : (*ends)[i];
end = std::min(end, dim_value);

if (step > 0) {
start = std::min(start, dim_value);
end = std::max(end, static_cast<T>(0));
Expand Down
Loading

0 comments on commit 32c2717

Please sign in to comment.