Skip to content

Commit

Permalink
Revert D30652629: use irange for loops
Browse files Browse the repository at this point in the history
Test Plan: revert-hammer

Differential Revision:
D30652629 (pytorch@687c226)

Original commit changeset: 0ae6c4bbbb55

fbshipit-source-id: 5c4f067b584a021c8c9656454d1ee60999600fb3
  • Loading branch information
Xue Li authored and facebook-github-bot committed Oct 15, 2021
1 parent 1e2b2ee commit 2f099c7
Show file tree
Hide file tree
Showing 487 changed files with 21,930 additions and 22,184 deletions.
15 changes: 7 additions & 8 deletions android/pytorch_android/src/main/cpp/pytorch_jni_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <string>

#include <c10/core/MemoryFormat.h>
#include <c10/util/irange.h>

#include <fbjni/ByteBuffer.h>
#include <fbjni/fbjni.h>
Expand Down Expand Up @@ -98,7 +97,7 @@ static at::Tensor newAtTensor(
std::vector<int64_t> shapeVec{};
shapeVec.reserve(rank);
auto numel = 1;
for (const auto i : c10::irange(rank)) {
for (auto i = 0; i < rank; ++i) {
shapeVec.push_back(shapeArr[i]);
numel *= shapeArr[i];
}
Expand Down Expand Up @@ -522,7 +521,7 @@ at::IValue JIValue::JIValueToAtIValue(

std::vector<at::IValue> elements;
elements.reserve(n);
for (const auto i : c10::irange(n)) {
for (auto i = 0; i < n; ++i) {
auto jivalue_element = jarray->getElement(i);
auto element = JIValue::JIValueToAtIValue(jivalue_element);
elements.push_back(std::move(element));
Expand All @@ -536,7 +535,7 @@ at::IValue JIValue::JIValueToAtIValue(
size_t n = jArrayPinned.size();
c10::List<bool> list{};
list.reserve(n);
for (const auto i : c10::irange(n)) {
for (size_t i = 0; i < n; ++i) {
list.push_back(jArrayPinned[i]);
}
return at::IValue{std::move(list)};
Expand All @@ -548,7 +547,7 @@ at::IValue JIValue::JIValueToAtIValue(
size_t n = jArrayPinned.size();
c10::List<int64_t> list{};
list.reserve(n);
for (const auto i : c10::irange(n)) {
for (size_t i = 0; i < n; ++i) {
list.push_back(jArrayPinned[i]);
}
return at::IValue{std::move(list)};
Expand All @@ -560,7 +559,7 @@ at::IValue JIValue::JIValueToAtIValue(
size_t n = jArrayPinned.size();
c10::List<double> list{};
list.reserve(n);
for (const auto i : c10::irange(n)) {
for (size_t i = 0; i < n; ++i) {
list.push_back(jArrayPinned[i]);
}
return at::IValue{std::move(list)};
Expand All @@ -573,7 +572,7 @@ at::IValue JIValue::JIValueToAtIValue(
size_t n = jArray->size();
c10::List<at::Tensor> list{};
list.reserve(n);
for (const auto i : c10::irange(n)) {
for (size_t i = 0; i < n; ++i) {
list.push_back(
TensorHybrid::newAtTensorFromJTensor(jArray->getElement(i)));
}
Expand All @@ -595,7 +594,7 @@ at::IValue JIValue::JIValueToAtIValue(
c10::impl::GenericList list{c10::unshapedType(first_element.type())};
list.reserve(n);
list.push_back(first_element);
for (const auto i : c10::irange(1, n)) {
for (auto i = 1; i < n; ++i) {
auto jivalue_element = jarray->getElement(i);
auto element = JIValue::JIValueToAtIValue(jivalue_element);
list.push_back(element);
Expand Down
5 changes: 2 additions & 3 deletions android/pytorch_android/src/main/cpp/pytorch_jni_lite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <fbjni/ByteBuffer.h>
#include <fbjni/fbjni.h>

#include <c10/util/irange.h>
#include <torch/csrc/jit/mobile/import.h>
#include <torch/csrc/jit/mobile/module.h>
#include <torch/script.h>
Expand Down Expand Up @@ -158,7 +157,7 @@ class PytorchJni : public facebook::jni::HybridClass<PytorchJni> {
std::vector<at::IValue> inputs{};
size_t n = jinputs->size();
inputs.reserve(n);
for (const auto i : c10::irange(n)) {
for (size_t i = 0; i < n; i++) {
at::IValue atIValue = JIValue::JIValueToAtIValue(jinputs->getElement(i));
if (at::kVulkan == deviceType_) {
inputs.push_back(
Expand Down Expand Up @@ -187,7 +186,7 @@ class PytorchJni : public facebook::jni::HybridClass<PytorchJni> {
std::vector<at::IValue> inputs{};
size_t n = jinputs->size();
inputs.reserve(n);
for (const auto i : c10::irange(n)) {
for (size_t i = 0; i < n; i++) {
at::IValue atIValue = JIValue::JIValueToAtIValue(jinputs->getElement(i));
if (at::kVulkan == deviceType_) {
inputs.push_back(
Expand Down
3 changes: 1 addition & 2 deletions aten/src/ATen/BatchingRegistrations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <ATen/BatchedFallback.h>
#include <ATen/native/ResizeCommon.h>
#include <ATen/ATen.h>
#include <c10/util/irange.h>

namespace at {

Expand Down Expand Up @@ -330,7 +329,7 @@ Tensor permute_batching_rule(const Tensor& self, IntArrayRef dims) {

VmapDimVector all_dims_physical;
all_dims_physical.reserve(self_physical.tensor().dim());
for (const auto bdim : c10::irange(self_physical.numBatchDims())) {
for (int64_t bdim = 0; bdim < self_physical.numBatchDims(); bdim++) {
all_dims_physical.push_back(bdim);
}
all_dims_physical.insert(
Expand Down
5 changes: 2 additions & 3 deletions aten/src/ATen/CPUApplyUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <ATen/Parallel.h>
#include <ATen/TensorUtils.h>
#include <c10/util/irange.h>
#include <limits>
#include <utility>
#include <cstring>
Expand Down Expand Up @@ -131,7 +130,7 @@ inline Tensor sort_strides(Tensor& tensor_) {
IntArrayRef strides = tensor_.strides();
std::vector<int64_t> indices;
indices.reserve(tensor_.ndimension());
for (const auto i : c10::irange(tensor_.ndimension())) {
for (int64_t i = 0; i < tensor_.ndimension(); i++) {
indices.push_back(i);
}
std::sort(indices.begin(), indices.end(), [&strides](int64_t i1, int64_t i2) {
Expand Down Expand Up @@ -197,7 +196,7 @@ inline bool _all_equal_numel(at::ArrayRef<Tensor> tensors) {
if (tensors.size() == 0)
return true;
int64_t all_numel = tensors[0].numel();
for (const auto i : c10::irange(1, tensors.size())) {
for (size_t i = 1; i < tensors.size(); i++) {
if (tensors[i].numel() != all_numel)
return false;
}
Expand Down
3 changes: 1 addition & 2 deletions aten/src/ATen/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <c10/util/Exception.h>
#include <c10/core/impl/DeviceGuardImplInterface.h>
#include <c10/core/QEngine.h>
#include <c10/util/irange.h>

#include <memory>
#include <mutex>
Expand Down Expand Up @@ -352,7 +351,7 @@ static inline void manual_seed(uint64_t seed) {
// available. In that case, we must not seed CUDA; it will fail!
const auto num_gpus = detail::getCUDAHooks().getNumGPUs();
if (hasCUDA() && num_gpus > 0) {
for (const auto i : c10::irange(num_gpus)) {
for (int i = 0; i < num_gpus; i++) {
auto cuda_gen = globalContext().defaultGenerator(
Device(at::kCUDA, static_cast<c10::DeviceIndex>(i))
);
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/ExpandUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ std::vector<int64_t> infer_dense_strides(IntArrayRef tensor_sizes, IntArrayRef t
// compute output strides which preserves the input tensor's memory layout
std::vector<int64_t> out_strides(ndim);
int64_t curr_stride = 1;
for (const auto i : c10::irange(ndim)) {
for (size_t i = 0; i < ndim; ++i) {
int64_t idx = perm[i];
out_strides[idx] = curr_stride;
// Note: for size 0, we simply treated it as 1, it really doesn't matter here
Expand Down
9 changes: 4 additions & 5 deletions aten/src/ATen/ExpandUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <ATen/Tensor.h>
#include <c10/util/Exception.h>
#include <c10/util/MaybeOwned.h>
#include <c10/util/irange.h>

#include <functional>
#include <sstream>
Expand Down Expand Up @@ -267,7 +266,7 @@ inline std::vector<Tensor> expand_outplace(TensorList to_expand) {
// expands a list of Tensors; ignores undefined (null) tensors
bool first = true;
DimVector sizes;
for (const auto i : c10::irange(to_expand.size())) {
for (size_t i = 0; i < to_expand.size(); ++i) {
if (!to_expand[i].defined()) {
continue;
} else if (first) {
Expand All @@ -279,7 +278,7 @@ inline std::vector<Tensor> expand_outplace(TensorList to_expand) {
}

std::vector<Tensor> result(to_expand.size());
for (const auto i : c10::irange(to_expand.size())) {
for (size_t i = 0; i < to_expand.size(); ++i) {
if (!to_expand[i].defined()) {
continue;
} else if (to_expand[i].sizes().equals(sizes)) {
Expand All @@ -300,7 +299,7 @@ static inline Tensor sum_to(Tensor tensor, const IntArrayRef shape) {
c10::SmallVector<int64_t, 8> reduce_dims;
const at::IntArrayRef sizes = tensor.sizes();
const int64_t leading_dims = sizes.size() - shape.size();
for (const auto i : c10::irange(leading_dims)) {
for (int64_t i = 0; i < leading_dims; ++i) {
reduce_dims.push_back(i);
}
for (int64_t i = leading_dims; i < static_cast<int64_t>(sizes.size()); ++i) {
Expand All @@ -321,7 +320,7 @@ static inline bool is_expandable_to(IntArrayRef shape, IntArrayRef desired) {
if (ndim > target_dim) {
return false;
}
for (const auto i : c10::irange(ndim)) {
for (size_t i = 0; i < ndim; i++) {
int64_t size = shape[ndim - i - 1];
int64_t target = desired[target_dim - i - 1];
if (size != target && size != 1) {
Expand Down
3 changes: 1 addition & 2 deletions aten/src/ATen/MemoryOverlap.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <ATen/MemoryOverlap.h>
#include <ATen/core/TensorBase.h>
#include <c10/core/Layout.h>
#include <c10/util/irange.h>

namespace at {

Expand All @@ -18,7 +17,7 @@ MemOverlap has_internal_overlap(TensorImpl* t) {

auto strides = t->strides();
auto sizes = t->sizes();
for (const auto i : c10::irange(strides.size())) {
for (size_t i = 0; i < strides.size(); ++i) {
if (strides[i] == 0 && sizes[i] > 1) {
return MemOverlap::YES;
}
Expand Down
4 changes: 2 additions & 2 deletions aten/src/ATen/NamedTensorUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ std::vector<Dimname> compute_squeeze_outnames(const Tensor& tensor) {
}
std::vector<Dimname> outnames;
auto tensor_names = tensor.names();
for (const auto d : c10::irange(tensor.dim())) {
for (int64_t d = 0; d < tensor.dim(); d++) {
if (tensor.sizes()[d] != 1) {
outnames.push_back(tensor_names[d]);
}
Expand All @@ -242,7 +242,7 @@ std::vector<Dimname> compute_diagonal_outnames(
}
std::vector<Dimname> outnames;
auto tensor_names = tensor.names();
for (const auto d : c10::irange(tensor.dim())) {
for (int64_t d = 0; d < tensor.dim(); d++) {
if (d == dim1 || d == dim2) {
continue;
}
Expand Down
3 changes: 1 addition & 2 deletions aten/src/ATen/ParallelNative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#ifndef C10_MOBILE
#include <c10/core/thread_pool.h>
#include <c10/util/irange.h>
#else
#include <caffe2/utils/threadpool/pthreadpool-cpp.h>
#endif // C10_MOBILE
Expand Down Expand Up @@ -88,7 +87,7 @@ TaskThreadPoolBase& _get_intraop_pool() {
// `fn` will be called with params: (thread_pool_task_id, task_id).
void _run_with_pool(const std::function<void(int, size_t)>& fn, size_t range) {
#ifndef C10_MOBILE
for (const auto i : c10::irange(1, range)) {
for (size_t i = 1; i < range; ++i) {
_get_intraop_pool().run([fn, i]() { fn((int)i, i); });
}
// Run the first task on the current thread directly.
Expand Down
5 changes: 2 additions & 3 deletions aten/src/ATen/SparseTensorImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <ATen/Tensor.h>
#include <c10/core/TensorImpl.h>
#include <c10/util/Exception.h>
#include <c10/util/irange.h>

namespace at {
struct TORCH_API SparseTensorImpl : public TensorImpl {
Expand Down Expand Up @@ -110,15 +109,15 @@ struct TORCH_API SparseTensorImpl : public TensorImpl {
bool shrinking_dense_dim = false;
auto sparse_size_original = sizes().slice(0, sparse_dim);
auto sparse_size_new = size.slice(0, sparse_dim);
for (const auto i : c10::irange(sparse_dim)) {
for (int64_t i = 0; i < sparse_dim; i++) {
if (sparse_size_new[i] < sparse_size_original[i]) {
shrinking_sparse_dims = true;
break;
}
}
auto dense_size_original = sizes().slice(sparse_dim);
auto dense_size_new = size.slice(sparse_dim);
for (const auto i : c10::irange(dense_dim)) {
for (int64_t i = 0; i < dense_dim; i++) {
if (dense_size_new[i] < dense_size_original[i]) {
shrinking_dense_dim = true;
break;
Expand Down
3 changes: 1 addition & 2 deletions aten/src/ATen/SparseTensorUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <ATen/ATen.h>
#include <ATen/SparseTensorImpl.h>
#include <ATen/Parallel.h>
#include <c10/util/irange.h>

namespace at { namespace sparse {

Expand Down Expand Up @@ -99,7 +98,7 @@ Tensor coo_to_csr(const int64_t* indices, int64_t dim, int64_t nnz) {
at::parallel_for(0, nnz, 10000, [&](int64_t start, int64_t end) {
// NOLINTNEXTLINE(cppcoreguidelines-init-variables)
int64_t h, hp0, hp1;
for (const auto i : c10::irange(start, end)) {
for (auto i = start; i < end; i++) {
hp0 = indices[i];
hp1 = (i+1 == nnz) ? dim : indices[i+1];
if (hp0 != hp1) {
Expand Down
3 changes: 1 addition & 2 deletions aten/src/ATen/TensorIndexing.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <ATen/TensorIndexing.h>

#include <c10/util/Exception.h>
#include <c10/util/irange.h>

namespace at {
namespace indexing {
Expand Down Expand Up @@ -32,7 +31,7 @@ std::ostream& operator<<(std::ostream& stream, const TensorIndex& tensor_index)

std::ostream& operator<<(std::ostream& stream, const std::vector<TensorIndex>& tensor_indices) {
stream << "(";
for (const auto i : c10::irange(tensor_indices.size())) {
for (size_t i = 0; i < tensor_indices.size(); i++) {
stream << tensor_indices[i];
if (i < tensor_indices.size() - 1) stream << ", ";
}
Expand Down
5 changes: 2 additions & 3 deletions aten/src/ATen/TensorIndexing.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <c10/util/Optional.h>
#include <c10/util/irange.h>
#include <ATen/core/TensorBody.h>
#include <ATen/ExpandUtils.h>
#include <ATen/Functions.h>
Expand Down Expand Up @@ -336,7 +335,7 @@ static inline Tensor scalarToTensor(const Scalar& v, const TensorOptions& option
// strip away unit dimensions from the left of 'src'
static inline IntArrayRef slicePrefix1sSize(const IntArrayRef& sizes) {
size_t first_non1_src = sizes.size();
for (const auto i : c10::irange(sizes.size())) {
for (size_t i = 0; i < sizes.size(); ++i) {
if (sizes[i] != 1) {
first_non1_src = i;
break;
Expand Down Expand Up @@ -440,7 +439,7 @@ static inline Tensor applySlicing(
"too many indices for tensor of dimension ", (int)self_sizes.size());

Tensor result = self;
for (const auto i : c10::irange(indices.size())) {
for (size_t i = 0; i < indices.size(); i++) {
auto& obj = indices[i];
result = handleDimInMultiDimIndexing(
/*prev_dim_result=*/result,
Expand Down
Loading

0 comments on commit 2f099c7

Please sign in to comment.