| 112 | }; |
| 113 | |
| 114 | TEST_F(ConstantFoldingTest, Basic) { |
| 115 | Scope s = Scope::NewRootScope(); |
| 116 | BuildSimpleGraph(&s); |
| 117 | Graph g(OpRegistry::Global()); |
| 118 | TF_ASSERT_OK(s.ToGraph(&g)); |
| 119 | |
| 120 | bool was_mutated; |
| 121 | TF_ASSERT_OK(ConstantFold(ConstantFoldingOptions{}, nullptr, Env::Default(), |
| 122 | nullptr, &g, &was_mutated)); |
| 123 | EXPECT_TRUE(was_mutated); |
| 124 | |
| 125 | std::unordered_map<string, Node*> index = g.BuildNodeNameIndex(); |
| 126 | Node* s1 = index.at("s1"); |
| 127 | Node* s2 = index.at("s2"); |
| 128 | // Nodes s1 and s2 now should now have a constant input |
| 129 | EXPECT_EQ(1, s1->num_inputs()); |
| 130 | ExpectNodeClose<float>(*(s1->in_nodes().begin()), {1.0, 2.0, 3.0, 4.0}, |
| 131 | {2, 2}); |
| 132 | EXPECT_EQ(1, s2->num_inputs()); |
| 133 | ExpectNodeClose<float>(*(s2->in_nodes().begin()), {2.0, 1.0, 4.0, 3.0}, |
| 134 | {2, 2}); |
| 135 | } |
| 136 | |
| 137 | // Tests that different node creation ordering creates same graph after constant |
| 138 | // folding. |
nothing calls this directly
no test coverage detected