Compute Library
 21.08
RandomAccessor Class Referencefinal

Random accessor class. More...

#include <GraphUtils.h>

Collaboration diagram for RandomAccessor:
[legend]

Public Member Functions

 RandomAccessor (PixelValue lower, PixelValue upper, const std::random_device::result_type seed=0)
 Constructor. More...
 
 RandomAccessor (RandomAccessor &&)=default
 Allows instances to move constructed. More...
 
bool access_tensor (ITensor &tensor) override
 Interface to be implemented to access a given tensor. More...
 
- Public Member Functions inherited from ITensorAccessor
virtual ~ITensorAccessor ()=default
 Default virtual destructor. More...
 

Detailed Description

Random accessor class.

Definition at line 406 of file GraphUtils.h.

Constructor & Destructor Documentation

◆ RandomAccessor() [1/2]

RandomAccessor ( PixelValue  lower,
PixelValue  upper,
const std::random_device::result_type  seed = 0 
)

Constructor.

Parameters
[in]lowerLower bound value.
[in]upperUpper bound value.
[in]seed(Optional) Seed used to initialise the random number generator.

Definition at line 661 of file GraphUtils.cpp.

References ITensor::buffer(), arm_compute::test::validation::distribution(), ITensorInfo::element_size(), BorderSize::empty(), arm_compute::execute_window_loop(), ITensor::info(), offset(), ITensorInfo::padding(), ITensor::ptr_to_element(), ITensorInfo::tensor_shape(), ITensorInfo::total_size(), and Window::use_tensor_dimensions().

662  : _lower(lower), _upper(upper), _seed(seed)
663 {
664 }

◆ RandomAccessor() [2/2]

RandomAccessor ( RandomAccessor &&  )
default

Allows instances to move constructed.

Member Function Documentation

◆ access_tensor()

bool access_tensor ( ITensor tensor)
overridevirtual

Interface to be implemented to access a given tensor.

Parameters
[in]tensorTensor to be accessed
Returns
True if access is successful else false

Implements ITensorAccessor.

Definition at line 693 of file GraphUtils.cpp.

References ARM_COMPUTE_ERROR, ITensorInfo::data_type(), arm_compute::F16, arm_compute::F32, arm_compute::F64, PixelValue::get(), ITensor::info(), arm_compute::QASYMM8, arm_compute::S16, arm_compute::S32, arm_compute::S64, arm_compute::S8, arm_compute::U16, arm_compute::U32, arm_compute::U64, and arm_compute::U8.

694 {
695  switch(tensor.info()->data_type())
696  {
697  case DataType::QASYMM8:
698  case DataType::U8:
699  {
700  std::uniform_int_distribution<uint8_t> distribution_u8(_lower.get<uint8_t>(), _upper.get<uint8_t>());
701  fill<uint8_t>(tensor, distribution_u8);
702  break;
703  }
704  case DataType::S8:
705  {
706  std::uniform_int_distribution<int8_t> distribution_s8(_lower.get<int8_t>(), _upper.get<int8_t>());
707  fill<int8_t>(tensor, distribution_s8);
708  break;
709  }
710  case DataType::U16:
711  {
712  std::uniform_int_distribution<uint16_t> distribution_u16(_lower.get<uint16_t>(), _upper.get<uint16_t>());
713  fill<uint16_t>(tensor, distribution_u16);
714  break;
715  }
716  case DataType::S16:
717  {
718  std::uniform_int_distribution<int16_t> distribution_s16(_lower.get<int16_t>(), _upper.get<int16_t>());
719  fill<int16_t>(tensor, distribution_s16);
720  break;
721  }
722  case DataType::U32:
723  {
724  std::uniform_int_distribution<uint32_t> distribution_u32(_lower.get<uint32_t>(), _upper.get<uint32_t>());
725  fill<uint32_t>(tensor, distribution_u32);
726  break;
727  }
728  case DataType::S32:
729  {
730  std::uniform_int_distribution<int32_t> distribution_s32(_lower.get<int32_t>(), _upper.get<int32_t>());
731  fill<int32_t>(tensor, distribution_s32);
732  break;
733  }
734  case DataType::U64:
735  {
736  std::uniform_int_distribution<uint64_t> distribution_u64(_lower.get<uint64_t>(), _upper.get<uint64_t>());
737  fill<uint64_t>(tensor, distribution_u64);
738  break;
739  }
740  case DataType::S64:
741  {
742  std::uniform_int_distribution<int64_t> distribution_s64(_lower.get<int64_t>(), _upper.get<int64_t>());
743  fill<int64_t>(tensor, distribution_s64);
744  break;
745  }
746  case DataType::F16:
747  {
748  arm_compute::utils::uniform_real_distribution_16bit<half> distribution_f16(_lower.get<float>(), _upper.get<float>());
749  fill<half>(tensor, distribution_f16);
750  break;
751  }
752  case DataType::F32:
753  {
754  std::uniform_real_distribution<float> distribution_f32(_lower.get<float>(), _upper.get<float>());
755  fill<float>(tensor, distribution_f32);
756  break;
757  }
758  case DataType::F64:
759  {
760  std::uniform_real_distribution<double> distribution_f64(_lower.get<double>(), _upper.get<double>());
761  fill<double>(tensor, distribution_f64);
762  break;
763  }
764  default:
765  ARM_COMPUTE_ERROR("NOT SUPPORTED!");
766  }
767  return true;
768 }
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
1 channel, 1 U8 per channel
void get(uint8_t &v) const
Interpret the pixel value as a U8.
Definition: PixelValue.h:244
1 channel, 1 F32 per channel
1 channel, 1 U16 per channel
1 channel, 1 F16 per channel
1 channel, 1 S32 per channel
signed 64-bit number
Specialized class to generate random non-zero FP16 values.
Definition: Utils.h:254
1 channel, 1 U32 per channel
quantized, asymmetric fixed-point 8-bit number unsigned
1 channel, 1 S16 per channel
64-bit floating-point number
unsigned 64-bit number
signed 8-bit number

The documentation for this class was generated from the following files: