| 477 | // to_remove inputs. |
| 478 | template <typename TensorT> |
| 479 | Status RemovePrecedingNode(Graph<TensorT>* graph, const Node* to_remove, |
| 480 | const Node* to_keep) { |
| 481 | // Make sure all outputs from to_remove are consumed by to_keep. |
| 482 | for (auto output : graph->FindOutputs(to_remove->id)) { |
| 483 | auto consumers = graph->FindConsumers(output->id); |
| 484 | if (consumers.size() > 1 || |
| 485 | (consumers.size() == 1 && consumers[0] != to_keep)) { |
| 486 | return InvalidArgumentError( |
| 487 | "Output from to_remove node has other consumers"); |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | // Update all references |
| 492 | for (auto input : graph->FindInputs(to_remove->id)) { |
| 493 | RETURN_IF_ERROR(graph->AddConsumer(to_keep->id, input->id)); |
| 494 | } |
| 495 | for (auto output : graph->FindOutputs(to_remove->id)) { |
| 496 | RETURN_IF_ERROR(graph->DeleteValue(output->id)); |
| 497 | } |
| 498 | return graph->DeleteNode(to_remove->id); |
| 499 | } |
| 500 | |
| 501 | // Removes to_remove node that follows to_keep node only if to_remove has inputs |
| 502 | // that are produced by to_keep. to_keep inherits all to_remove inputs. |
no test coverage detected