| 118 | } |
| 119 | |
| 120 | Status GraphView::CheckAndAddFaninsInternal(NodeView* node_view) { |
| 121 | bool has_observed_control = false; |
| 122 | const NodeDef* node = node_view->node(); |
| 123 | const string& node_name = node->name(); |
| 124 | const int node_index = node_view->node_index_; |
| 125 | node_view->fanins_set_.reserve(node->input_size()); |
| 126 | for (const string& input : node->input()) { |
| 127 | TensorId fanin_id = ParseTensorName(input); |
| 128 | if (fanin_id.node() == node_name) { |
| 129 | return errors::InvalidArgument(kGraphViewError, "node '", node_name, |
| 130 | "' has self cycle fanin '", input, "'."); |
| 131 | } |
| 132 | bool is_control = IsTensorIdControl(fanin_id); |
| 133 | if (!is_control && has_observed_control) { |
| 134 | return errors::InvalidArgument(kGraphViewError, "node '", node_name, |
| 135 | "' has regular fanin '", input, |
| 136 | "' after controlling fanins."); |
| 137 | } |
| 138 | auto it = node_index_by_name_.find(fanin_id.node()); |
| 139 | if (it == node_index_by_name_.end()) { |
| 140 | return errors::InvalidArgument(kGraphViewError, "node '", node_name, |
| 141 | "' has missing fanin '", input, "'."); |
| 142 | } |
| 143 | const int fanin_node_index = it->second; |
| 144 | NodeView& fanin_node_view = nodes_[fanin_node_index]; |
| 145 | |
| 146 | if (is_control) { |
| 147 | fanin_node_view.controlled_fanouts_.emplace_back(this, node_index, |
| 148 | Graph::kControlSlot); |
| 149 | node_view->controlling_fanins_.emplace_back(this, fanin_node_index, |
| 150 | Graph::kControlSlot); |
| 151 | node_view->fanins_set_.emplace(fanin_node_view.node(), |
| 152 | Graph::kControlSlot); |
| 153 | has_observed_control = true; |
| 154 | } else { |
| 155 | if (fanin_node_view.regular_fanouts_by_port_.size() < |
| 156 | fanin_id.index() + 1) { |
| 157 | fanin_node_view.regular_fanouts_by_port_.resize(fanin_id.index() + 1); |
| 158 | } |
| 159 | fanin_node_view.regular_fanouts_by_port_[fanin_id.index()].emplace_back( |
| 160 | this, node_index, node_view->regular_fanins_.size()); |
| 161 | ++fanin_node_view.num_regular_fanouts_; |
| 162 | node_view->regular_fanins_.emplace_back(this, fanin_node_index, |
| 163 | fanin_id.index()); |
| 164 | node_view->fanins_set_.emplace(fanin_node_view.node(), fanin_id.index()); |
| 165 | } |
| 166 | } |
| 167 | return Status::OK(); |
| 168 | } |
| 169 | |
| 170 | MutableFaninView::MutableFaninView(MutableNodeView* node_view, int index) |
| 171 | : NodeIndexAndPortIndex(node_view->graph_view_, node_view->node_index_, |
nothing calls this directly
no test coverage detected