Skip to content

Commit 1433160

Browse files
r-barnesfacebook-github-bot
authored andcommitted
use irange for loops 6 (pytorch#66742)
Summary: Pull Request resolved: pytorch#66742 Modified loops in files under fbsource/fbcode/caffe2/ from the format `for(TYPE var=x0;var<x_max;x++)` to the format `for(const auto var: irange(xmax))` This was achieved by running r-barnes's loop upgrader script (D28874212) with some modification to exclude all files under /torch/jit and a number of reversions or unused variable suppression warnings added by hand. Test Plan: Sandcastle Reviewed By: malfet Differential Revision: D31705366 fbshipit-source-id: be58222426c192406a7f93c21582c3f6f2082401
1 parent 9a7732e commit 1433160

File tree

94 files changed

+558
-480
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+558
-480
lines changed

caffe2/ideep/operators/conv_pool_base_op.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class IDEEPConvPoolOpBase : public ConvPoolOpBase<IDEEPContext> {
5353

5454
bool RunOnDevice() override {
5555
if (!global_pooling_) {
56-
for (int dim = 0; dim < kernel_.size(); ++dim) {
56+
for (const auto dim : c10::irange(kernel_.size())) {
5757
CAFFE_ENFORCE_GT(kernel_[dim], 0);
5858
}
5959
}

caffe2/ideep/operators/conv_transpose_unpool_base_op.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class IDEEPConvTransposeUnpoolBase : public IDEEPOperator {
109109
CAFFE_ENFORCE_EQ(pads_.size(), 2 * kernel_.size());
110110
}
111111

112-
for (int dim = 0; dim < kernel_.size(); ++dim) {
112+
for (const auto dim : c10::irange(kernel_.size())) {
113113
CAFFE_ENFORCE_GT(kernel_[dim], 0);
114114
CAFFE_ENFORCE_GT(stride_[dim], 0);
115115
CAFFE_ENFORCE_GE(adj_[dim], 0);
@@ -143,7 +143,7 @@ class IDEEPConvTransposeUnpoolBase : public IDEEPOperator {
143143
auto input_dims = input.get_dims();
144144
itensor::dims dims;
145145
dims.assign(input_dims.begin() + 2, input_dims.end());
146-
for (int dim = 0; dim < dims.size(); ++dim) {
146+
for (const auto dim : c10::irange(dims.size())) {
147147
int dim_size = 0;
148148
ComputeSizeAndPad(
149149
dims[dim],

caffe2/ideep/operators/operator_fallback_ideep.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class IDEEPFallbackOp final : public IDEEPOperator {
5252
// Create output blobs in parent workspace,
5353
// then forward output blobs to local workspace.
5454
std::unordered_map<string, string> forwarded_output_blobs;
55-
for (int i = 0; i < base_def_.output_size(); i++) {
55+
for (const auto i : c10::irange(base_def_.output_size())) {
5656
// For in-place case, the in/output tensor for local_ws must be
5757
// re-created, instead of forwarding from current workspace.
5858
string parent_name(base_def_.output(i));
@@ -81,7 +81,7 @@ class IDEEPFallbackOp final : public IDEEPOperator {
8181
}
8282

8383
bool RunOnDevice() override {
84-
for (int i = 0; i < InputSize(); ++i) {
84+
for (const auto i : c10::irange(InputSize())) {
8585
if (InputIsType<itensor>(i)
8686
&& (Input(i).has_scale()
8787
|| Input(i).get_data_type() == idtype::f32)) {
@@ -128,7 +128,7 @@ class IDEEPFallbackOp final : public IDEEPOperator {
128128
return false;
129129
}
130130

131-
for (int i = 0; i < OutputSize(); ++i) {
131+
for (const auto i : c10::irange(OutputSize())) {
132132
if (SkipOutputCopy::Contains(i)) {
133133
VLOG(1) << "Copy output: index " << i << " skipped.";
134134
continue;

caffe2/ideep/utils/ideep_context.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class IDEEPContext final : public BaseContext {
8383
static_cast<const void*>(src),
8484
static_cast<void*>(dst));
8585
} else {
86-
for (size_t i = 0; i < n; ++i) {
86+
for (const auto i : c10::irange(n)) {
8787
dst[i] = src[i];
8888
}
8989
}

0 commit comments

Comments
 (0)