| 99 | } |
| 100 | |
| 101 | void AxisArgs::Process(int ndim, SmallVector<int, 6> &axes) { |
| 102 | if (axes.empty()) { |
| 103 | if (!(flags_ & AllowEmpty)) |
| 104 | DALI_FAIL("Need to specify at least one axis"); |
| 105 | if (flags_ & AllIfEmpty) { |
| 106 | axes.resize(ndim); |
| 107 | std::iota(axes.begin(), axes.end(), 0); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | if (flags_ & AllowNegative) { |
| 112 | for (auto &axis : axes) { |
| 113 | DALI_ENFORCE(axis >= -ndim && axis < ndim, |
| 114 | make_string("Axis ", axis, " out of range. Expected range is [", -ndim, ", ", |
| 115 | ndim - 1, "] for a ", ndim, "D input")); |
| 116 | if (axis < 0) |
| 117 | axis += ndim; |
| 118 | } |
| 119 | } else { |
| 120 | for (auto &axis : axes) { |
| 121 | DALI_ENFORCE(axis >= 0 && axis < ndim, |
| 122 | make_string("Axis ", axis, " out of range. Expected range is [0, ", ndim - 1, |
| 123 | "] for a ", ndim, "D input")); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | if (!(flags_ & AllowEmpty) && axes.empty()) |
| 128 | DALI_FAIL("Need to specify at least one axis"); |
| 129 | |
| 130 | |
| 131 | SmallVector<bool, 6> axes_check; |
| 132 | for (auto axis : axes) { |
| 133 | if (axes_check[axis]) |
| 134 | DALI_FAIL(make_string("Axis index ", axis, |
| 135 | " occurs more than once in ``axes`` " |
| 136 | "(might include negative indices referring to the same axis")); |
| 137 | axes_check[axis] = true; |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | } // namespace dali |