| 261 | } |
| 262 | |
| 263 | std::unordered_set<const Node*> FindExcludeDuplicationNodes(Graph* g, |
| 264 | std::unordered_set<const Node*>& visited) { |
| 265 | // Compute set of nodes that we need to traverse in order to reach |
| 266 | // the nodes in "nodes" by performing a breadth-first search from those |
| 267 | // nodes, and accumulating the visited nodes. |
| 268 | std::deque<const Node*> queue; |
| 269 | for (const Node* n : visited) { |
| 270 | VLOG(2) << "Reverse reach init: " << n->name(); |
| 271 | queue.emplace_back(n); |
| 272 | } |
| 273 | while (!queue.empty()) { |
| 274 | const Node* n = queue.front(); |
| 275 | queue.pop_front(); |
| 276 | for (const Node* in : n->in_nodes()) { |
| 277 | if (visited.insert(in).second) { |
| 278 | queue.emplace_back(in); |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | // Make a pass over the graph to remove nodes not in "visited" |
| 284 | std::vector<Node*> all_nodes; |
| 285 | all_nodes.reserve(g->num_nodes()); |
| 286 | for (Node* n : g->nodes()) { |
| 287 | all_nodes.emplace_back(n); |
| 288 | } |
| 289 | |
| 290 | std::unordered_set<const Node*> excluded; |
| 291 | for (Node* n : all_nodes) { |
| 292 | if (visited.count(n) == 0 && !n->IsSource() && !n->IsSink()) { |
| 293 | excluded.emplace(n); |
| 294 | } |
| 295 | } |
| 296 | return excluded; |
| 297 | } |
| 298 | |
| 299 | } // namespace tensorflow |
no test coverage detected