tensorflow/core/grappler/optimizers/data/split_utils_test.cc
// Run a FunctionDef on the given input tensors.
Run a FunctionDef on the given input tensors.
Run a FunctionDef on the given input tensors .
void RunFunction(const FunctionDef& func,
                 const std::vector<Tensor>& input_tensors,
                 std::vector<Tensor>* results) {
  using test::function::NDef;
  std::vector<NodeDef> nodes;
  std::vector<string> 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()}}));
    inputs.push_back(input_name);
    feeds.push_back({input_name, tensor});
  }
  nodes.push_back(NDef("f", func.signature().name(), inputs, {}));
  GraphDef graph_def = test::function::GDef(nodes, {func});
  VLOG(2) << "Original 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> outputs;
  const int num_outputs = func.ret_size();
  for (int i = 0; i < num_outputs; i++) {
    outputs.push_back(absl::StrCat("f:", i));
  }
  TF_ASSERT_OK(session->Run(feeds, outputs, {}, results));
}
void RunFunction ( const FunctionDef & func , const std :: vector < Tensor > & input_tensors , std :: vector < Tensor > * results ) { using test :: function :: NDef ; std :: vector < NodeDef > nodes ; std :: vector < string > 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 ( ) } } ) ) ; inputs . push_back ( input_name ) ; feeds . push_back ( { input_name , tensor } ) ; } nodes . push_back ( NDef ( " " , func . signature ( ) . name ( ) , inputs , { } ) ) ; GraphDef graph_def = test :: function :: GDef ( nodes , { func } ) ; 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 > outputs ; const int num_outputs = func . ret_size ( ) ; for ( int i = 0 ; i < num_outputs ; i ++ ) { outputs . push_back ( absl :: StrCat ( " " , i ) ) ; } TF_ASSERT_OK ( session -> Run ( feeds , outputs , { } , results ) ) ; }
Run a FunctionDef on the given input tensors.
Run a FunctionDef on the given input tensors .