Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
refactor topological_sort to use Node.get_users() (#2536)
Browse files Browse the repository at this point in the history
* use Node.get_users() to replace deprecated func

* use const ref instead of auto

* used const auto& in graph_util.cpp
  • Loading branch information
Wenzhe Xue authored and diyessi committed Mar 9, 2019
1 parent f5b296d commit 97ca4a6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/ngraph/graph_util.cpp
Expand Up @@ -185,7 +185,7 @@ bool ngraph::is_post_dominated(Node* X, Node* Y)
stack.pop_front();
if (curr != Y)
{
for (auto next : curr->get_users())
for (const auto& next : curr->get_users())
{
if (visited.count(next.get()) == 0)
{
Expand Down Expand Up @@ -458,7 +458,7 @@ NodeVector ngraph::get_subgraph_outputs(const NodeVector& nodes,
continue;
}

for (auto u : n->get_users())
for (const auto& u : n->get_users())
{
if (nodes_set.count(u) == 0 && (!ignore_unused || is_used(u.get())))
{
Expand Down Expand Up @@ -487,7 +487,7 @@ bool ngraph::is_used(Node* node)
instances_seen.insert(n);
}
stack.pop_front();
for (auto arg : n->get_users())
for (const auto& arg : n->get_users())
{
if (instances_seen.count(arg.get()) == 0)
{
Expand All @@ -501,7 +501,7 @@ bool ngraph::is_used(Node* node)
size_t ngraph::get_user_count(Node* node)
{
size_t count = 0;
for (auto node_user : node->get_users())
for (const auto& node_user : node->get_users())
{
count += is_used(node_user.get());
}
Expand Down
24 changes: 6 additions & 18 deletions src/ngraph/graph_util.hpp
Expand Up @@ -96,17 +96,11 @@ namespace ngraph
result_list.push_back(node_map[independent_node]);
independent_nodes.pop_front();

for (auto& output : independent_node->get_outputs())
for (const std::shared_ptr<Node>& user : independent_node->get_users())
{
for (auto& input : output.get_inputs())
if (--node_dependency_count[user.get()] == 0)
{
auto user = input->get_raw_pointer_node();
node_dependency_count[user] -= 1;
size_t count = node_dependency_count[user];
if (count == 0)
{
independent_nodes.push_back(user);
}
independent_nodes.push_back(user.get());
}
}

Expand Down Expand Up @@ -179,17 +173,11 @@ namespace ngraph
result_list.push_back(node_map[independent_node]);
independent_nodes.pop_front();

for (auto& output : independent_node->get_outputs())
for (const std::shared_ptr<Node>& user : independent_node->get_users())
{
for (auto& input : output.get_inputs())
if (--node_dependency_count[user.get()] == 0)
{
auto user = input->get_raw_pointer_node();
node_dependency_count[user] -= 1;
size_t count = node_dependency_count[user];
if (count == 0)
{
independent_nodes.push_back(user);
}
independent_nodes.push_back(user.get());
}
}

Expand Down

0 comments on commit 97ca4a6

Please sign in to comment.