Compute Library
 22.05
arm_compute::test::detail Namespace Reference

Functions

void validate_npy_header (std::ifstream &stream, const std::string &expect_typestr, const TensorShape &expect_shape)
 
template<typename T >
std::vector< std::pair< T, T > > convert_range_pair (const std::vector< AssetsLibrary::RangePair > &excluded_range_pairs)
 

Function Documentation

◆ convert_range_pair()

std::vector<std::pair<T, T> > arm_compute::test::detail::convert_range_pair ( const std::vector< AssetsLibrary::RangePair > &  excluded_range_pairs)
inline

Definition at line 481 of file AssetsLibrary.h.

References validate_npy_header().

482 {
483  std::vector<std::pair<T, T>> converted;
484  std::transform(excluded_range_pairs.begin(),
485  excluded_range_pairs.end(),
486  std::back_inserter(converted),
487  [](const AssetsLibrary::RangePair & p)
488  {
489  return std::pair<T, T>(static_cast<T>(p.first), static_cast<T>(p.second));
490  });
491  return converted;
492 }

◆ validate_npy_header()

void validate_npy_header ( std::ifstream &  stream,
const std::string &  expect_typestr,
const TensorShape expect_shape 
)
inline

Definition at line 522 of file AssetsLibrary.cpp.

References ARM_COMPUTE_ERROR_ON_MSG, ARM_COMPUTE_UNUSED, arm_compute::mlgo::parser::header(), Dimensions< T >::num_dimensions(), and arm_compute::test::validation::shape.

Referenced by convert_range_pair(), and AssetsLibrary::fill_layer_data().

523 {
524  ARM_COMPUTE_UNUSED(expect_typestr);
525  ARM_COMPUTE_UNUSED(expect_shape);
526 
527  std::string header = npy::read_header(stream);
528 
529  // Parse header
530  std::vector<unsigned long> shape;
531  bool fortran_order = false;
532  std::string typestr;
533  npy::parse_header(header, typestr, fortran_order, shape);
534 
535  // Check if the typestring matches the given one
536  ARM_COMPUTE_ERROR_ON_MSG(typestr != expect_typestr, "Typestrings mismatch");
537 
538  // Validate tensor shape
539  ARM_COMPUTE_ERROR_ON_MSG(shape.size() != expect_shape.num_dimensions(), "Tensor ranks mismatch");
540  if(fortran_order)
541  {
542  for(size_t i = 0; i < shape.size(); ++i)
543  {
544  ARM_COMPUTE_ERROR_ON_MSG(expect_shape[i] != shape[i], "Tensor dimensions mismatch");
545  }
546  }
547  else
548  {
549  for(size_t i = 0; i < shape.size(); ++i)
550  {
551  ARM_COMPUTE_ERROR_ON_MSG(expect_shape[i] != shape[shape.size() - i - 1], "Tensor dimensions mismatch");
552  }
553  }
554 }
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
void header(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:481