Skip to content

Commit

Permalink
Fix grid sampler
Browse files Browse the repository at this point in the history
  • Loading branch information
wanghaoshuang committed Oct 21, 2021
1 parent 3090988 commit 3b70764
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions paddle/fluid/operators/grid_sampler_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ static inline void clip(const platform::CPUDeviceContext& ctx,
auto grid_abs = grid_slice_t.abs();
auto extra = grid_abs - (grid_abs / double_range).floor() * double_range;
grid_slice_t.device(place) = extra.cwiseMin(double_range - extra);
if (max_val == 0) {
grid_slice_t.device(place) = grid_slice_t.constant(static_cast<T>(0));
}
} else {
auto double_range = static_cast<T>((max_val + 1) * 2);
auto grid_abs = (grid_slice_t + static_cast<T>(0.5)).abs();
Expand Down Expand Up @@ -128,6 +131,9 @@ static inline void clipWithMask(const platform::CPUDeviceContext& ctx,
grid_scale_t * ((is_neg == one_more_flip).template cast<T>() -
(is_neg != one_more_flip).template cast<T>());
grid_slice_t.device(place) = extra.cwiseMin(double_range - extra);
if (max_val == 0) {
grid_slice_t.device(place) = grid_slice_t.constant(static_cast<T>(0));
}
} else {
auto double_range = static_cast<T>((max_val + 1) * 2);
auto grid_abs = (grid_slice_t + static_cast<T>(0.5)).abs();
Expand Down

0 comments on commit 3b70764

Please sign in to comment.