MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ReplaceNode

Function ReplaceNode

tensorflow/compiler/tf2xla/tf2xla_util.cc:706–740  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

704}
705
706xla::StatusOr<Node*> ReplaceNode(Graph* g, Node* n, const NodeDef& node_def) {
707 // Create the replacement node.
708 Status s;
709 Node* new_node = g->AddNode(node_def, &s);
710 if (!s.ok()) {
711 return s;
712 }
713
714 // Record original node's output edges and remove them first. This is to avoid
715 // multiple producers for dst nodes' input.
716 std::vector<OutEdgeInfo> out_edge_info;
717 std::vector<const Edge*> out_edges;
718 for (const Edge* edge : n->out_edges()) {
719 out_edges.push_back(edge);
720 out_edge_info.push_back(
721 {edge->dst(), edge->src_output(), edge->dst_input()});
722 }
723 for (const Edge* edge : out_edges) {
724 g->RemoveEdge(edge);
725 }
726
727 // Add original node's input and output edges to the replacement node.
728 for (const Edge* in_edge : n->in_edges()) {
729 g->AddEdge(in_edge->src(), in_edge->src_output(), new_node,
730 in_edge->dst_input());
731 }
732 for (const OutEdgeInfo& out_edge : out_edge_info) {
733 g->AddEdge(new_node, out_edge.src_output, out_edge.dst, out_edge.dst_input);
734 }
735
736 // Remove the original node.
737 g->RemoveNode(n);
738
739 return new_node;
740}
741
742xla::StatusOr<Node*> BuildIdentityNode(
743 Graph* graph, const string& node_name, DataType dtype, const Node* input,

Calls 10

AddNodeMethod · 0.45
okMethod · 0.45
push_backMethod · 0.45
dstMethod · 0.45
src_outputMethod · 0.45
dst_inputMethod · 0.45
RemoveEdgeMethod · 0.45
AddEdgeMethod · 0.45
srcMethod · 0.45
RemoveNodeMethod · 0.45

Tested by

no test coverage detected