Shuffle elements in the `attr` according to the permutation. Optional `inner_size` allows to shuffle array attributes created from rank 2 tensors on outer dimension only.
| 318 | // `inner_size` allows to shuffle array attributes created from rank 2 tensors |
| 319 | // on outer dimension only. |
| 320 | ArrayAttr ShuffleArrayAttr(ArrayAttr attr, ArrayRef<int64_t> permutation, |
| 321 | int inner_size = 1) { |
| 322 | if (attr.size() == 0) return attr; |
| 323 | |
| 324 | assert(attr.size() % inner_size == 0); |
| 325 | assert(attr.size() / inner_size == permutation.size()); |
| 326 | |
| 327 | SmallVector<Attribute, 8> values{attr.begin(), attr.end()}; |
| 328 | SmallVector<Attribute, 8> shuffled(values.size()); |
| 329 | |
| 330 | for (size_t i = 0; i < permutation.size(); ++i) { |
| 331 | for (size_t j = 0; j < inner_size; ++j) { |
| 332 | shuffled[i * inner_size + j] = values[permutation[i] * inner_size + j]; |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | return ArrayAttr::get(shuffled, attr.getContext()); |
| 337 | } |
| 338 | |
| 339 | // Shuffle ranked tensor dimensions according to the permutation. |
| 340 | Type ShuffleRankedTensorType(Type type, ArrayRef<int64_t> permutation) { |
no test coverage detected