tensorflow/c/while_loop_test.cc
// This is a basic test to make sure the C++ gradient code can handle while
// loops created by the C API (which calls the C++ API under the hood). There
// are more while loop gradient tests in cc/framework/while_gradients_test.cc.
This is a basic test to make sure the C++ gradient code can handle while
loops created by the C API (which calls the C++ API under the hood). There
are more while loop gradient tests in cc/framework/while_gradients_test.cc.
This is a basic test to make sure the C ++ gradient code can handle while loops created by the C API ( which calls the C ++ API under the hood ) . There are more while loop gradient tests in cc / framework / while_gradients_test . cc .
TEST_F(CApiWhileLoopTest, Gradients) {
  Init(1);
  TF_Operation* ten = ScalarConst(10, params_->cond_graph, s_);
  TF_Operation* less_than =
      LessThan(params_->cond_inputs[0], {ten, 0}, params_->cond_graph, s_);
  DCHECK_EQ(TF_OK, TF_GetCode(s_)) << TF_Message(s_);
  params_->cond_output = {less_than, 0};
  TF_Operation* one = ScalarConst(1, params_->body_graph, s_);
  TF_Operation* add =
      Add(params_->body_inputs[0], {one, 0}, params_->body_graph, s_);
  ASSERT_EQ(TF_OK, TF_GetCode(s_)) << TF_Message(s_);
  params_->body_outputs[0] = {add, 0};
  ExpectOK();
  TF_Output grad_output;
  TF_AddGradients(graph_, outputs_.data(), outputs_.size(), inputs_.data(), 1,
                  nullptr, s_, &grad_output);
  ASSERT_EQ(TF_OK, TF_GetCode(s_)) << TF_Message(s_);
  Run({grad_output}, {0});
  ExpectOutputValue(0, 1);
}
TEST_F ( CApiWhileLoopTest , Gradients ) { Init ( 1 ) ; TF_Operation * ten = ScalarConst ( 10 , params_ -> cond_graph , s_ ) ; TF_Operation * less_than = LessThan ( params_ -> cond_inputs [ 0 ] , { ten , 0 } , params_ -> cond_graph , s_ ) ; DCHECK_EQ ( TF_OK , TF_GetCode ( s_ ) ) << TF_Message ( s_ ) ; params_ -> cond_output = { less_than , 0 } ; TF_Operation * one = ScalarConst ( 1 , params_ -> body_graph , s_ ) ; TF_Operation * add = Add ( params_ -> body_inputs [ 0 ] , { one , 0 } , params_ -> body_graph , s_ ) ; ASSERT_EQ ( TF_OK , TF_GetCode ( s_ ) ) << TF_Message ( s_ ) ; params_ -> body_outputs [ 0 ] = { add , 0 } ; ExpectOK ( ) ; TF_Output grad_output ; TF_AddGradients ( graph_ , outputs_ . data ( ) , outputs_ . size ( ) , inputs_ . data ( ) , 1 , nullptr , s_ , & grad_output ) ; ASSERT_EQ ( TF_OK , TF_GetCode ( s_ ) ) << TF_Message ( s_ ) ; Run ( { grad_output } , { 0 } ) ; ExpectOutputValue ( 0 , 1 ) ; }
This is a basic test to make sure the C++ gradient code can handle while
loops created by the C API (which calls the C++ API under the hood).
This is a basic test to make sure the C ++ gradient code can handle while loops created by the C API ( which calls the C ++ API under the hood ) .
// Create loop: while (i < 10) i += 1 // Create backprop graph // Run gradient