Find broadcasted dimensions. This will store a map from the next axis to the indices of the previous dimensions that are being broadcasted.
| 1271 | // Find broadcasted dimensions. This will store a map from the next axis |
| 1272 | // to the indices of the previous dimensions that are being broadcasted. |
| 1273 | static std::map<std::size_t, std::deque<std::size_t>> |
| 1274 | find_broadcasted_dims(const std::vector<dimension>& dimensions, std::size_t rank) |
| 1275 | { |
| 1276 | std::map<std::size_t, std::deque<std::size_t>> broadcast_dims_map; |
| 1277 | group_find( |
| 1278 | dimensions.begin(), dimensions.end(), &missing_leading_axis, [&](auto start, auto last) { |
| 1279 | auto axis = rank; |
| 1280 | if(last != dimensions.end()) |
| 1281 | { |
| 1282 | assert(not last->subdimensions.empty()); |
| 1283 | const auto& sub = last->subdimensions.front(); |
| 1284 | assert(not sub.origin_axis().empty()); |
| 1285 | axis = sub.origin_axis().front(); |
| 1286 | } |
| 1287 | std::deque<std::size_t> dims(std::distance(start, last)); |
| 1288 | std::iota(dims.begin(), dims.end(), std::distance(dimensions.begin(), start)); |
| 1289 | broadcast_dims_map[axis] = dims; |
| 1290 | }); |
| 1291 | return broadcast_dims_map; |
| 1292 | } |
| 1293 | |
| 1294 | void shape_transform_descriptor::simplify() |
| 1295 | { |