this function checks whether the next index falls on a special multiplier of the outer shape so the algorithm knows when to jump over/back to a starting element of the outer shape for e.g. in [[1,4,7], [2,5,8], [3,6,9]], elements 1,2,3 are the starting elements of their respective rows this additional check only has 1 loop for 2d matrix but runtime performance might degrade to O(nlog(n)) for highe
| 88 | // but runtime performance might degrade to O(nlog(n)) for higher dimensional |
| 89 | // tensors |
| 90 | int determine_order(vector<int> &shape_multipliers, int counter) { |
| 91 | for (size_t n = 0; n < (shape_multipliers.size() - 1); ++n) { |
| 92 | if ((counter % shape_multipliers[n]) == 0) { |
| 93 | return ((shape_multipliers.size()) - 1 - n); |
| 94 | } |
| 95 | } |
| 96 | return 0; |
| 97 | }; |
| 98 | |
| 99 | // this function updates the base indexes with the current index after every |
| 100 | // single traversal step, |