| 21 | namespace convolution_utils { |
| 22 | |
| 23 | DimDesc ParseAndValidateDim(int ndim, const TensorLayout &layout) { |
| 24 | static constexpr int kMaxDim = 3; |
| 25 | if (layout.empty()) { |
| 26 | // assuming plain data with no channels |
| 27 | DALI_ENFORCE(ndim <= kMaxDim, |
| 28 | make_string("Input data with empty layout cannot have more than ", kMaxDim, |
| 29 | " dimensions, got input with ", ndim, " dimensions.")); |
| 30 | return {0, ndim, ndim}; |
| 31 | } |
| 32 | int axes_start = 0; |
| 33 | int axes_end = ndim; |
| 34 | while (axes_start < ndim && (layout[axes_start] == 'C' || layout[axes_start] == 'F')) { |
| 35 | axes_start++; |
| 36 | } |
| 37 | if (axes_end > 0 && layout[axes_end - 1] == 'C') { |
| 38 | axes_end--; |
| 39 | } |
| 40 | int axes_count = axes_end - axes_start; |
| 41 | DALI_ENFORCE(axes_count > 0, make_string("No spatial axes found in the layout: ", layout)); |
| 42 | DALI_ENFORCE( |
| 43 | std::all_of(layout.begin() + axes_start, layout.begin() + axes_end, |
| 44 | std::bind(std::not_equal_to<char>(), 'C', std::placeholders::_1)), |
| 45 | make_string("Only channel-first or channel-last layouts are supported, got: ", layout, ".")); |
| 46 | DALI_ENFORCE( |
| 47 | std::all_of(layout.begin() + axes_start, layout.begin() + axes_end, |
| 48 | std::bind(std::not_equal_to<char>(), 'F', std::placeholders::_1)), |
| 49 | make_string("For sequences, layout should begin with 'F' or 'C', got: ", layout, ".")); |
| 50 | DALI_ENFORCE( |
| 51 | axes_start <= 2, |
| 52 | make_string("Found more the one occurrence of 'F' or 'C' axes in layout: ", layout, ".")); |
| 53 | DALI_ENFORCE(axes_count <= kMaxDim, |
| 54 | make_string("Too many dimensions, found: ", axes_count, |
| 55 | " data axes, maximum supported is: ", kMaxDim, ".")); |
| 56 | return {axes_start, axes_count, ndim}; |
| 57 | } |
| 58 | |
| 59 | } // namespace convolution_utils |
| 60 | } // namespace dali |
no test coverage detected