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

Function TEST

tensorflow/core/kernels/immutable_constant_op_test.cc:90–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88struct ImmutableConstantOpTest {};
89
90TEST(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.

Callers

nothing calls this directly

Calls 14

ImmutableConstFunction · 0.85
DefaultFunction · 0.85
CreateTempFileFunction · 0.85
ExitOnErrorMethod · 0.80
MatMulFunction · 0.70
nameMethod · 0.65
NewSessionFunction · 0.50
ToGraphDefMethod · 0.45
CreateMethod · 0.45
RunMethod · 0.45
nodeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected