function to traverse a const strided tensor object it requires an additional vector, traversal_info {0,0,0,0 ...}, comprising (x.shape().size()+2) elements of 0 for e.g. 2d matrix: index 0 and 1 store the base row and column index respectively index 2 stores the current index of the traversal index 3 stores the order of the traversal for e.g. if the order is 0, it means the next element can be nav
| 114 | // index 3 stores the order of the traversal for e.g. if the order is 0, |
| 115 | // it means the next element can be navigated to using the innermost stride |
| 116 | void traverse_next(const Tensor &x, vector<int> &shape_multipliers, |
| 117 | vector<int> &traversal_info, int counter) { |
| 118 | update_base_index(x, traversal_info); |
| 119 | traversal_info[x.shape().size() + 1] = |
| 120 | determine_order(shape_multipliers, counter); |
| 121 | traversal_info[x.shape().size()] = |
| 122 | traversal_info[traversal_info[x.shape().size() + 1]] + |
| 123 | x.stride()[x.stride().size() - traversal_info[x.shape().size() + 1] - 1]; |
| 124 | }; |
| 125 | |
| 126 | inline int next_offset(int offset, const vector<size_t> &shape, |
| 127 | const vector<int> &stride, vector<int> *index) { |
no test coverage detected