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

Function TEST_F

tensorflow/c/while_loop_test.cc:138–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

136};
137
138TEST_F(CApiWhileLoopTest, BasicLoop) {
139 Init(2);
140
141 // Validate TF_WhileParams returned by TF_NewWhile()
142 EXPECT_TRUE(params_->body_graph != nullptr);
143 EXPECT_TRUE(params_->cond_graph != nullptr);
144
145 EXPECT_EQ(params_->ninputs, 2);
146
147 ASSERT_TRUE(params_->cond_inputs != nullptr);
148 ASSERT_TRUE(params_->cond_inputs[0].oper != nullptr);
149 EXPECT_TRUE(params_->cond_inputs[1].oper != nullptr);
150
151 ASSERT_TRUE(params_->body_inputs != nullptr);
152 EXPECT_TRUE(params_->body_inputs[0].oper != nullptr);
153 EXPECT_TRUE(params_->body_inputs[1].oper != nullptr);
154
155 ASSERT_TRUE(params_->body_outputs != nullptr);
156
157 // Create loop: while (input1 < input2) input1 += input2 + 1
158 TF_Operation* less_than =
159 LessThan(params_->cond_inputs[0], params_->cond_inputs[1],
160 params_->cond_graph, s_);
161 ASSERT_EQ(TF_OK, TF_GetCode(s_)) << TF_Message(s_);
162 params_->cond_output = {less_than, 0};
163
164 TF_Operation* add1 = Add(params_->body_inputs[0], params_->body_inputs[1],
165 params_->body_graph, s_, "add1");
166 ASSERT_EQ(TF_OK, TF_GetCode(s_)) << TF_Message(s_);
167 TF_Operation* one = ScalarConst(1, params_->body_graph, s_);
168 ASSERT_EQ(TF_OK, TF_GetCode(s_)) << TF_Message(s_);
169 TF_Operation* add2 = Add(add1, one, params_->body_graph, s_, "add2");
170 ASSERT_EQ(TF_OK, TF_GetCode(s_)) << TF_Message(s_);
171 params_->body_outputs[0] = {add2, 0};
172 params_->body_outputs[1] = params_->body_inputs[1];
173
174 // Finalize while loop
175 ExpectOK();
176
177 // Validate while loop outputs returned by TF_FinishWhile()
178 EXPECT_TRUE(outputs_[0].oper != nullptr);
179 EXPECT_GE(outputs_[0].index, 0);
180 EXPECT_TRUE(outputs_[1].oper != nullptr);
181 EXPECT_GE(outputs_[1].index, 0);
182
183 // Check that cond and body inputs are not present
184 for (int i = 0; i < params_->ninputs; ++i) {
185 string cond_name =
186 ::tensorflow::strings::StrCat(params_->name, "/cond/cond_input", i);
187 string body_name =
188 ::tensorflow::strings::StrCat(params_->name, "/body/body_input", i);
189 EXPECT_TRUE(TF_GraphOperationByName(graph_, cond_name.c_str()) == nullptr);
190 EXPECT_TRUE(TF_GraphOperationByName(graph_, body_name.c_str()) == nullptr);
191 }
192
193 // Run the graph
194 Run({-9, 2});
195 ExpectOutputValue(0, 3);

Callers

nothing calls this directly

Calls 15

LessThanFunction · 0.85
TF_GetCodeFunction · 0.85
TF_MessageFunction · 0.85
ScalarConstFunction · 0.85
TF_GraphOperationByNameFunction · 0.85
TF_NewWhileFunction · 0.85
TF_FinishWhileFunction · 0.85
TF_NewOperationFunction · 0.85
TF_AddInputFunction · 0.85
TF_FinishOperationFunction · 0.85
TF_AbortWhileFunction · 0.85
TF_AddGradientsFunction · 0.85

Tested by

no test coverage detected