mirror of
https://github.com/pytorch/pytorch.git
synced 2026-11-20 09:04:25 +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/torch.h>
|
||||
|
||||
#include <test/cpp/api/support.h>
|
||||
@@ -11,7 +12,8 @@ struct OperationTest : torch::test::SeedingFixture {
|
||||
};
|
||||
|
||||
TEST_F(OperationTest, Lerp) {
|
||||
for (auto i = 0; i < TEST_AMOUNT; i++) {
|
||||
for (const auto i : c10::irange(TEST_AMOUNT)) {
|
||||
(void)i; // Suppress unused variable warning
|
||||
// test lerp_kernel_scalar
|
||||
auto start = torch::rand({3, 5});
|
||||
auto end = torch::rand({3, 5});
|
||||
@@ -35,13 +37,14 @@ TEST_F(OperationTest, Lerp) {
|
||||
}
|
||||
|
||||
TEST_F(OperationTest, Cross) {
|
||||
for (auto i = 0; i < TEST_AMOUNT; i++) {
|
||||
for (const auto i : c10::irange(TEST_AMOUNT)) {
|
||||
(void)i; // Suppress unused variable warning
|
||||
// input
|
||||
auto a = torch::rand({10, 3});
|
||||
auto b = torch::rand({10, 3});
|
||||
// expected
|
||||
auto exp = torch::empty({10, 3});
|
||||
for (int j = 0; j < 10; j++) {
|
||||
for (const auto j : c10::irange(10)) {
|
||||
auto u1 = a[j][0], u2 = a[j][1], u3 = a[j][2];
|
||||
auto v1 = b[j][0], v2 = b[j][1], v3 = b[j][2];
|
||||
exp[j][0] = u2 * v3 - v2 * u3;
|
||||
|
||||
Reference in New Issue
Block a user