Skip to content

Commit d9c8dbe

Browse files
committed
Replace abs by std::abs
Old gcc versions were giving wrong results here, because they would resolve abs as int -> int, thus causing undesired truncation. Replacing abs by std::abs should allow for correct overloading of abs as float -> float.
1 parent 6ac2215 commit d9c8dbe

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

torchvision/csrc/cpu/DeformConv_cpu.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
#include <ATen/TensorUtils.h>
7171
#include <TH/TH.h>
7272

73+
#include <cmath>
7374
#include <iostream>
7475
#include <tuple>
7576

@@ -455,9 +456,9 @@ static void deformable_col2im_kernel(
455456
int yp = int(y) + dy;
456457
int xp = int(x) + dx;
457458
if (0 <= yp && yp < height && 0 <= xp && xp < width &&
458-
abs(y - yp) < 1 && abs(x - xp) < 1) {
459+
std::abs(y - yp) < 1 && std::abs(x - xp) < 1) {
459460
int grad_pos = ((b * channels + c) * height + yp) * width + xp;
460-
scalar_t weight = (1 - abs(y - yp)) * (1 - abs(x - xp));
461+
scalar_t weight = (1 - std::abs(y - yp)) * (1 - std::abs(x - xp));
461462
grad_im[grad_pos] += weight * col[index];
462463
}
463464
}

0 commit comments

Comments
 (0)