tensorflow/compiler/aot/codegen.cc
// Add (from,to) rewrite pairs based on the given shape.  These rewrite pairs
// are used to generate methods for args and results.
Add (from,to) rewrite pairs based on the given shape.  These rewrite pairs
are used to generate methods for args and results.
Add ( from to ) rewrite pairs based on the given shape . These rewrite pairs are used to generate methods for args and results .
Status AddRewritesForShape(int i, const xla::Shape& shape,
                           std::vector<std::pair<string, string>>* rewrites) {
  string type;
  TF_RETURN_IF_ERROR(XLATypeToCpp(shape.element_type(), &type));
  std::vector<string> dim_vars;
  string dim_sizes, indices;
  int count = 1;
  if (shape.rank() == 0 ||
      (shape.dimensions_size() == 1 && shape.dimensions(0) == 1)) {
    dim_sizes = "[1]";
    indices = "[0]";
  } else {
    for (int dim = 0; dim < shape.dimensions_size(); ++dim) {
      dim_vars.push_back(absl::StrCat("size_t dim", dim));
      dim_sizes += absl::StrCat("[", shape.dimensions(dim), "]");
      indices += absl::StrCat("[dim", dim, "]");
      count *= shape.dimensions(dim);
    }
  }
  rewrites->push_back({"{{I}}", absl::StrCat(i)});
  rewrites->push_back({"{{TYPE}}", type});
  rewrites->push_back({"{{DIM_VARS}}", absl::StrJoin(dim_vars, ", ")});
  rewrites->push_back({"{{DIM_SIZES}}", dim_sizes});
  rewrites->push_back({"{{INDICES}}", indices});
  rewrites->push_back({"{{COUNT}}", absl::StrCat(count)});
  return Status::OK();
}
Status AddRewritesForShape ( int i , const xla :: Shape & shape , std :: vector < std :: pair < string , string > > * rewrites ) { string type ; TF_RETURN_IF_ERROR ( XLATypeToCpp ( shape . element_type ( ) , & type ) ) ; std :: vector < string > dim_vars ; string dim_sizes , indices ; int count = 1 ; if ( shape . rank ( ) == 0 || ( shape . dimensions_size ( ) == 1 && shape . dimensions ( 0 ) == 1 ) ) { dim_sizes = " " ; indices = " " ; } else { for ( int dim = 0 ; dim < shape . dimensions_size ( ) ; ++ dim ) { dim_vars . push_back ( absl :: StrCat ( " " , dim ) ) ; dim_sizes += absl :: StrCat ( " " , shape . dimensions ( dim ) , " " ) ; indices += absl :: StrCat ( " " , dim , " " ) ; count *= shape . dimensions ( dim ) ; } } rewrites -> push_back ( { " " , absl :: StrCat ( i ) } ) ; rewrites -> push_back ( { " " , type } ) ; rewrites -> push_back ( { " " , absl :: StrJoin ( dim_vars , " " ) } ) ; rewrites -> push_back ( { " " , dim_sizes } ) ; rewrites -> push_back ( { " " , indices } ) ; rewrites -> push_back ( { " " , absl :: StrCat ( count ) } ) ; return Status :: OK ( ) ; }
Add (from,to) rewrite pairs based on the given shape.
Add ( from to ) rewrite pairs based on the given shape .