Skip to content

Commit 66a6b7f

Browse files
generatedunixname89002005287564facebook-github-bot
authored andcommitted
[Codemod][CppQualityCommon] Fix CQS signal readability-braces-around-statements in fbcode/pytorch/vision
Reviewed By: dtolnay Differential Revision: D78881813 fbshipit-source-id: f5d56101748bdfec69ab77fbda21ce29ec131323
1 parent f5fce85 commit 66a6b7f

File tree

9 files changed

+43
-23
lines changed

9 files changed

+43
-23
lines changed

torchvision/csrc/io/image/cpu/decode_png.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@ torch::Tensor decode_png(
104104

105105
int channels = png_get_channels(png_ptr, info_ptr);
106106

107-
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
107+
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) {
108108
png_set_expand_gray_1_2_4_to_8(png_ptr);
109+
}
109110

110111
int number_of_passes;
111112
if (interlace_type == PNG_INTERLACE_ADAM7) {

torchvision/csrc/io/image/cpu/encode_png.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ void torch_png_write_data(
4747
size_t nsize = p->size + length;
4848

4949
/* allocate or grow buffer */
50-
if (p->buffer)
50+
if (p->buffer) {
5151
p->buffer = (char*)realloc(p->buffer, nsize);
52-
else
52+
} else {
5353
p->buffer = (char*)malloc(nsize);
54+
}
5455

55-
if (!p->buffer)
56+
if (!p->buffer) {
5657
png_error(png_ptr, "Write Error");
58+
}
5759

5860
/* copy new bytes to end of buffer */
5961
memcpy(p->buffer + p->size, data, length);

torchvision/csrc/io/image/cuda/decode_jpegs_cuda.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ std::vector<torch::Tensor> decode_jpegs_cuda(
8989
at::cuda::CUDAGuard device_guard(device);
9090

9191
if (cudaJpegDecoder == nullptr || device != cudaJpegDecoder->target_device) {
92-
if (cudaJpegDecoder != nullptr)
92+
if (cudaJpegDecoder != nullptr) {
9393
cudaJpegDecoder.reset(new CUDAJpegDecoder(device));
94-
else {
94+
} else {
9595
cudaJpegDecoder = std::make_unique<CUDAJpegDecoder>(device);
9696
std::atexit([]() { cudaJpegDecoder.reset(); });
9797
}

torchvision/csrc/io/image/cuda/encode_jpegs_cuda.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ std::vector<torch::Tensor> encode_jpegs_cuda(
4646
// so we reuse it across calls. NB: the cached structures are device specific
4747
// and cannot be reused across devices
4848
if (cudaJpegEncoder == nullptr || device != cudaJpegEncoder->target_device) {
49-
if (cudaJpegEncoder != nullptr)
49+
if (cudaJpegEncoder != nullptr) {
5050
delete cudaJpegEncoder.release();
51+
}
5152

5253
cudaJpegEncoder = std::make_unique<CUDAJpegEncoder>(device);
5354

torchvision/csrc/ops/cpu/nms_kernel.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ at::Tensor nms_kernel_impl(
1717
dets.scalar_type() == scores.scalar_type(),
1818
"dets should have the same type as scores");
1919

20-
if (dets.numel() == 0)
20+
if (dets.numel() == 0) {
2121
return at::empty({0}, dets.options().dtype(at::kLong));
22+
}
2223

2324
auto x1_t = dets.select(1, 0).contiguous();
2425
auto y1_t = dets.select(1, 1).contiguous();
@@ -47,8 +48,9 @@ at::Tensor nms_kernel_impl(
4748

4849
for (int64_t _i = 0; _i < ndets; _i++) {
4950
auto i = order[_i];
50-
if (suppressed[i] == 1)
51+
if (suppressed[i] == 1) {
5152
continue;
53+
}
5254
keep[num_to_keep++] = i;
5355
auto ix1 = x1[i];
5456
auto iy1 = y1[i];
@@ -58,8 +60,9 @@ at::Tensor nms_kernel_impl(
5860

5961
for (int64_t _j = _i + 1; _j < ndets; _j++) {
6062
auto j = order[_j];
61-
if (suppressed[j] == 1)
63+
if (suppressed[j] == 1) {
6264
continue;
65+
}
6366
auto xx1 = std::max(ix1, x1[j]);
6467
auto yy1 = std::max(iy1, y1[j]);
6568
auto xx2 = std::min(ix2, x2[j]);
@@ -69,8 +72,9 @@ at::Tensor nms_kernel_impl(
6972
auto h = std::max(static_cast<scalar_t>(0), yy2 - yy1);
7073
auto inter = w * h;
7174
auto ovr = inter / (iarea + areas[j] - inter);
72-
if (ovr > iou_threshold)
75+
if (ovr > iou_threshold) {
7376
suppressed[j] = 1;
77+
}
7478
}
7579
}
7680
return keep_t.narrow(/*dim=*/0, /*start=*/0, /*length=*/num_to_keep);

torchvision/csrc/ops/cpu/ps_roi_align_kernel.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ T bilinear_interpolate(
2020
return 0;
2121
}
2222

23-
if (y <= 0)
23+
if (y <= 0) {
2424
y = 0;
25-
if (x <= 0)
25+
}
26+
if (x <= 0) {
2627
x = 0;
28+
}
2729

2830
int y_low = (int)y;
2931
int x_low = (int)x;
@@ -163,10 +165,12 @@ void bilinear_interpolate_gradient(
163165
return;
164166
}
165167

166-
if (y <= 0)
168+
if (y <= 0) {
167169
y = 0;
168-
if (x <= 0)
170+
}
171+
if (x <= 0) {
169172
x = 0;
173+
}
170174

171175
y_low = (int)y;
172176
x_low = (int)x;

torchvision/csrc/ops/cpu/roi_align_kernel.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,12 @@ void bilinear_interpolate_gradient(
130130
return;
131131
}
132132

133-
if (y <= 0)
133+
if (y <= 0) {
134134
y = 0;
135-
if (x <= 0)
135+
}
136+
if (x <= 0) {
136137
x = 0;
138+
}
137139

138140
y_low = (int)y;
139141
x_low = (int)x;
@@ -304,8 +306,9 @@ at::Tensor roi_align_forward_kernel(
304306
at::Tensor output = at::zeros(
305307
{num_rois, channels, pooled_height, pooled_width}, input.options());
306308

307-
if (output.numel() == 0)
309+
if (output.numel() == 0) {
308310
return output;
311+
}
309312

310313
auto input_ = input.contiguous(), rois_ = rois.contiguous();
311314
AT_DISPATCH_FLOATING_TYPES_AND_HALF(

torchvision/csrc/ops/quantized/cpu/qnms_kernel.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ at::Tensor qnms_kernel_impl(
1717
dets.scalar_type() == scores.scalar_type(),
1818
"dets should have the same type as scores");
1919

20-
if (dets.numel() == 0)
20+
if (dets.numel() == 0) {
2121
return at::empty({0}, dets.options().dtype(at::kLong));
22+
}
2223

2324
const auto ndets = dets.size(0);
2425

@@ -56,8 +57,9 @@ at::Tensor qnms_kernel_impl(
5657

5758
for (int64_t _i = 0; _i < ndets; _i++) {
5859
auto i = order[_i];
59-
if (suppressed[i] == 1)
60+
if (suppressed[i] == 1) {
6061
continue;
62+
}
6163
keep[num_to_keep++] = i;
6264

6365
// We explicitly cast coordinates to float so that the code can be
@@ -70,8 +72,9 @@ at::Tensor qnms_kernel_impl(
7072

7173
for (int64_t _j = _i + 1; _j < ndets; _j++) {
7274
auto j = order[_j];
73-
if (suppressed[j] == 1)
75+
if (suppressed[j] == 1) {
7476
continue;
77+
}
7578
float xx1 = std::max(ix1val, (float)x1[j].val_);
7679
float yy1 = std::max(iy1val, (float)y1[j].val_);
7780
float xx2 = std::min(ix2val, (float)x2[j].val_);
@@ -81,8 +84,9 @@ at::Tensor qnms_kernel_impl(
8184
auto h = std::max(0.f, yy2 - yy1); // * scale (gets canceled below)
8285
auto inter = w * h;
8386
auto ovr = inter / (iarea + areas[j] - inter);
84-
if (ovr > iou_threshold)
87+
if (ovr > iou_threshold) {
8588
suppressed[j] = 1;
89+
}
8690
}
8791
}
8892
return keep_t.narrow(/*dim=*/0, /*start=*/0, /*length=*/num_to_keep);

torchvision/csrc/ops/quantized/cpu/qroi_align_kernel.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,9 @@ at::Tensor qroi_align_forward_kernel(
257257
input.q_scale(),
258258
input.q_zero_point());
259259

260-
if (output.numel() == 0)
260+
if (output.numel() == 0) {
261261
return output;
262+
}
262263

263264
AT_DISPATCH_QINT_TYPES(input.scalar_type(), "qroi_align_forward_kernel", [&] {
264265
qroi_align_forward_kernel_impl<scalar_t>(

0 commit comments

Comments
 (0)