tensorflow/compiler/tf2xla/rearrange_function_argument.cc
// Given all _Retval nodes in the function, return if we need to rewrite the
// function (by checking if we have DT_RESOURCE return values). If we need to
// rewrite the function, `retval_index_mapping` will hold the mapping from
// original _Retval to rearranged _Retval, and `resource_retval_to_arg` will
// hold mapping from DT_RESOURCE _Retval index to its input _Arg index. Here we
// assume that all DT_RESOURCE _Retval nodes come from _Arg nodes directly.
Given all _Retval nodes in the function, return if we need to rewrite the
function (by checking if we have DT_RESOURCE return values). If we need to
rewrite the function, `retval_index_mapping` will hold the mapping from
original _Retval to rearranged _Retval, and `resource_retval_to_arg` will
hold mapping from DT_RESOURCE _Retval index to its input _Arg index. Here we
assume that all DT_RESOURCE _Retval nodes come from _Arg nodes directly.
Given all _Retval nodes in the function return if we need to rewrite the function ( by checking if we have DT_RESOURCE return values ) . If we need to rewrite the function ` retval_index_mapping ` will hold the mapping from original _Retval to rearranged _Retval and ` resource_retval_to_arg ` will hold mapping from DT_RESOURCE _Retval index to its input _Arg index . Here we assume that all DT_RESOURCE _Retval nodes come from _Arg nodes directly .
Status CalculateRetvalRearrange(
    const gtl::InlinedVector<Node*, 4>& ret_nodes,  
    std::map<int, int>* retval_index_mapping,
    std::map<int, int>* resource_retval_to_arg) {
  for (int i = 0, end = ret_nodes.size(); i < end; i++) {
    Node* n = ret_nodes[i];
    DataType t;
    TF_RETURN_IF_ERROR(GetNodeAttr(n->def(), "T", &t));
    if (t != DT_RESOURCE) {
      int new_retval_index = retval_index_mapping->size();
      retval_index_mapping->insert(std::make_pair(i, new_retval_index));
      continue;
    }
    const Edge* e;
    TF_RETURN_IF_ERROR(n->input_edge(0, &e));
    if (!e->src()->IsArg()) {
      return errors::Unimplemented(
          "Resource _Retval node's input does not come from _Arg "
          "directly: ",
          e->DebugString());
    }
    Node* arg = e->src();
    int src_index;
    TF_RETURN_IF_ERROR(GetNodeAttr(arg->def(), "index", &src_index));
    resource_retval_to_arg->insert(std::make_pair(i, src_index));
  }
  return Status::OK();
}
Status CalculateRetvalRearrange ( const gtl :: InlinedVector < Node * , 4 > & ret_nodes , std :: map < int , int > * retval_index_mapping , std :: map < int , int > * resource_retval_to_arg ) { for ( int i = 0 , end = ret_nodes . size ( ) ; i < end ; i ++ ) { Node * n = ret_nodes [ i ] ; DataType t ; TF_RETURN_IF_ERROR ( GetNodeAttr ( n -> def ( ) , " " , & t ) ) ; if ( t != DT_RESOURCE ) { int new_retval_index = retval_index_mapping -> size ( ) ; retval_index_mapping -> insert ( std :: make_pair ( i , new_retval_index ) ) ; continue ; } const Edge * e ; TF_RETURN_IF_ERROR ( n -> input_edge ( 0 , & e ) ) ; if ( ! e -> src ( ) -> IsArg ( ) ) { return errors :: Unimplemented ( " " " " , e -> DebugString ( ) ) ; } Node * arg = e -> src ( ) ; int src_index ; TF_RETURN_IF_ERROR ( GetNodeAttr ( arg -> def ( ) , " " , & src_index ) ) ; resource_retval_to_arg -> insert ( std :: make_pair ( i , src_index ) ) ; } return Status :: OK ( ) ; }
Given all _Retval nodes in the function, return if we need to rewrite the
function (by checking if we have DT_RESOURCE return values).
Given all _Retval nodes in the function return if we need to rewrite the function ( by checking if we have DT_RESOURCE return values ) .
// non-absl ok