use irange for loops 10 (#69394)

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

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

fbshipit-source-id: fc7c4f76d2f32a17a0faf329294b3fe7cb81df32
This commit is contained in:
Richard Barnes
2021-12-09 09:44:04 -08:00
committed by Facebook GitHub Bot
parent 2d5b3101c1
commit afb742382a
11 changed files with 103 additions and 85 deletions
+4 -3
View File
@@ -2,6 +2,7 @@
#include <torch/torch.h>
#include <ATen/native/Pow.h>
#include <c10/util/irange.h>
#include <torch/types.h>
#include <torch/utils.h>
#include <test/cpp/api/support.h>
@@ -24,7 +25,7 @@ TEST_F(DispatchTest, TestAVX2) {
setenv("ATEN_CPU_CAPABILITY", "avx2", 1);
#endif
const auto actual_pow_avx2 = vals_tensor.pow(pows_tensor);
for (int i = 0; i < 4; i++) {
for (const auto i : c10::irange(4)) {
ASSERT_EQ(result[i], actual_pow_avx2[i].item<int>());
}
}
@@ -40,7 +41,7 @@ TEST_F(DispatchTest, TestAVX512) {
setenv("ATEN_CPU_CAPABILITY", "avx512", 1);
#endif
const auto actual_pow_avx512 = vals_tensor.pow(pows_tensor);
for (int i = 0; i < 4; i++) {
for (const auto i : c10::irange(4)) {
ASSERT_EQ(result[i], actual_pow_avx512[i].item<int>());
}
}
@@ -56,7 +57,7 @@ TEST_F(DispatchTest, TestDefault) {
setenv("ATEN_CPU_CAPABILITY", "default", 1);
#endif
const auto actual_pow_default = vals_tensor.pow(pows_tensor);
for (int i = 0; i < 4; i++) {
for (const auto i : c10::irange(4)) {
ASSERT_EQ(result[i], actual_pow_default[i].item<int>());
}
}