55#include < algorithm>
66#include < cstdint>
77
8+ #include < c10/util/irange.h>
89#include < executorch/runtime/core/exec_aten/exec_aten.h>
910#include < executorch/runtime/core/exec_aten/util/dim_order_util.h>
1011#include < executorch/runtime/core/exec_aten/util/scalar_type_util.h>
@@ -78,7 +79,7 @@ inline bool check_strides(
7879 // a.strides == (1, 1, 2). We want to sort create a mapping to make the
7980 // sorted_stride as (2, 1, 1) while sorted_size == (3, 2, 1)
8081 std::vector<std::int32_t > sorted_idx (sizes.size ());
81- for (size_t i = 0 ; i < sizes.size (); i++ ) {
82+ for (const auto i : c10::irange ( sizes.size ()) ) {
8283 sorted_idx[i] = i;
8384 }
8485 std::sort (
@@ -98,7 +99,7 @@ inline bool check_strides(
9899 // Use the mapping to rearrange the sizes and strides
99100 std::vector<std::int32_t > sorted_sizes (sizes.size ());
100101 std::vector<std::int32_t > sorted_strides (sizes.size ());
101- for (size_t i = 0 ; i < sizes.size (); i++ ) {
102+ for (const auto i : c10::irange ( sizes.size ()) ) {
102103 sorted_sizes[i] = sizes[sorted_idx[i]] == 0 ? 1 : sizes[sorted_idx[i]];
103104 sorted_strides[i] = strides[sorted_idx[i]];
104105 }
@@ -132,7 +133,7 @@ inline bool check_dim_order(
132133 }
133134 size_t gauss_sum = 0 ;
134135 std::vector<int > count (dim_order.size (), 0 );
135- for (int i = 0 ; i < dim_order.size (); i++ ) {
136+ for (const auto i : c10::irange ( dim_order.size ()) ) {
136137 if (dim_order[i] < 0 || dim_order[i] >= sizes.size ()) {
137138 return false ;
138139 }
@@ -378,7 +379,7 @@ class TensorFactory {
378379 std::vector<executorch::aten::StridesType> contiguous_strides =
379380 internal::strides_from_dim_order (sizes, contiguous_dim_order);
380381
381- for (int32_t i = 0 ; i < input.dim (); i++ ) {
382+ for (const auto i : c10::irange ( input.dim ()) ) {
382383 ET_CHECK_MSG (
383384 input.strides ()[i] == contiguous_strides[i],
384385 " Input tensor is not contiguous" );
@@ -394,10 +395,10 @@ class TensorFactory {
394395 std::vector<ctype> channels_last_data (
395396 N * C * H * W); // Create a new blob with the same total size to contain
396397 // channels_last data
397- for (int32_t n = 0 ; n < N; ++n ) {
398- for (int32_t c = 0 ; c < C; ++c ) {
399- for (int32_t h = 0 ; h < H; ++h ) {
400- for (int32_t w = 0 ; w < W; ++w ) {
398+ for (const auto n : c10::irange (N) ) {
399+ for (const auto c : c10::irange (C) ) {
400+ for (const auto h : c10::irange (H) ) {
401+ for (const auto w : c10::irange (W) ) {
401402 // Calculate the index in the original blob
402403 int32_t old_index = ((n * C + c) * H + h) * W + w;
403404 // Calculate the index in the new blob
@@ -598,7 +599,7 @@ inline void validate_strides(
598599 }
599600 }
600601 // No two dimensions can have same stride value
601- for (int32_t i = 0 ; i < strides.size (); ++i ) {
602+ for (const auto i : c10::irange ( strides.size ()) ) {
602603 for (int32_t j = i + 1 ; j < strides.size (); ++j) {
603604 if ((sizes[i] == 0 ) || (sizes[j] == 0 ) ||
604605 ((sizes[i] == 1 ) || (sizes[j] == 1 ))) {
@@ -814,7 +815,7 @@ class TensorFactory {
814815 // given strides is empty.
815816 if (!sizes.empty () && dim_order.empty ()) {
816817 default_dim_order.resize (sizes.size (), 1 );
817- for (size_t i = 0 ; i < sizes.size (); ++i ) {
818+ for (const auto i : c10::irange ( sizes.size ()) ) {
818819 default_dim_order[i] = i;
819820 }
820821 }
@@ -888,10 +889,10 @@ class TensorFactory {
888889 std::vector<ctype> channels_last_data (
889890 N * C * H * W); // Create a new blob with the same total size to contain
890891 // channels_last data
891- for (int32_t n = 0 ; n < N; ++n ) {
892- for (int32_t c = 0 ; c < C; ++c ) {
893- for (int32_t h = 0 ; h < H; ++h ) {
894- for (int32_t w = 0 ; w < W; ++w ) {
892+ for (const auto n : c10::irange (N) ) {
893+ for (const auto c : c10::irange (C) ) {
894+ for (const auto h : c10::irange (H) ) {
895+ for (const auto w : c10::irange (W) ) {
895896 // Calculate the index in the original blob
896897 int32_t old_index = ((n * C + c) * H + h) * W + w;
897898 // Calculate the index in the new blob
0 commit comments