diff --git a/runtime/core/exec_aten/testing_util/targets.bzl b/runtime/core/exec_aten/testing_util/targets.bzl index ed130c8706c..6198a09c2cb 100644 --- a/runtime/core/exec_aten/testing_util/targets.bzl +++ b/runtime/core/exec_aten/testing_util/targets.bzl @@ -44,6 +44,7 @@ def define_common_targets(): "//executorch/runtime/core/exec_aten/util:scalar_type_util" + aten_suffix, "//executorch/runtime/core/exec_aten/util:tensor_util" + aten_suffix, "//executorch/runtime/core/exec_aten/util:tensor_dimension_limit", + "//executorch/runtime/core/portable_type/c10/c10:c10", ], exported_external_deps = [ "gmock" + aten_suffix, diff --git a/runtime/core/exec_aten/testing_util/tensor_factory.h b/runtime/core/exec_aten/testing_util/tensor_factory.h index 1e29b220251..1cad4ec2a7c 100644 --- a/runtime/core/exec_aten/testing_util/tensor_factory.h +++ b/runtime/core/exec_aten/testing_util/tensor_factory.h @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -78,7 +79,7 @@ inline bool check_strides( // a.strides == (1, 1, 2). We want to sort create a mapping to make the // sorted_stride as (2, 1, 1) while sorted_size == (3, 2, 1) std::vector sorted_idx(sizes.size()); - for (size_t i = 0; i < sizes.size(); i++) { + for (const auto i : c10::irange(sizes.size())) { sorted_idx[i] = i; } std::sort( @@ -98,7 +99,7 @@ inline bool check_strides( // Use the mapping to rearrange the sizes and strides std::vector sorted_sizes(sizes.size()); std::vector sorted_strides(sizes.size()); - for (size_t i = 0; i < sizes.size(); i++) { + for (const auto i : c10::irange(sizes.size())) { sorted_sizes[i] = sizes[sorted_idx[i]] == 0 ? 1 : sizes[sorted_idx[i]]; sorted_strides[i] = strides[sorted_idx[i]]; } @@ -132,7 +133,7 @@ inline bool check_dim_order( } size_t gauss_sum = 0; std::vector count(dim_order.size(), 0); - for (int i = 0; i < dim_order.size(); i++) { + for (const auto i : c10::irange(dim_order.size())) { if (dim_order[i] >= sizes.size()) { return false; } @@ -378,7 +379,7 @@ class TensorFactory { std::vector contiguous_strides = internal::strides_from_dim_order(sizes, contiguous_dim_order); - for (int32_t i = 0; i < input.dim(); i++) { + for (const auto i : c10::irange(input.dim())) { ET_CHECK_MSG( input.strides()[i] == contiguous_strides[i], "Input tensor is not contiguous"); @@ -394,10 +395,10 @@ class TensorFactory { std::vector channels_last_data( N * C * H * W); // Create a new blob with the same total size to contain // channels_last data - for (int32_t n = 0; n < N; ++n) { - for (int32_t c = 0; c < C; ++c) { - for (int32_t h = 0; h < H; ++h) { - for (int32_t w = 0; w < W; ++w) { + for (const auto n : c10::irange(N)) { + for (const auto c : c10::irange(C)) { + for (const auto h : c10::irange(H)) { + for (const auto w : c10::irange(W)) { // Calculate the index in the original blob int32_t old_index = ((n * C + c) * H + h) * W + w; // Calculate the index in the new blob @@ -614,7 +615,7 @@ inline void validate_strides( } } // No two dimensions can have same stride value - for (int32_t i = 0; i < strides.size(); ++i) { + for (const auto i : c10::irange(strides.size())) { for (int32_t j = i + 1; j < strides.size(); ++j) { if ((sizes[i] == 0) || (sizes[j] == 0) || ((sizes[i] == 1) || (sizes[j] == 1))) { @@ -830,7 +831,7 @@ class TensorFactory { // given strides is empty. if (!sizes.empty() && dim_order.empty()) { default_dim_order.resize(sizes.size(), 1); - for (size_t i = 0; i < sizes.size(); ++i) { + for (const auto i : c10::irange(sizes.size())) { default_dim_order[i] = i; } } @@ -904,10 +905,10 @@ class TensorFactory { std::vector channels_last_data( N * C * H * W); // Create a new blob with the same total size to contain // channels_last data - for (int32_t n = 0; n < N; ++n) { - for (int32_t c = 0; c < C; ++c) { - for (int32_t h = 0; h < H; ++h) { - for (int32_t w = 0; w < W; ++w) { + for (const auto n : c10::irange(N)) { + for (const auto c : c10::irange(C)) { + for (const auto h : c10::irange(H)) { + for (const auto w : c10::irange(W)) { // Calculate the index in the original blob int32_t old_index = ((n * C + c) * H + h) * W + w; // Calculate the index in the new blob diff --git a/runtime/core/exec_aten/testing_util/tensor_util.cpp b/runtime/core/exec_aten/testing_util/tensor_util.cpp index 56d7382aab2..35ddbe8ac15 100644 --- a/runtime/core/exec_aten/testing_util/tensor_util.cpp +++ b/runtime/core/exec_aten/testing_util/tensor_util.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -50,7 +51,7 @@ bool data_is_close( if (a == b) { return true; } - for (size_t i = 0; i < numel; i++) { + for (const auto i : c10::irange(numel)) { const auto ai = a[i]; const auto bi = b[i]; @@ -201,7 +202,7 @@ bool tensor_lists_are_close( if (num_tensors_a != num_tensors_b) { return false; } - for (size_t i = 0; i < num_tensors_a; i++) { + for (const auto i : c10::irange(num_tensors_a)) { if (!tensors_are_close(tensors_a[i], tensors_b[i], rtol, opt_atol)) { return false; } @@ -245,7 +246,7 @@ template std::ostream& print_data(std::ostream& os, const T* data, size_t numel) { // TODO(dbort): Make this smarter: show dimensions, listen to strides, // break up or truncate data when it's huge - for (auto i = 0; i < numel; i++) { + for (const auto i : c10::irange(numel)) { os << data[i]; if (i < numel - 1) { os << ", "; @@ -257,7 +258,7 @@ std::ostream& print_data(std::ostream& os, const T* data, size_t numel) { template std::ostream& print_data(std::ostream& os, const etensor::complex* data, size_t numel) { - for (auto i = 0; i < numel; i++) { + for (const auto i : c10::irange(numel)) { os << data[i].real_ << " + " << data[i].imag_ << "j"; if (i < numel - 1) { os << ", "; @@ -276,7 +277,7 @@ template <> std::ostream& print_data(std::ostream& os, const uint8_t* data, size_t numel) { // TODO(dbort): Make this smarter: show dimensions, listen to strides, // break up or truncate data when it's huge - for (auto i = 0; i < numel; i++) { + for (const auto i : c10::irange(numel)) { os << (uint64_t)data[i]; if (i < numel - 1) { os << ", "; @@ -292,7 +293,7 @@ std::ostream& print_data(std::ostream& os, const uint8_t* data, size_t numel) { */ std::ostream& operator<<(std::ostream& os, const Tensor& t) { os << "ETensor(sizes={"; - for (auto dim = 0; dim < t.dim(); dim++) { + for (const auto dim : c10::irange(t.dim())) { os << t.size(dim); if (dim < t.dim() - 1) { os << ", "; diff --git a/runtime/core/exec_aten/testing_util/test/targets.bzl b/runtime/core/exec_aten/testing_util/test/targets.bzl index a37d08ecb22..44796994ba3 100644 --- a/runtime/core/exec_aten/testing_util/test/targets.bzl +++ b/runtime/core/exec_aten/testing_util/test/targets.bzl @@ -25,5 +25,6 @@ def define_common_targets(): preprocessor_flags = preprocessor_flags, deps = [ "//executorch/runtime/core/exec_aten/testing_util:tensor_util" + aten_suffix, + "//executorch/runtime/core/portable_type/c10/c10:c10", ], ) diff --git a/runtime/core/exec_aten/testing_util/test/tensor_factory_test.cpp b/runtime/core/exec_aten/testing_util/test/tensor_factory_test.cpp index feb00f79b8f..ab201a0d784 100644 --- a/runtime/core/exec_aten/testing_util/test/tensor_factory_test.cpp +++ b/runtime/core/exec_aten/testing_util/test/tensor_factory_test.cpp @@ -6,6 +6,7 @@ * LICENSE file in the root directory of this source tree. */ +#include #include #include #include @@ -86,7 +87,7 @@ using torch::executor::TensorImpl; "Arrays are not equal size." #a1 " size:%zu," #a2 " size:%zu", \ a1.size(), \ a2.size()); \ - for (size_t i = 0; i < a1.size(); ++i) { \ + for (const auto i : c10::irange(a1.size())) { \ ET_CHECK_MSG( \ a1[i] == a2[i], \ "Value mismatch at index %zu, " #a1 \ @@ -784,7 +785,7 @@ void run_zeros_like_test(Tensor input) { // A Tensor created manually, that should be identical to `actual`. std::vector expected_data; - for (int i = 0; i < input.numel(); i++) { + for (const auto i : c10::irange(input.numel())) { expected_data.push_back(0); } #ifdef USE_ATEN_LIB @@ -842,7 +843,7 @@ void run_ones_like_test(Tensor input) { // A Tensor created manually, that should be identical to `actual`. std::vector expected_data; - for (int i = 0; i < input.numel(); i++) { + for (const auto i : c10::irange(input.numel())) { expected_data.push_back(1); } #ifdef USE_ATEN_LIB diff --git a/runtime/core/exec_aten/util/dim_order_util.h b/runtime/core/exec_aten/util/dim_order_util.h index 07b3d5c2a97..d01b2079ab2 100644 --- a/runtime/core/exec_aten/util/dim_order_util.h +++ b/runtime/core/exec_aten/util/dim_order_util.h @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -23,7 +24,7 @@ namespace runtime { namespace { template bool validate_dim_order(const DimOrderType* dim_order, const size_t dims) { - for (size_t i = 0; i < dims; ++i) { + for (const auto i : c10::irange(dims)) { if (dim_order[i] >= static_cast(dims)) { return false; } @@ -43,7 +44,7 @@ template inline bool is_contiguous_dim_order( const DimOrderType* dim_order, const size_t dims) { - for (size_t i = 0; i < dims; ++i) { + for (const auto i : c10::irange(dims)) { if (dim_order[i] != static_cast(i)) { return false; } diff --git a/runtime/core/exec_aten/util/targets.bzl b/runtime/core/exec_aten/util/targets.bzl index ac46da052ca..9ec2310250c 100644 --- a/runtime/core/exec_aten/util/targets.bzl +++ b/runtime/core/exec_aten/util/targets.bzl @@ -40,6 +40,7 @@ def define_common_targets(): ], exported_deps = [ "//executorch/runtime/core:core", + "//executorch/runtime/core/portable_type/c10/c10:c10", ], visibility = [ "//executorch/...", @@ -62,6 +63,7 @@ def define_common_targets(): exported_deps = [ ":tensor_dimension_limit", "//executorch/runtime/core:core", + "//executorch/runtime/core/portable_type/c10/c10:c10", ] + [ "//executorch/runtime/core/exec_aten:lib" + aten_suffix, ":scalar_type_util" + aten_suffix, diff --git a/runtime/core/exec_aten/util/tensor_util.h b/runtime/core/exec_aten/util/tensor_util.h index b0b79882361..67a813f8d34 100644 --- a/runtime/core/exec_aten/util/tensor_util.h +++ b/runtime/core/exec_aten/util/tensor_util.h @@ -17,6 +17,7 @@ #include +#include #include #include #include @@ -277,7 +278,7 @@ a_strides = a__.strides(); \ const ::executorch::aten::ArrayRef \ b_strides = b__.strides(); \ - for (size_t i = 0; i < a__.dim(); i++) { \ + for (const auto i : c10::irange(a__.dim())) { \ ET_CHECK_MSG( \ a_strides[i] == b_strides[i], \ "a.strides()[%zu] shall equal to b.strides()[%zu], " \ @@ -309,7 +310,7 @@ b_strides = b__.strides(); \ const ::executorch::aten::ArrayRef \ c_strides = c__.strides(); \ - for (size_t i = 0; i < a__.dim(); i++) { \ + for (const auto i : c10::irange(a__.dim())) { \ ET_CHECK_MSG( \ a_strides[i] == b_strides[i] && b_strides[i] == c_strides[i], \ "a_strides[%zu], b_strides[%zu] and c_strides[%zu] " \ @@ -967,7 +968,7 @@ inline size_t coordinateToIndex( const executorch::aten::Tensor& tensor, const size_t* const coordinate) { size_t index = 0; - for (int d = 0; d < tensor.dim(); ++d) { + for (const auto d : c10::irange(tensor.dim())) { index += coordinate[d] * getTrailingDims(tensor, d); } return index; @@ -999,7 +1000,7 @@ inline size_t coordinateToIndexWithTrailingDimsMemo( const size_t* const coordinate, const size_t trailing_dims_memo[kTensorDimensionLimit]) { size_t index = 0; - for (int d = 0; d < tensor.dim(); ++d) { + for (const auto d : c10::irange(tensor.dim())) { index += coordinate[d] * trailing_dims_memo[d]; } return index; @@ -1021,7 +1022,7 @@ inline void indexToCoordinate( size_t index, size_t* coordinate) { ET_CHECK(index < static_cast(tensor.numel())); - for (auto i = 0; i < tensor.dim(); ++i) { + for (const auto i : c10::irange(tensor.dim())) { auto dim = tensor.dim() - 1 - i; size_t dim_size = tensor.size(dim); coordinate[dim] = index % dim_size; @@ -1211,7 +1212,7 @@ ET_NODISCARD inline Error resize_tensor( std::array new_sizes_casted{}; size_t new_sizes_ndim = new_sizes.size(); - for (size_t i = 0; i < new_sizes_ndim; ++i) { + for (const auto i : c10::irange(new_sizes_ndim)) { new_sizes_casted[i] = static_cast(new_sizes[i]); } @@ -1342,7 +1343,7 @@ inline size_t calculate_linear_index( const executorch::aten::StridesType* strides, const size_t ndim) { size_t index = 0; - for (size_t i = 0; i < ndim; i++) { + for (const auto i : c10::irange(ndim)) { index += coordinate[i] * strides[i]; } return index; diff --git a/runtime/core/exec_aten/util/tensor_util_aten.cpp b/runtime/core/exec_aten/util/tensor_util_aten.cpp index ddfd0560a69..b8d8e266016 100644 --- a/runtime/core/exec_aten/util/tensor_util_aten.cpp +++ b/runtime/core/exec_aten/util/tensor_util_aten.cpp @@ -9,6 +9,7 @@ #include #include // @manual +#include #include namespace executorch { @@ -41,7 +42,7 @@ bool tensor_has_valid_dim_order(at::Tensor t) { if (!validate_dim_order(dim_order, t.dim())) { ET_LOG(Error, "Tensor dim order is not valid:"); - for (size_t d = 0; d < t.dim(); ++d) { + for (const auto d : c10::irange(t.dim())) { ET_LOG( Error, " dim_order(%zu): %zu", @@ -66,7 +67,7 @@ inline bool tensor_is_default_or_channels_last_dim_order(at::Tensor t) { ET_LOG( Error, "Expected tensor to have default or channels last dim order, but got"); - for (size_t d = 0; d < t.dim(); ++d) { + for (const auto d : c10::irange(t.dim())) { ET_LOG( Error, " dim_order(%zu): %zu", @@ -96,7 +97,7 @@ bool tensors_have_same_dim_order( bool all_channels_last = is_channels_last_dim_order(first_dim_order, tensor_list[0].dim()); - for (size_t i = 1; i < tensor_list.size(); ++i) { + for (const auto i : c10::irange(1, tensor_list.size())) { ET_CHECK_OR_RETURN_FALSE( get_dim_order(tensor_list[i], other_dim_order, tensor_list[i].dim()) == Error::Ok, diff --git a/runtime/core/exec_aten/util/tensor_util_portable.cpp b/runtime/core/exec_aten/util/tensor_util_portable.cpp index e4aa875aed4..f30dd7f3a2a 100644 --- a/runtime/core/exec_aten/util/tensor_util_portable.cpp +++ b/runtime/core/exec_aten/util/tensor_util_portable.cpp @@ -6,6 +6,7 @@ * LICENSE file in the root directory of this source tree. */ +#include #include #include @@ -42,7 +43,7 @@ Error get_dim_order( bool tensor_has_valid_dim_order(torch::executor::Tensor t) { if (!validate_dim_order(t.dim_order().data(), t.dim_order().size())) { ET_LOG(Error, "Tensor dim order is not valid:"); - for (size_t d = 0; d < static_cast(t.dim()); ++d) { + for ([[maybe_unused]] const auto d : c10::irange(t.dim())) { ET_LOG( Error, " dim_order(%zu): %zu", @@ -63,7 +64,7 @@ bool tensor_is_default_or_channels_last_dim_order(torch::executor::Tensor t) { ET_LOG( Error, "Expected tensor to have default or channels last dim order, but got"); - for (size_t d = 0; d < static_cast(t.dim()); ++d) { + for ([[maybe_unused]] const auto d : c10::irange(t.dim())) { ET_LOG( Error, " dim_order(%zu): %zu", @@ -80,7 +81,7 @@ bool tensor_is_default_dim_order(torch::executor::Tensor t) { if (!ret_val) { ET_LOG(Error, "Expected tensor to have default dim order, but got"); - for (size_t d = 0; d < static_cast(t.dim()); ++d) { + for ([[maybe_unused]] const auto d : c10::irange(t.dim())) { ET_LOG( Error, " dim_order(%zu): %zu", @@ -97,7 +98,7 @@ bool tensor_is_channels_last_dim_order(torch::executor::Tensor t) { if (!ret_val) { ET_LOG(Error, "Expected tensor to have channels last dim order, but got"); - for (size_t d = 0; d < static_cast(t.dim()); ++d) { + for ([[maybe_unused]] const auto d : c10::irange(t.dim())) { ET_LOG( Error, " dim_order(%zu): %zu", @@ -115,7 +116,7 @@ bool tensors_have_same_dim_order( } bool all_contiguous = true; bool all_channels_last = true; - for (size_t i = 0; i < tensor_list.size(); ++i) { + for (const auto i : c10::irange(tensor_list.size())) { all_contiguous = all_contiguous && is_contiguous_dim_order( tensor_list[i].dim_order().data(), diff --git a/runtime/core/exec_aten/util/test/dim_order_util_test.cpp b/runtime/core/exec_aten/util/test/dim_order_util_test.cpp index 12897738333..fe3c1f6d82a 100644 --- a/runtime/core/exec_aten/util/test/dim_order_util_test.cpp +++ b/runtime/core/exec_aten/util/test/dim_order_util_test.cpp @@ -6,6 +6,7 @@ * LICENSE file in the root directory of this source tree. */ +#include #include #include @@ -24,7 +25,7 @@ namespace { void check_strides_eq( executorch::aten::ArrayRef strides_a, executorch::aten::ArrayRef strides_b) { - for (int32_t i = 0; i < strides_a.size(); ++i) { + for (const auto i : c10::irange(strides_a.size())) { EXPECT_EQ(strides_a[i], strides_b[i]); } } @@ -32,7 +33,7 @@ void check_strides_eq( void check_dim_order_eq( executorch::aten::ArrayRef dim_order_a, executorch::aten::ArrayRef dim_order_b) { - for (int32_t i = 0; i < dim_order_a.size(); ++i) { + for (const auto i : c10::irange(dim_order_a.size())) { EXPECT_EQ(dim_order_a[i], dim_order_b[i]); } } @@ -227,7 +228,7 @@ TEST(DimOrderUtilTest, StrideToDimOrderSameStrides) { } TEST(DimOrderUtilTest, IsDefaultDimOrderTest) { - for (int i = 1; i < 7; ++i) { + for (const auto i : c10::irange(1, 7)) { std::vector dim_order(i); std::iota(dim_order.begin(), dim_order.end(), 0); @@ -241,7 +242,7 @@ TEST(DimOrderUtilTest, IsDefaultDimOrderTest) { TEST(DimOrderUtilTest, IsDefaultDimOrderFailCasesTest) { // Dims is default order but have two elements swapped - for (int i = 3; i < 8; ++i) { + for (const auto i : c10::irange(3, 8)) { std::vector dim_order(i); std::iota(dim_order.begin(), dim_order.end(), 0); std::swap(dim_order[0], dim_order[1]); @@ -250,9 +251,9 @@ TEST(DimOrderUtilTest, IsDefaultDimOrderFailCasesTest) { } // Dims is default order but shifted by 1 - for (int i = 3; i < 8; ++i) { + for (const auto i : c10::irange(3, 8)) { std::vector dim_order(i); - for (int d = 0; d < i; ++d) { + for (const auto d : c10::irange(i)) { dim_order[d] = (d + 1) % i; } diff --git a/runtime/core/exec_aten/util/test/operator_impl_example_test.cpp b/runtime/core/exec_aten/util/test/operator_impl_example_test.cpp index 7975720b575..d9d285c4f0f 100644 --- a/runtime/core/exec_aten/util/test/operator_impl_example_test.cpp +++ b/runtime/core/exec_aten/util/test/operator_impl_example_test.cpp @@ -13,6 +13,7 @@ * this package. */ +#include #include #include #include @@ -44,7 +45,7 @@ void add_tensors_impl(const Tensor& a, const Tensor& b, Tensor& out) { const auto data_a = a.const_data_ptr(); const auto data_b = b.const_data_ptr(); auto data_out = out.mutable_data_ptr(); - for (size_t i = 0; i < n; ++i) { + for (const auto i : c10::irange(n)) { data_out[i] = data_a[i] + data_b[i]; } } diff --git a/runtime/core/exec_aten/util/test/targets.bzl b/runtime/core/exec_aten/util/test/targets.bzl index 1fcf984e034..25077550e6c 100644 --- a/runtime/core/exec_aten/util/test/targets.bzl +++ b/runtime/core/exec_aten/util/test/targets.bzl @@ -23,6 +23,7 @@ def define_common_targets(): "//executorch/runtime/core/exec_aten/testing_util:tensor_util", "//executorch/runtime/core/exec_aten/util:scalar_type_util", "//executorch/runtime/core/exec_aten/util:tensor_util", + "//executorch/runtime/core/portable_type/c10/c10:c10", ], ) @@ -32,6 +33,7 @@ def define_common_targets(): deps = [ "//executorch/runtime/core/exec_aten/testing_util:tensor_util", "//executorch/runtime/core/exec_aten/util:tensor_util", + "//executorch/runtime/core/portable_type/c10/c10:c10", ], ) @@ -44,6 +46,7 @@ def define_common_targets(): "//executorch/runtime/core/exec_aten/testing_util:tensor_util", "//executorch/runtime/core/exec_aten/util:scalar_type_util", "//executorch/runtime/core/exec_aten/util:tensor_util" + aten_suffix, + "//executorch/runtime/core/portable_type/c10/c10:c10", ], ) diff --git a/runtime/core/exec_aten/util/test/tensor_util_test.cpp b/runtime/core/exec_aten/util/test/tensor_util_test.cpp index cdc391adf20..842f2341235 100644 --- a/runtime/core/exec_aten/util/test/tensor_util_test.cpp +++ b/runtime/core/exec_aten/util/test/tensor_util_test.cpp @@ -6,6 +6,7 @@ * LICENSE file in the root directory of this source tree. */ +#include #include #include #include @@ -228,8 +229,8 @@ TEST_F(TensorUtilTest, CheckSameContiguousStrideSupported) { // Any two tensors in `same_stride_tensor_list` have same strides. The two // could contain duplicate tensors. - for (int i = 0; i < same_stride_tensor_list.size(); i++) { - for (int j = i; j < same_stride_tensor_list.size(); j++) { + for (const auto i : c10::irange(same_stride_tensor_list.size())) { + for (const auto j : c10::irange(i, same_stride_tensor_list.size())) { auto ti = same_stride_tensor_list[i]; auto tj = same_stride_tensor_list[j]; ET_CHECK_SAME_STRIDES2(ti, tj); @@ -238,16 +239,16 @@ TEST_F(TensorUtilTest, CheckSameContiguousStrideSupported) { // Any tensor in `same_stride_tensor_list` shall not have same stride with // `different_stride`. - for (int i = 0; i < same_stride_tensor_list.size(); i++) { + for (const auto i : c10::irange(same_stride_tensor_list.size())) { auto ti = same_stride_tensor_list[i]; ET_EXPECT_DEATH(ET_CHECK_SAME_STRIDES2(ti, different_stride), ""); } // Any three tensors in same_stride_tensor_list have same strides. The three // could contain duplicate tensors. - for (size_t i = 0; i < same_stride_tensor_list.size(); i++) { - for (size_t j = i; j < same_stride_tensor_list.size(); j++) { - for (size_t k = j; k < same_stride_tensor_list.size(); k++) { + for (const auto i : c10::irange(same_stride_tensor_list.size())) { + for (const auto j : c10::irange(i, same_stride_tensor_list.size())) { + for (const auto k : c10::irange(j, same_stride_tensor_list.size())) { auto ti = same_stride_tensor_list[i]; auto tj = same_stride_tensor_list[j]; auto tk = same_stride_tensor_list[k]; @@ -258,8 +259,8 @@ TEST_F(TensorUtilTest, CheckSameContiguousStrideSupported) { // Any two tensors in same_stride_tensor_list shall not have same strides with // `different_stride`. The two could contain duplicate tensors. - for (int i = 0; i < same_stride_tensor_list.size(); i++) { - for (int j = i; j < same_stride_tensor_list.size(); j++) { + for (const auto i : c10::irange(same_stride_tensor_list.size())) { + for (const auto j : c10::irange(i, same_stride_tensor_list.size())) { auto ti = same_stride_tensor_list[i]; auto tj = same_stride_tensor_list[j]; ET_EXPECT_DEATH(ET_CHECK_SAME_STRIDES3(ti, tj, different_stride), "");