| 664 | namespace { |
| 665 | |
| 666 | Status ReplaceNode( |
| 667 | const std::string& op_name, |
| 668 | Node* node, Graph* graph, |
| 669 | std::vector<SrcInfo>& input_info, |
| 670 | std::unordered_map<std::string, const AttrValue*>& attr_info) { |
| 671 | |
| 672 | // Create KvLookup/KvImport op here and remove the node |
| 673 | NodeDef new_node_def; |
| 674 | new_node_def.set_name(node->name()); |
| 675 | new_node_def.set_op(op_name); |
| 676 | |
| 677 | // Set attrs |
| 678 | for (auto attr : attr_info) { |
| 679 | (*new_node_def.mutable_attr())[attr.first] = *(attr.second); |
| 680 | } |
| 681 | |
| 682 | Status status; |
| 683 | Node *new_node = graph->AddNode(new_node_def, &status); |
| 684 | if (!status.ok()) return status; |
| 685 | |
| 686 | // Add input egdes, from slot 0 -> n |
| 687 | for (size_t i = 0; i < input_info.size(); ++i) { |
| 688 | int idx = i; |
| 689 | if (input_info[i].src_slot == Graph::kControlSlot) { |
| 690 | idx = Graph::kControlSlot; |
| 691 | } |
| 692 | graph->AddEdge(input_info[i].src_node, |
| 693 | input_info[i].src_slot, |
| 694 | new_node, idx); |
| 695 | } |
| 696 | |
| 697 | // Add output edges |
| 698 | for (const Edge* edge : node->out_edges()) { |
| 699 | graph->AddEdge(new_node, edge->src_output(), |
| 700 | edge->dst(), edge->dst_input()); |
| 701 | } |
| 702 | |
| 703 | // remove current node |
| 704 | graph->RemoveNode(node); |
| 705 | |
| 706 | return Status::OK(); |
| 707 | } |
| 708 | |
| 709 | Status ReplaceNode( |
| 710 | const std::string& op_name, |
no test coverage detected