tensorflow/lite/experimental/resource/resource_variable_test.cc
// Helper util that initialize 'tensor'.
Helper util that initialize 'tensor'.
Helper util that initialize ' tensor ' .
void InitTensor(const std::vector<int>& shape, TfLiteAllocationType alloc_type,
                float default_value, TfLiteTensor* tensor) {
  memset(tensor, 0, sizeof(TfLiteTensor));
  int num_elements = 1;
  for (auto dim : shape) num_elements *= dim;
  if (shape.empty()) num_elements = 0;
  float* buf = static_cast<float*>(malloc(sizeof(float) * num_elements));
  for (int i = 0; i < num_elements; ++i) buf[i] = default_value;
  const int bytes = num_elements * sizeof(buf[0]);
  auto* dims = ConvertArrayToTfLiteIntArray(shape.size(), shape.data());
  TfLiteTensorReset(TfLiteType::kTfLiteFloat32, nullptr, dims, {},
                    reinterpret_cast<char*>(buf), bytes, alloc_type, nullptr,
                    false, tensor);
}
void InitTensor ( const std :: vector < int > & shape , TfLiteAllocationType alloc_type , float default_value , TfLiteTensor * tensor ) { memset ( tensor , 0 , sizeof ( TfLiteTensor ) ) ; int num_elements = 1 ; for ( auto dim : shape ) num_elements *= dim ; if ( shape . empty ( ) ) num_elements = 0 ; float * buf = static_cast < float * > ( malloc ( sizeof ( float ) * num_elements ) ) ; for ( int i = 0 ; i < num_elements ; ++ i ) buf [ i ] = default_value ; const int bytes = num_elements * sizeof ( buf [ 0 ] ) ; auto * dims = ConvertArrayToTfLiteIntArray ( shape . size ( ) , shape . data ( ) ) ; TfLiteTensorReset ( TfLiteType :: kTfLiteFloat32 , nullptr , dims , { } , reinterpret_cast < char * > ( buf ) , bytes , alloc_type , nullptr , false , tensor ) ; }
Helper util that initialize 'tensor'.
Helper util that initialize ' tensor ' .