Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang-tidy] NO.35 enable bugprone-incorrect-roundings #56747

Merged
merged 2 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions paddle/fluid/operators/detection/mask_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -82,15 +82,15 @@ 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 {
s = dy == 0 ? 0 : static_cast<double>(xe - xs) / dy;
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++;
}
}
Expand Down
14 changes: 7 additions & 7 deletions paddle/phi/kernels/cpu/interpolate_grad_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions paddle/phi/kernels/cpu/interpolate_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions paddle/phi/kernels/cpu/roi_align_grad_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions paddle/phi/kernels/cpu/roi_align_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down