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

View File

@ -1706,7 +1706,7 @@ void concrete_dispatch_fn(
}
// Find overloaded tensors
for (int64_t idx = 0; idx < arguments.size(); idx++) {
for (const auto idx : c10::irange(arguments.size())) {
const auto& ivalue = arguments[idx];
if (ivalue.isTensor()) {
const auto& tensor = ivalue.toTensor();
@ -1728,12 +1728,12 @@ void concrete_dispatch_fn(
}
// Populate positional arguments
for (int64_t idx = 0; idx < positional_default_start; idx++) {
for (const auto idx : c10::irange(positional_default_start)) {
PyTuple_SET_ITEM(args.ptr(), idx, torch::jit::toPyObject(std::move(arguments[idx])).release().ptr());
}
// Populate keyword arguments
for (int64_t idx = kwarg_only_start; idx < arguments.size(); idx++) {
for (const auto idx : c10::irange(kwarg_only_start, arguments.size())) {
// But don't populate default keyword arguments
if (is_default(idx)) continue;
const auto& arg = schema.arguments()[idx];