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

Function CheckGraph

tensorflow/core/grappler/mutable_graph_view_test.cc:88–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

86}
87
88void CheckGraph(const MutableGraphView& mutable_graph) {
89 GraphView immutable_graph(mutable_graph.graph());
90 EXPECT_EQ(mutable_graph.graph()->node_size(),
91 immutable_graph.graph()->node_size());
92 EXPECT_EQ(mutable_graph.graph(), immutable_graph.graph());
93
94 auto check_edges =
95 [](const absl::flat_hash_set<MutableGraphView::Edge>& mutable_edges,
96 const absl::flat_hash_set<GraphView::Edge>& immutable_edges) {
97 EXPECT_EQ(mutable_edges.size(), immutable_edges.size());
98 for (const auto& fanin_edge : mutable_edges) {
99 GraphView::Edge immutable_edge(
100 {fanin_edge.src.node, fanin_edge.src.port_id},
101 {fanin_edge.dst.node, fanin_edge.dst.port_id});
102 EXPECT_TRUE(immutable_edges.contains(immutable_edge));
103 }
104 };
105
106 // Check graph connectivity.
107 for (auto& node : *mutable_graph.graph()->mutable_node()) {
108 EXPECT_EQ(&node, immutable_graph.GetNode(node.name()));
109
110 auto mutable_fanins =
111 mutable_graph.GetFanins(node, /*include_controlling_nodes=*/true);
112 auto immutable_fanins =
113 immutable_graph.GetFanins(node, /*include_controlling_nodes=*/true);
114 EXPECT_EQ(mutable_fanins.size(), immutable_fanins.size());
115 for (const auto& fanin : mutable_fanins) {
116 GraphView::OutputPort immutable_fanin(fanin.node, fanin.port_id);
117 EXPECT_TRUE(immutable_fanins.contains(immutable_fanin));
118 }
119
120 auto mutable_fanouts =
121 mutable_graph.GetFanouts(node, /*include_controlled_nodes=*/true);
122 auto immutable_fanouts =
123 immutable_graph.GetFanouts(node, /*include_controlled_nodes=*/true);
124 EXPECT_EQ(mutable_fanouts.size(), immutable_fanouts.size());
125 for (const auto& fanout : mutable_fanouts) {
126 GraphView::InputPort immutable_fanout(fanout.node, fanout.port_id);
127 EXPECT_TRUE(immutable_fanouts.contains(immutable_fanout));
128 }
129
130 auto mutable_fanin_edges =
131 mutable_graph.GetFaninEdges(node, /*include_controlling_edges=*/true);
132 auto immutable_fanin_edges =
133 immutable_graph.GetFaninEdges(node, /*include_controlling_edges=*/true);
134 check_edges(mutable_fanin_edges, immutable_fanin_edges);
135
136 auto mutable_fanout_edges =
137 mutable_graph.GetFanoutEdges(node, /*include_controlled_edges=*/true);
138 auto immutable_fanout_edges =
139 immutable_graph.GetFanoutEdges(node, /*include_controlled_edges=*/true);
140 check_edges(mutable_fanout_edges, immutable_fanout_edges);
141 }
142}
143
144TEST(MutableGraphViewTest, AddSubgraph) {
145 GraphDef graph_def = test::function::GDef(

Callers 15

TESTFunction · 0.85
TestUpdateNodeNameFunction · 0.85
TestSwapNodeNamesFunction · 0.85
TestSwapNodeNamesErrorFunction · 0.85
TestAddRegularFaninFunction · 0.85
TestRemoveRegularFaninFunction · 0.85
TestRemoveAllFaninsFunction · 0.85
TestUpdateFaninFunction · 0.85

Calls 9

containsMethod · 0.80
GetFaninsMethod · 0.80
GetFanoutsMethod · 0.80
GetFaninEdgesMethod · 0.80
GetFanoutEdgesMethod · 0.80
nameMethod · 0.65
graphMethod · 0.45
sizeMethod · 0.45
GetNodeMethod · 0.45

Tested by

no test coverage detected