use irange for loops 5 (#66744)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/66744

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: ngimel

Differential Revision: D31705358

fbshipit-source-id: d6ea350cbaa8f452fc78f238160e5374be637a48
This commit is contained in:
Richard Barnes
2021-10-18 21:58:26 -07:00
committed by Facebook GitHub Bot
parent bceb1db885
commit e0643fa3fc
31 changed files with 423 additions and 393 deletions
+3 -2
View File
@@ -1,5 +1,6 @@
#include <gtest/gtest.h>
#include <c10/util/irange.h>
#include <torch/torch.h>
#include <algorithm>
@@ -172,7 +173,7 @@ TEST_F(SequentialTest, AccessWithAt) {
ASSERT_EQ(sequential->size(), 3);
// returns the correct module for a given index
for (size_t i = 0; i < modules.size(); ++i) {
for (const auto i : c10::irange(modules.size())) {
ASSERT_EQ(&sequential->at<M>(i), modules[i].get());
}
@@ -201,7 +202,7 @@ TEST_F(SequentialTest, AccessWithPtr) {
ASSERT_EQ(sequential->size(), 3);
// returns the correct module for a given index
for (size_t i = 0; i < modules.size(); ++i) {
for (const auto i : c10::irange(modules.size())) {
ASSERT_EQ(sequential->ptr(i).get(), modules[i].get());
ASSERT_EQ(sequential[i].get(), modules[i].get());
ASSERT_EQ(sequential->ptr<M>(i).get(), modules[i].get());