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

Function PermuteNodesInPlace

tensorflow/core/grappler/utils.cc:402–419  ·  view source on GitHub ↗

Every permutation is a product of one or more cycles. Iterate over the cycles in the permutation, and convert each of those into a product of transpositions (swaps): https://en.wikipedia.org/wiki/Cyclic_permutation

Source from the content-addressed store, hash-verified

400// in the permutation, and convert each of those into a product of
401// transpositions (swaps): https://en.wikipedia.org/wiki/Cyclic_permutation
402void PermuteNodesInPlace(GraphDef* graph, std::vector<int>* permutation,
403 bool invert_permutation) {
404 CHECK_EQ(graph->node_size(), permutation->size());
405 std::vector<int> inv_perm(permutation->size(), 0);
406 if (invert_permutation) {
407 for (size_t n = 0; n < permutation->size(); ++n) {
408 inv_perm[(*permutation)[n]] = n;
409 }
410 permutation->swap(inv_perm);
411 }
412 for (std::size_t n = 0; n + 1 < permutation->size(); ++n) {
413 while (n != (*permutation)[n]) {
414 std::size_t r = (*permutation)[n];
415 graph->mutable_node()->SwapElements(n, r);
416 std::swap((*permutation)[n], (*permutation)[r]);
417 }
418 }
419}
420
421void DedupControlInputs(NodeDef* node) {
422 std::unordered_set<string> inputs;

Callers 3

ReversedTopologicalSortFunction · 0.85
TopologicalSortFunction · 0.85
SortTopologicallyMethod · 0.85

Calls 2

sizeMethod · 0.45
swapMethod · 0.45

Tested by

no test coverage detected