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

Function DescribeCycle

tensorflow/compiler/jit/xla_cluster_util.cc:46–82  ·  view source on GitHub ↗

Returns a string describing how an edge from src to dst would create a cycle.

Source from the content-addressed store, hash-verified

44// Returns a string describing how an edge from src to dst would
45// create a cycle.
46string DescribeCycle(const GraphCycles* cycles, const Graph& graph, int src,
47 int dst) {
48 int32 max_path_size = graph.num_node_ids() + 1;
49 std::vector<int32> path(max_path_size);
50 int32 path_size = cycles->FindPath(dst, src, max_path_size, path.data());
51 if (path_size == 0) {
52 return "";
53 }
54
55 auto node_name = [&graph](int node_id) {
56 if (!FastBoundsCheck(node_id, graph.num_node_ids())) {
57 return string("(null)");
58 }
59 auto* node = graph.FindNodeId(node_id);
60 if (node == nullptr) {
61 return string("(null)");
62 }
63 return node->name();
64 };
65
66 string description;
67 absl::StrAppend(&description, "Edge from ", node_name(src), " to ",
68 node_name(dst), " would create a cycle.\n");
69 path.resize(path_size);
70 for (int32 node_id : path) {
71 string ascii_art;
72 if (node_id == dst) {
73 ascii_art = "+-> ";
74 } else if (node_id != src) {
75 ascii_art = "| ";
76 } else {
77 ascii_art = "+-- ";
78 }
79 absl::StrAppend(&description, ascii_art, node_name(node_id), "\n");
80 }
81 return description;
82}
83
84bool AlwaysForwardsRefInput(const Node& node) { return node.IsIdentity(); }
85

Callers 1

Calls 8

FastBoundsCheckFunction · 0.85
FindPathMethod · 0.80
nameMethod · 0.65
StrAppendFunction · 0.50
num_node_idsMethod · 0.45
dataMethod · 0.45
FindNodeIdMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected