MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ShuffleArrayAttr

Function ShuffleArrayAttr

tensorflow/compiler/mlir/tensorflow/ir/tf_ops.cc:320–337  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

318// `inner_size` allows to shuffle array attributes created from rank 2 tensors
319// on outer dimension only.
320ArrayAttr 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.
340Type ShuffleRankedTensorType(Type type, ArrayRef<int64_t> permutation) {

Callers 2

FoldOperandsPermutationFunction · 0.85
UpdateDataFormatMethod · 0.85

Calls 5

getContextMethod · 0.80
getFunction · 0.50
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected