tensorflow/core/grappler/optimizers/data/split_utils_test.cc
// Run two FunctionDefs in sequence. Returns second(first(*input_tensors)) in
// *results.
Run two FunctionDefs in sequence.
Run two FunctionDefs in sequence .
void RunSplitFunctions(const FunctionDef& first, const FunctionDef& second,
                       const std::vector<Tensor>& input_tensors,
                       int num_captured_inputs, std::vector<Tensor>* results) {
  using test::function::NDef;
  std::vector<NodeDef> nodes;
  std::vector<string> first_inputs;
  std::vector<std::pair<std::string, Tensor>> feeds;
  for (int i = 0; i < input_tensors.size(); i++) {
    const Tensor& tensor = input_tensors[i];
    string input_name = absl::StrCat("input_", i);
    nodes.push_back(
        NDef(input_name, "Placeholder", {}, {{"dtype", tensor.dtype()}}));
    first_inputs.push_back(input_name);
    feeds.push_back({input_name, tensor});
  }
  nodes.push_back(NDef("first", first.signature().name(), first_inputs, {}));
  std::vector<string> second_inputs;
  const int num_outputs_of_first = first.ret_size();
  for (int i = 0; i < num_outputs_of_first; i++) {
    second_inputs.push_back(absl::StrCat("first:", i));
  }
  for (int i = input_tensors.size() - num_captured_inputs;
       i < input_tensors.size(); i++) {
    second_inputs.push_back(absl::StrCat("input_", i));
  }
  nodes.push_back(NDef("second", second.signature().name(), second_inputs, {}));
  GraphDef graph_def = test::function::GDef(nodes, {first, second});
  VLOG(2) << "Split graph def:\n" << graph_def.DebugString() << "\n";
  std::unique_ptr<Session> session;
  {
    Session* new_session;
    TF_ASSERT_OK(NewSession({}, &new_session));
    session.reset(new_session);
  }
  TF_ASSERT_OK(session->Create(graph_def));
  std::vector<string> second_outputs;
  const int num_outputs_of_second = second.ret_size();
  for (int i = 0; i < num_outputs_of_second; i++) {
    second_outputs.push_back(absl::StrCat("second:", i));
  }
  TF_ASSERT_OK(session->Run(feeds, second_outputs, {}, results));
}
void RunSplitFunctions ( const FunctionDef & first , const FunctionDef & second , const std :: vector < Tensor > & input_tensors , int num_captured_inputs , std :: vector < Tensor > * results ) { using test :: function :: NDef ; std :: vector < NodeDef > nodes ; std :: vector < string > first_inputs ; std :: vector < std :: pair < std :: string , Tensor > > feeds ; for ( int i = 0 ; i < input_tensors . size ( ) ; i ++ ) { const Tensor & tensor = input_tensors [ i ] ; string input_name = absl :: StrCat ( " " , i ) ; nodes . push_back ( NDef ( input_name , " " , { } , { { " " , tensor . dtype ( ) } } ) ) ; first_inputs . push_back ( input_name ) ; feeds . push_back ( { input_name , tensor } ) ; } nodes . push_back ( NDef ( " " , first . signature ( ) . name ( ) , first_inputs , { } ) ) ; std :: vector < string > second_inputs ; const int num_outputs_of_first = first . ret_size ( ) ; for ( int i = 0 ; i < num_outputs_of_first ; i ++ ) { second_inputs . push_back ( absl :: StrCat ( " " , i ) ) ; } for ( int i = input_tensors . size ( ) - num_captured_inputs ; i < input_tensors . size ( ) ; i ++ ) { second_inputs . push_back ( absl :: StrCat ( " " , i ) ) ; } nodes . push_back ( NDef ( " " , second . signature ( ) . name ( ) , second_inputs , { } ) ) ; GraphDef graph_def = test :: function :: GDef ( nodes , { first , second } ) ; VLOG ( 2 ) << " \n " << graph_def . DebugString ( ) << " \n " ; std :: unique_ptr < Session > session ; { Session * new_session ; TF_ASSERT_OK ( NewSession ( { } , & new_session ) ) ; session . reset ( new_session ) ; } TF_ASSERT_OK ( session -> Create ( graph_def ) ) ; std :: vector < string > second_outputs ; const int num_outputs_of_second = second . ret_size ( ) ; for ( int i = 0 ; i < num_outputs_of_second ; i ++ ) { second_outputs . push_back ( absl :: StrCat ( " " , i ) ) ; } TF_ASSERT_OK ( session -> Run ( feeds , second_outputs , { } , results ) ) ; }
Run two FunctionDefs in sequence.
Run two FunctionDefs in sequence .