MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / TEST

Function TEST

tensorflow/core/graph/algorithm_test.cc:80–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78}
79
80TEST(AlgorithmTest, ReversePostOrder) {
81 GraphDefBuilder b(GraphDefBuilder::kFailImmediately);
82 using namespace ::tensorflow::ops; // NOLINT(build/namespaces)
83 Node* w1 = SourceOp("TestParams", b.opts().WithName("W1"));
84 Node* w2 = SourceOp("TestParams", b.opts().WithName("W2"));
85 Node* input =
86 SourceOp("TestInput", b.opts().WithName("input").WithControlInput(w1));
87 Node* t1 = BinaryOp("TestMul", w1, {input, 1}, b.opts().WithName("t1"));
88 BinaryOp("TestMul", w1, {input, 1},
89 b.opts().WithName("t2").WithControlInput(t1));
90 BinaryOp("TestMul", w2, {input, 1}, b.opts().WithName("t3"));
91
92 Graph g(OpRegistry::Global());
93 TF_ASSERT_OK(GraphDefBuilderToGraph(b, &g));
94 std::vector<Node*> order;
95
96 // Test reverse post order:
97 GetReversePostOrder(g, &order);
98
99 // Check that the order respects the dependencies correctly.
100 std::vector<std::pair<string, string>> reverse_orders = {
101 {"W1", "input"}, {"W1", "t1"}, {"W1", "t2"}, {"W1", "t3"},
102 {"input", "t1"}, {"input", "t3"}, {"t1", "t2"}, {"W2", "t3"}};
103 string error;
104 EXPECT_TRUE(ExpectBefore(reverse_orders, order, &error)) << error;
105
106 // A false ordering should fail the check.
107 reverse_orders = {{"input", "W1"}};
108 EXPECT_FALSE(ExpectBefore(reverse_orders, order, &error));
109
110 // Test post order:
111 GetPostOrder(g, &order);
112
113 // Check that the order respects the dependencies correctly.
114 std::vector<std::pair<string, string>> orders = {
115 {"input", "W1"}, {"t1", "W1"}, {"t2", "W1"}, {"t3", "W1"},
116 {"t1", "input"}, {"t3", "input"}, {"t2", "t1"}, {"t3", "W2"}};
117 EXPECT_TRUE(ExpectBefore(orders, order, &error)) << error;
118
119 // A false ordering should fail the check.
120 orders = {{"W1", "t3"}};
121 EXPECT_FALSE(ExpectBefore(orders, order, &error));
122}
123
124TEST(AlgorithmTest, ReversePostOrderStable) {
125 int64 run_count = 100;

Callers

nothing calls this directly

Calls 15

SourceOpFunction · 0.85
GraphDefBuilderToGraphFunction · 0.85
GetReversePostOrderFunction · 0.85
ExpectBeforeFunction · 0.85
GetPostOrderFunction · 0.85
NodeComparatorNameClass · 0.85
reverseFunction · 0.85
WithControlInputMethod · 0.80
BinaryOpFunction · 0.70
UnaryOpFunction · 0.70
nameMethod · 0.65
StrCatFunction · 0.50

Tested by

no test coverage detected