diff options
author | A. Unique TensorFlower <gardener@tensorflow.org> | 2017-05-22 13:58:57 -0700 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2017-05-22 14:02:55 -0700 |
commit | 4e131d27354bc9be90e291f3ec4538c0e3bf06eb (patch) | |
tree | 2677eb5ff6b721721f0bf6b5ac2cd41f1afa1075 /tensorflow/core/graph/graph.cc | |
parent | 89e09f6357863f05ffd3db1ac5f202559470bbfd (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.cc')
-rw-r--r-- | tensorflow/core/graph/graph.cc | 6 |
1 files changed, 0 insertions, 6 deletions
diff --git a/tensorflow/core/graph/graph.cc b/tensorflow/core/graph/graph.cc index 9066de5668..80161ceb56 100644 --- a/tensorflow/core/graph/graph.cc +++ b/tensorflow/core/graph/graph.cc @@ -488,12 +488,6 @@ string Graph::NewName(StringPiece prefix) { return strings::StrCat(prefix, "/_", name_counter_++); } -gtl::iterator_range<NodeIter> Graph::nodes() const { - // Note that NodeId 0 is always valid since we don't let the source - // node be removed from the graph. - return gtl::make_range(NodeIter(this, 0), NodeIter(this, num_node_ids())); -} - bool Graph::IsValidNode(Node* node) const { if (node == nullptr) return false; const int id = node->id(); |