mirror of
https://github.com/pytorch/pytorch.git
synced 2025-11-06 00:54:56 +08:00
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:
committed by
Facebook GitHub Bot
parent
bceb1db885
commit
e0643fa3fc
@ -1,5 +1,6 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <c10/util/irange.h>
|
||||
#include <torch/detail/static.h>
|
||||
#include <torch/csrc/utils/variadic.h>
|
||||
#include <torch/torch.h>
|
||||
@ -95,7 +96,7 @@ TEST(TestStatic, Apply) {
|
||||
std::vector<int> v;
|
||||
torch::apply([&v](int x) { v.push_back(x); }, 1, 2, 3, 4, 5);
|
||||
ASSERT_EQ(v.size(), 5);
|
||||
for (size_t i = 0; i < v.size(); ++i) {
|
||||
for (const auto i : c10::irange(v.size())) {
|
||||
ASSERT_EQ(v.at(i), i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user