| 310 | // the outer channel dimension (i.e. 1). |
| 311 | template <int NUM_SPATIAL_DIMS> |
| 312 | inline int32 GetTensorDimIndex(TensorFormat format, char dimension) { |
| 313 | if (format == FORMAT_NHWC || format == FORMAT_NHWC_VECT_W) { |
| 314 | // clang-format off |
| 315 | switch (dimension) { |
| 316 | case 'N': return 0; |
| 317 | case '0': return 1; |
| 318 | case '1': return 2; |
| 319 | case '2': return 3; |
| 320 | case 'H': return NUM_SPATIAL_DIMS - 1; |
| 321 | case 'W': return NUM_SPATIAL_DIMS; |
| 322 | case 'C': return NUM_SPATIAL_DIMS + 1; |
| 323 | default: |
| 324 | LOG(FATAL) << "Invalid dimension: " << dimension; |
| 325 | return -1; // Avoid compiler warning about missing return value |
| 326 | } |
| 327 | } else if (format == FORMAT_NCHW || format == FORMAT_NCHW_VECT_C) { |
| 328 | switch (dimension) { |
| 329 | case 'N': return 0; |
| 330 | case 'C': return 1; |
| 331 | case '0': return 2; |
| 332 | case '1': return 3; |
| 333 | case '2': return 4; |
| 334 | case 'H': return NUM_SPATIAL_DIMS; |
| 335 | case 'W': return NUM_SPATIAL_DIMS + 1; |
| 336 | default: |
| 337 | LOG(FATAL) << "Invalid dimension: " << dimension; |
| 338 | return -1; // Avoid compiler warning about missing return value |
| 339 | } |
| 340 | } else if (format == FORMAT_HWNC) { |
| 341 | switch (dimension) { |
| 342 | case '0': return 0; |
| 343 | case '1': return 1; |
| 344 | case '2': return 2; |
| 345 | case 'H': return NUM_SPATIAL_DIMS - 2; |
| 346 | case 'W': return NUM_SPATIAL_DIMS - 1; |
| 347 | case 'N': return NUM_SPATIAL_DIMS; |
| 348 | case 'C': return NUM_SPATIAL_DIMS + 1; |
| 349 | default: |
| 350 | LOG(FATAL) << "Invalid dimension: " << dimension; |
| 351 | return -1; // Avoid compiler warning about missing return value |
| 352 | } |
| 353 | } else if (format == FORMAT_HWCN) { |
| 354 | switch (dimension) { |
| 355 | case '0': return 0; |
| 356 | case '1': return 1; |
| 357 | case '2': return 2; |
| 358 | case 'H': return NUM_SPATIAL_DIMS - 2; |
| 359 | case 'W': return NUM_SPATIAL_DIMS - 1; |
| 360 | case 'C': return NUM_SPATIAL_DIMS; |
| 361 | case 'N': return NUM_SPATIAL_DIMS + 1; |
| 362 | default: |
| 363 | LOG(FATAL) << "Invalid dimension: " << dimension; |
| 364 | return -1; // Avoid compiler warning about missing return value |
| 365 | } |
| 366 | } else { |
| 367 | LOG(FATAL) << "Invalid format: " << static_cast<int>(format); |
| 368 | return -1; // Avoid compiler warning about missing return value |
| 369 | } |
no test coverage detected