aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/graph/graph_constructor.cc
diff options
context:
space:
mode:
authorGravatar A. Unique TensorFlower <gardener@tensorflow.org>2017-05-22 13:58:57 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-05-22 14:02:55 -0700
commit4e131d27354bc9be90e291f3ec4538c0e3bf06eb (patch)
tree2677eb5ff6b721721f0bf6b5ac2cd41f1afa1075 /tensorflow/core/graph/graph_constructor.cc
parent89e09f6357863f05ffd3db1ac5f202559470bbfd (diff)
Many algorithms need to enumerate the set of nodes within a graph, while excluding the special Sink and Source nodes. The checks for skipping Source and Sink are duplicated in dozens of loops.
This CL adds a new Graph::op_nodes() method, which returns an enumerable range of all operation nodes, excluding Sink and Source. This allows many for loops to be simplified. This simplification is being done mainly for readability / reliability. There may be a tiny performance difference owing to this change (as well as making the Graph::nodes() and Graph::op_nodes() methods inlineable), but the measured difference is not reliably large enough to be significant. The changes to graph.h and graph.cc are quite minimal. I updated all of the uses of Graph::nodes() that I could reliably determine were unaffected by the change. Most uses immediately checked node->IsOp(). Some compared node->type_string() against literal strings, none of which were "_SINK" or "_SOURCE", and so using op_nodes() was more appropriate than nodes(). In some cases, it was not obvious whether an existing use of Graph::node() wanted to enumerate Sink / Source, so I left those uses unaffected. PiperOrigin-RevId: 156782112
Diffstat (limited to 'tensorflow/core/graph/graph_constructor.cc')
-rw-r--r--tensorflow/core/graph/graph_constructor.cc4
1 files changed, 1 insertions, 3 deletions
diff --git a/tensorflow/core/graph/graph_constructor.cc b/tensorflow/core/graph/graph_constructor.cc
index 70087b8fe1..1d7eea2206 100644
--- a/tensorflow/core/graph/graph_constructor.cc
+++ b/tensorflow/core/graph/graph_constructor.cc
@@ -898,9 +898,7 @@ void CopyGraph(const Graph& src, Graph* dest) {
node_map; // "Node in src" -> "Node in *dest"
node_map[src.source_node()] = dest->source_node();
node_map[src.sink_node()] = dest->sink_node();
- for (Node* n : src.nodes()) {
- if (n->IsSource() || n->IsSink()) continue;
- CHECK(n->IsOp());
+ for (Node* n : src.op_nodes()) {
node_map[n] = dest->CopyNode(n);
}