Converts inference-style shape to legacy tflite::Dims<4>.
| 300 | |
| 301 | // Converts inference-style shape to legacy tflite::Dims<4>. |
| 302 | inline tflite::Dims<4> ToRuntimeDims(const tflite::RuntimeShape& array_shape) { |
| 303 | tflite::Dims<4> result; |
| 304 | const int dimensions_count = array_shape.DimensionsCount(); |
| 305 | TFLITE_CHECK_LE(dimensions_count, 4); |
| 306 | int cum_prod = 1; |
| 307 | for (int i = 0; i < 4; i++) { |
| 308 | const int new_dim = |
| 309 | (i < dimensions_count) ? array_shape.Dims(dimensions_count - 1 - i) : 1; |
| 310 | result.sizes[i] = new_dim; |
| 311 | result.strides[i] = cum_prod; |
| 312 | cum_prod *= new_dim; |
| 313 | } |
| 314 | return result; |
| 315 | } |
| 316 | |
| 317 | // TODO(b/80418076): Move to legacy ops file, update invocations. |
| 318 | inline RuntimeShape DimsToShape(const tflite::Dims<4>& dims) { |
nothing calls this directly
no test coverage detected