| 1202 | } |
| 1203 | |
| 1204 | Status MutableGraphView::RemoveAllFanins(absl::string_view node_name, |
| 1205 | bool keep_controlling_fanins) { |
| 1206 | NodeDef* node = GetNode(node_name); |
| 1207 | if (node == nullptr) { |
| 1208 | string params = |
| 1209 | absl::Substitute("node_name='$0', keep_controlling_fanins=$1", |
| 1210 | node_name, keep_controlling_fanins); |
| 1211 | return MutationError("RemoveAllFanins", params, |
| 1212 | NodeMissingErrorMsg(node_name)); |
| 1213 | } |
| 1214 | |
| 1215 | if (node->input().empty()) { |
| 1216 | return Status::OK(); |
| 1217 | } |
| 1218 | |
| 1219 | const int num_regular_fanins = |
| 1220 | NumFanins(*node, /*include_controlling_nodes=*/false); |
| 1221 | RemoveFaninsInternal(node, keep_controlling_fanins); |
| 1222 | if (keep_controlling_fanins) { |
| 1223 | if (num_regular_fanins == 0) { |
| 1224 | return Status::OK(); |
| 1225 | } else if (num_regular_fanins < node->input_size()) { |
| 1226 | node->mutable_input()->DeleteSubrange(0, num_regular_fanins); |
| 1227 | } else { |
| 1228 | node->clear_input(); |
| 1229 | } |
| 1230 | } else { |
| 1231 | node->clear_input(); |
| 1232 | } |
| 1233 | return Status::OK(); |
| 1234 | } |
| 1235 | |
| 1236 | Status MutableGraphView::UpdateFanin(absl::string_view node_name, |
| 1237 | const TensorId& from_fanin, |