未验证 提交 e8a96347 编写于 作者: G gouzil 提交者: GitHub

[clang-tidy] enable bugprone-incorrect-roundings check (#56747)

上级 15728a79
......@@ -12,7 +12,7 @@ bugprone-exception-escape,
-bugprone-fold-init-type,
-bugprone-forwarding-reference-overload,
-bugprone-inaccurate-erase,
-bugprone-incorrect-roundings,
bugprone-incorrect-roundings,
-bugprone-infinite-loop,
bugprone-integer-division,
-bugprone-macro-repeated-side-effects,
......
......@@ -51,9 +51,9 @@ void Poly2Mask(const float* xy, int k, int h, int w, uint8_t* mask) {
x = reinterpret_cast<int*>(xptr->ptr());
y = x + (k + 1);
for (j = 0; j < k; j++) x[j] = static_cast<int>(scale * xy[j * 2 + 0] + .5);
for (j = 0; j < k; j++) x[j] = std::lround(scale * xy[j * 2 + 0]);
x[k] = x[0];
for (j = 0; j < k; j++) y[j] = static_cast<int>(scale * xy[j * 2 + 1] + .5);
for (j = 0; j < k; j++) y[j] = std::lround(scale * xy[j * 2 + 1]);
y[k] = y[0];
for (j = 0; j < k; j++) {
m += UMax(abs(x[j] - x[j + 1]), abs(y[j] - y[j + 1])) + 1;
......@@ -82,7 +82,7 @@ void Poly2Mask(const float* xy, int k, int h, int w, uint8_t* mask) {
for (d = 0; d <= dx; d++) {
t = flip ? dx - d : d;
u[m] = t + xs;
v[m] = static_cast<int>(ys + s * t + .5);
v[m] = std::lround(ys + s * t);
m++;
}
} else {
......@@ -90,7 +90,7 @@ void Poly2Mask(const float* xy, int k, int h, int w, uint8_t* mask) {
for (d = 0; d <= dy; d++) {
t = flip ? dy - d : d;
v[m] = t + ys;
u[m] = static_cast<int>(xs + s * t + .5);
u[m] = std::lround(xs + s * t);
m++;
}
}
......
......@@ -359,17 +359,17 @@ static void NearestNeighbor3DInterpolateGrad(const DenseTensor& output_grad,
auto output_grad_t = EigenTensor<T, 5>::From(output_grad);
for (int d = 0; d < out_d; d++) {
int in_d = static_cast<int>(align_corners
? (ratio_d * static_cast<float>(d) + 0.5f)
: (ratio_d * static_cast<float>(d)));
int in_d = static_cast<int>(
align_corners ? std::lround(ratio_d * static_cast<float>(d))
: (ratio_d * static_cast<float>(d)));
for (int k = 0; k < out_h; k++) { // loop for images
int in_k = static_cast<int>(align_corners
? (ratio_h * static_cast<float>(k) + 0.5f)
: (ratio_h * static_cast<float>(k)));
int in_k = static_cast<int>(
align_corners ? std::lround(ratio_h * static_cast<float>(k))
: (ratio_h * static_cast<float>(k)));
for (int l = 0; l < out_w; l++) {
int in_l = static_cast<int>(
align_corners ? (ratio_w * static_cast<float>(l) + 0.5f)
align_corners ? std::lround(ratio_w * static_cast<float>(l))
: (ratio_w * static_cast<float>(l)));
for (int i = 0; i < n; i++) { // loop for batches
......
......@@ -232,12 +232,12 @@ static void NearestNeighborInterpolate(const DenseTensor& input,
for (int k = 0; k < out_h; k++) { // loop for images
int in_k = (align_corners)
? static_cast<int>(ratio_h * static_cast<float>(k) + 0.5)
? std::lround(ratio_h * static_cast<float>(k))
: static_cast<int>(ratio_h * static_cast<float>(k));
for (int l = 0; l < out_w; l++) {
int in_l = (align_corners)
? static_cast<int>(ratio_w * static_cast<float>(l) + 0.5)
? std::lround(ratio_w * static_cast<float>(l))
: static_cast<int>(ratio_w * static_cast<float>(l));
for (int i = 0; i < n; i++) { // loop for batches
......@@ -515,16 +515,16 @@ static void NearestNeighbor3DInterpolate(const DenseTensor& input,
auto output_t = EigenTensor<T, 5>::From(*output);
for (int d = 0; d < out_d; d++) { // loop for images
int in_d = (align_corners)
? static_cast<int>(ratio_d * static_cast<float>(d) + 0.5)
? std::lround(ratio_d * static_cast<float>(d))
: static_cast<int>(ratio_d * static_cast<float>(d));
for (int k = 0; k < out_h; k++) {
int in_k = (align_corners)
? static_cast<int>(ratio_h * static_cast<float>(k) + 0.5)
? std::lround(ratio_h * static_cast<float>(k))
: static_cast<int>(ratio_h * static_cast<float>(k));
for (int l = 0; l < out_w; l++) {
int in_l = (align_corners)
? static_cast<int>(ratio_w * static_cast<float>(l) + 0.5)
? std::lround(ratio_w * static_cast<float>(l))
: static_cast<int>(ratio_w * static_cast<float>(l));
for (int i = 0; i < n; i++) { // loop for batches
......
......@@ -170,11 +170,11 @@ void RoiAlignGradKernel(const Context& dev_ctx,
T count = roi_bin_grid_h * roi_bin_grid_w;
for (int iy = 0; iy < roi_bin_grid_h; iy++) {
const T y = roi_ymin + ph * bin_size_h +
static_cast<T>(iy + .5f) * bin_size_h /
static_cast<T>(iy + .5f) * bin_size_h / // NOLINT
static_cast<T>(roi_bin_grid_h);
for (int ix = 0; ix < roi_bin_grid_w; ix++) {
const T x = roi_xmin + pw * bin_size_w +
static_cast<T>(ix + .5f) * bin_size_w /
static_cast<T>(ix + .5f) * bin_size_w / // NOLINT
static_cast<T>(roi_bin_grid_w);
bilinear_interpolate_gradient(height,
width,
......
......@@ -79,12 +79,13 @@ std::vector<OffsetsAndRatios<T>> GetIndexesAndRatios(
for (std::size_t px = 0; px < pooled_width; px++) {
for (std::size_t iy = 0; iy < roi_bin_grid_h; iy++) {
// calculate x of sample points
auto y = roi_ymin + bin_h * (py + static_cast<T>(iy + .5f) /
auto y = roi_ymin + bin_h * (py + static_cast<T>(iy + .5f) / // NOLINT
static_cast<T>(roi_bin_grid_h));
for (std::size_t ix = 0; ix < roi_bin_grid_w; ix++) {
// calculate x of sample points
auto x = roi_xmin + bin_w * (px + static_cast<T>(ix + .5f) /
static_cast<T>(roi_bin_grid_w));
auto x =
roi_xmin + bin_w * (px + static_cast<T>(ix + .5f) / // NOLINT
static_cast<T>(roi_bin_grid_w));
// deal with elements out of map
if (y < -1.0 || y > height || x < -1.0 || x > width) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册