Gets next index to iterate through a multidimensional array.
| 322 | |
| 323 | // Gets next index to iterate through a multidimensional array. |
| 324 | inline bool NextIndex(const int num_dims, const int* dims, int* current) { |
| 325 | if (num_dims == 0) { |
| 326 | return false; |
| 327 | } |
| 328 | TFLITE_DCHECK(dims != nullptr); |
| 329 | TFLITE_DCHECK(current != nullptr); |
| 330 | int carry = 1; |
| 331 | for (int idx = num_dims - 1; idx >= 0; --idx) { |
| 332 | int current_val = current[idx] + carry; |
| 333 | TFLITE_DCHECK_GE(dims[idx], current_val); |
| 334 | if (dims[idx] == current_val) { |
| 335 | current[idx] = 0; |
| 336 | } else { |
| 337 | current[idx] = current_val; |
| 338 | carry = 0; |
| 339 | break; |
| 340 | } |
| 341 | } |
| 342 | return (carry == 0); |
| 343 | } |
| 344 | |
| 345 | // Gets offset of index if reducing on axis. When reducing, the flattened offset |
| 346 | // will not change, if the input index changes on the given axis. For example, |
no outgoing calls
no test coverage detected