File tree Expand file tree Collapse file tree 2 files changed +9
-11
lines changed
Expand file tree Collapse file tree 2 files changed +9
-11
lines changed Original file line number Diff line number Diff line change @@ -17,13 +17,12 @@ template<typename Acctype>
1717__device__ __forceinline__
1818static Acctype linear_upsampling_compute_source_index (
1919 Acctype scale, int dst_index, bool align_corners) {
20- if (dst_index == 0 ) {
21- return Acctype (0 );
22- } else if (align_corners) {
23- return scale * dst_index;
24- } else {
25- return scale * (dst_index + Acctype (0.5 )) - Acctype (0.5 );
26- }
20+ if (align_corners) {
21+ return scale * dst_index;
22+ } else {
23+ Acctype src_idx = scale * (dst_index + Acctype (0.5 )) - Acctype (0.5 );
24+ return src_idx < Acctype (0 ) ? Acctype (0 ) : src_idx;
25+ }
2726}
2827
2928
Original file line number Diff line number Diff line change @@ -14,12 +14,11 @@ static inline float THNN_(linear_upsampling_compute_scale)(
1414
1515static inline float THNN_ (linear_upsampling_compute_source_index )(
1616 float scale , int dst_index , bool align_corners ) {
17- if (dst_index == 0 ) {
18- return 0.f ;
19- } else if (align_corners ) {
17+ if (align_corners ) {
2018 return scale * dst_index ;
2119 } else {
22- return scale * (dst_index + 0.5 ) - 0.5 ;
20+ float src_idx = scale * (dst_index + 0.5 ) - 0.5 ;
21+ return src_idx < 0 ? 0.f : src_idx ;
2322 }
2423}
2524
You can’t perform that action at this time.
0 commit comments