| 88 | struct ImmutableConstantOpTest {}; |
| 89 | |
| 90 | TEST(ImmutableConstantOpTest, Simple) { |
| 91 | const TensorShape kTestTensorShape({4, 1}); |
| 92 | const TensorShape kTestTensorShapeT({1, 4}); |
| 93 | auto root = Scope::NewRootScope().ExitOnError(); |
| 94 | auto node1 = |
| 95 | ops::ImmutableConst(root, DT_FLOAT, kTestTensorShape, "test:///2"); |
| 96 | auto node2 = |
| 97 | ops::ImmutableConst(root, DT_FLOAT, kTestTensorShapeT, "test:///3"); |
| 98 | auto result = ops::MatMul(root, node1, node2); |
| 99 | GraphDef graph_def; |
| 100 | TF_ASSERT_OK(root.ToGraphDef(&graph_def)); |
| 101 | SessionOptions session_options; |
| 102 | session_options.env = Env::Default(); |
| 103 | session_options.config.mutable_graph_options() |
| 104 | ->mutable_optimizer_options() |
| 105 | ->set_opt_level(OptimizerOptions::L0); |
| 106 | std::unique_ptr<Session> session(NewSession(session_options)); |
| 107 | ASSERT_TRUE(session != nullptr) << "Failed to create session"; |
| 108 | TF_ASSERT_OK(session->Create(graph_def)) << "Can't create test graph"; |
| 109 | std::vector<Tensor> outputs; |
| 110 | TF_ASSERT_OK(session->Run({}, {result.node()->name() + ":0"}, {}, &outputs)); |
| 111 | ASSERT_EQ(outputs.size(), 1); |
| 112 | EXPECT_EQ(outputs.front().flat<float>()(0), 2.0f * 3.0f); |
| 113 | EXPECT_EQ(outputs.front().flat<float>()(1), 2.0f * 3.0f); |
| 114 | EXPECT_EQ(outputs.front().flat<float>()(2), 2.0f * 3.0f); |
| 115 | EXPECT_EQ(outputs.front().flat<float>()(kTestTensorSize - 1), 2.0f * 3.0f); |
| 116 | } |
| 117 | |
| 118 | // Creates a test graph with two immutable_const tensors and a simple math |
| 119 | // operation, one of nodes has wrong size, check that error properly reported. |
nothing calls this directly
no test coverage detected