| 82 | } // namespace |
| 83 | |
| 84 | GraphView::GraphView(const GraphDef* graph, Status* status) |
| 85 | : GraphViewInternal(graph) { |
| 86 | const int num_nodes = graph->node_size(); |
| 87 | node_index_by_name_.reserve(num_nodes); |
| 88 | nodes_.reserve(num_nodes); |
| 89 | for (const NodeDef& node : graph->node()) { |
| 90 | if (!AddUniqueNodeInternal(&node)) { |
| 91 | *status = errors::InvalidArgument( |
| 92 | kGraphViewError, "graph has multiple nodes with the name '", |
| 93 | node.name(), "'."); |
| 94 | Reset(); |
| 95 | return; |
| 96 | } |
| 97 | } |
| 98 | Status s; |
| 99 | for (NodeView& node_view : nodes_) { |
| 100 | s = CheckAndAddFaninsInternal(&node_view); |
| 101 | if (!s.ok()) { |
| 102 | *status = s; |
| 103 | Reset(); |
| 104 | return; |
| 105 | } |
| 106 | } |
| 107 | *status = Status::OK(); |
| 108 | } |
| 109 | |
| 110 | bool GraphView::AddUniqueNodeInternal(const NodeDef* node) { |
| 111 | const int node_index = node_index_by_name_.size(); |