Skip to content

Commit

Permalink
Merge pull request PaddlePaddle#15 from Superjomn/test/add-graph-utils
Browse files Browse the repository at this point in the history
add graph utils test
  • Loading branch information
Superjomn authored Feb 5, 2020
2 parents 2818c10 + 05cf518 commit 187ecf4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cinn/common/graph_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include <glog/logging.h>
#include <list>
#include <map>
#include <string>
#include <unordered_map>
#include <vector>

#include "cinn/common/object.h"
Expand Down Expand Up @@ -116,7 +116,7 @@ class Graph {

protected:
//! A lookup table that map from hash key to graph node, note that it doesn't own the graph node.
std::unordered_map<size_t, GraphNode*> registry_;
std::map<size_t, GraphNode*> registry_;
//! A list owns the graph nodes.
std::vector<Shared<GraphNode>> nodes_;
};
Expand Down
6 changes: 6 additions & 0 deletions cinn/common/graph_utils_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ TEST(Graph, basic) {
Graph::edge_order_t edge_order;
std::tie(node_order, edge_order) = graph.topological_order();

std::vector<std::string> order({"A", "B", "C", "D", "E"});

for (auto* e : edge_order) {
LOG(INFO) << "visit edge: " << e->source()->As<GraphNodeWithName>()->name << " -> "
<< e->sink()->As<GraphNodeWithName>()->name;
Expand All @@ -47,6 +49,10 @@ TEST(Graph, basic) {
for (auto* n : node_order) {
LOG(INFO) << "visit node: " << n->As<GraphNodeWithName>()->name;
}

for (int i = 0; i < node_order.size(); i++) {
EXPECT_EQ(node_order[i]->As<GraphNodeWithName>()->name, order[i]);
}
}

} // namespace common
Expand Down

0 comments on commit 187ecf4

Please sign in to comment.