diff options
author | Skye Wanderman-Milne <skyewm@google.com> | 2017-11-28 16:11:48 -0800 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2017-11-28 16:14:57 -0800 |
commit | a80fd2acf08ceba0c8fc7684c3013e8e7d6bd8d3 (patch) | |
tree | 4f828449eba3eb6b603266732bc79e5e40974508 /tensorflow/c/c_api.cc | |
parent | 9049b440df17de47baf16d9e24590c3d0761e2c9 (diff) |
C API: fix bug in ValidateNoCycles().
This change makes ValidateNoCycles() work when the graph has unused
node ids (i.e. when Graph::num_nodes() < Graph::num_node_ids()).
PiperOrigin-RevId: 177234002
Diffstat (limited to 'tensorflow/c/c_api.cc')
-rw-r--r-- | tensorflow/c/c_api.cc | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/tensorflow/c/c_api.cc b/tensorflow/c/c_api.cc index bb41f92306..4fb8ec8e4b 100644 --- a/tensorflow/c/c_api.cc +++ b/tensorflow/c/c_api.cc @@ -383,12 +383,11 @@ void TF_Reset_Helper(const TF_SessionOptions* opt, const char** containers, // be less than the total node count. Status ValidateNoCycles(const Graph& g) { // TODO(nolivia): check this on a subset of the graph instead of all of it. - int total_num_nodes = g.num_node_ids(); // A node is ready when all of its inputs have been visited. std::vector<const Node*> ready; - std::vector<int> pending_count(total_num_nodes, 0); + std::vector<int> pending_count(g.num_node_ids(), 0); - for (int i = 0; i < total_num_nodes; ++i) { + for (int i = 0; i < g.num_node_ids(); ++i) { const Node* n = g.FindNodeId(i); if (n == nullptr) continue; pending_count[i] = n->in_edges().size(); @@ -421,7 +420,7 @@ Status ValidateNoCycles(const Graph& g) { } } - if (processed < total_num_nodes) { + if (processed < g.num_nodes()) { std::vector<string> nodes_in_cycle; for (int i = 0; i < pending_count.size() && nodes_in_cycle.size() < 3; ++i) { @@ -430,7 +429,7 @@ Status ValidateNoCycles(const Graph& g) { } } return errors::InvalidArgument( - "Graph is invalid, contains a cycle with ", total_num_nodes - processed, + "Graph is invalid, contains a cycle with ", g.num_nodes() - processed, " nodes, including: ", str_util::Join(nodes_in_cycle, ", ")); } return Status::OK(); |