diff options
Diffstat (limited to 'tensorflow/core/grappler/graph_view.cc')
-rw-r--r-- | tensorflow/core/grappler/graph_view.cc | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/tensorflow/core/grappler/graph_view.cc b/tensorflow/core/grappler/graph_view.cc index 3e448216f9..7998f0a902 100644 --- a/tensorflow/core/grappler/graph_view.cc +++ b/tensorflow/core/grappler/graph_view.cc @@ -22,28 +22,33 @@ namespace grappler { GraphView::GraphView(GraphDef* graph) : graph_(graph) { for (int i = 0; i < graph_->node_size(); i++) { auto node = graph_->mutable_node(i); - auto rslt = nodes_.insert(std::make_pair(node->name(), node)); + auto result = nodes_.emplace(node->name(), node); // Check that the graph doesn't contain multiple nodes with the same name. - CHECK(rslt.second) << "Non unique node name detected: " << node->name(); + CHECK(result.second) << "Non unique node name detected: " << node->name(); } + for (NodeDef& node : *graph_->mutable_node()) { - for (int i = 0; i < node.input_size(); ++i) { - OutputPort fanin; - string fanin_name = ParseNodeName(node.input(i), &fanin.port_id); - fanin.node = nodes_[fanin_name]; + AddFanouts(&node); + } +} - InputPort input; - input.node = &node; - if (fanin.port_id < 0) { - input.port_id = -1; - } else { - input.port_id = i; - num_regular_outputs_[fanin.node] = - std::max(num_regular_outputs_[fanin.node], fanin.port_id); - } +void GraphView::AddFanouts(NodeDef* node) { + for (int i = 0; i < node->input_size(); ++i) { + OutputPort fanin; + string fanin_name = ParseNodeName(node->input(i), &fanin.port_id); + fanin.node = nodes_[fanin_name]; - fanouts_[fanin].insert(input); + InputPort input; + input.node = node; + if (fanin.port_id < 0) { + input.port_id = -1; + } else { + input.port_id = i; + num_regular_outputs_[fanin.node] = + std::max(num_regular_outputs_[fanin.node], fanin.port_id); } + + fanouts_[fanin].insert(input); } } |