62 return *
reinterpret_cast<const uint8_t *
>(ptr);
64 return *
reinterpret_cast<const int8_t *
>(ptr);
66 return *
reinterpret_cast<const uint16_t *
>(ptr);
68 return *
reinterpret_cast<const int16_t *
>(ptr);
70 return *
reinterpret_cast<const uint32_t *
>(ptr);
72 return *
reinterpret_cast<const int32_t *
>(ptr);
74 return *
reinterpret_cast<const uint64_t *
>(ptr);
76 return *
reinterpret_cast<const int64_t *
>(ptr);
78 return *
reinterpret_cast<const half *
>(ptr);
80 return *
reinterpret_cast<const float *
>(ptr);
82 return *
reinterpret_cast<const double *
>(ptr);
84 return *
reinterpret_cast<const size_t *
>(ptr);
90 void check_border_element(
const IAccessor &tensor,
const Coordinates &
id,
91 const BorderMode &border_mode,
const void *border_value,
92 int64_t &num_elements, int64_t &num_mismatches)
95 const auto ptr =
static_cast<const uint8_t *
>(tensor(
id));
99 Coordinates border_id{
id };
105 else if(static_cast<size_t>(
id.x()) >= tensor.shape().x())
107 border_id.set(0, tensor.shape().x() - 1);
114 else if(static_cast<size_t>(
id.y()) >= tensor.shape().y())
116 border_id.set(1, tensor.shape().y() - 1);
119 border_value = tensor(border_id);
123 for(
int channel = 0; channel < tensor.num_channels(); ++channel)
125 const size_t channel_offset = channel * channel_size;
126 const double target = get_double_data(ptr + channel_offset, tensor.data_type());
127 const double reference = get_double_data(static_cast<const uint8_t *>(border_value) + channel_offset, tensor.data_type());
129 if(!
compare<AbsoluteTolerance<double>>(target, reference))
181 int64_t num_mismatches = 0;
182 int64_t num_elements = 0;
186 const uint32_t tensor_num_elements = tensor.
num_elements();
187 for(uint32_t element_idx = 0; element_idx < tensor_num_elements; ++element_idx)
191 const auto ptr =
static_cast<const uint8_t *
>(tensor(
id));
194 for(
int channel = 0; channel < tensor.
num_channels(); ++channel)
196 const size_t channel_offset = channel * channel_size;
197 const double target = get_double_data(ptr + channel_offset, tensor.
data_type());
198 const double reference = get_double_data(reference_value, tensor.
data_type());
217 const float percent_mismatches =
static_cast<float>(num_mismatches) / num_elements * 100.f;
219 ARM_COMPUTE_TEST_INFO(num_mismatches <<
" values (" << std::fixed << std::setprecision(2) << percent_mismatches <<
"%) mismatched");
235 int64_t num_mismatches = 0;
236 int64_t num_elements = 0;
237 const int slice_size = tensor.
shape()[0] * tensor.
shape()[1];
239 for(
int element_idx = 0; element_idx < tensor.
num_elements(); element_idx += slice_size)
244 for(
int y = -border_size.
top; y < 0; ++y)
248 for(
int x = -border_size.
left; x < static_cast<int>(tensor.
shape()[0]) + static_cast<int>(border_size.
right); ++x)
252 check_border_element(tensor,
id, border_mode, border_value, num_elements, num_mismatches);
257 for(
int y = tensor.
shape()[1]; y < static_cast<int>(tensor.
shape()[1]) + static_cast<int>(border_size.
bottom); ++y)
261 for(
int x = -border_size.
left; x < static_cast<int>(tensor.
shape()[0]) + static_cast<int>(border_size.
right); ++x)
265 check_border_element(tensor,
id, border_mode, border_value, num_elements, num_mismatches);
270 for(
int y = 0; y < static_cast<int>(tensor.
shape()[1]); ++y)
275 for(
int x = -border_size.
left; x < 0; ++x)
279 check_border_element(tensor,
id, border_mode, border_value, num_elements, num_mismatches);
283 for(
int x = tensor.
shape()[0]; x < static_cast<int>(tensor.
shape()[0]) + static_cast<int>(border_size.
right); ++x)
287 check_border_element(tensor,
id, border_mode, border_value, num_elements, num_mismatches);
294 const float percent_mismatches =
static_cast<float>(num_mismatches) / num_elements * 100.f;
296 ARM_COMPUTE_TEST_INFO(num_mismatches <<
" values (" << std::fixed << std::setprecision(2) << percent_mismatches <<
"%) mismatched");
301 void validate(std::vector<unsigned int> classified_labels, std::vector<unsigned int> expected_labels)
305 int64_t num_mismatches = 0;
306 const int num_elements = std::min(classified_labels.size(), expected_labels.size());
308 for(
int i = 0; i < num_elements; ++i)
310 if(classified_labels[i] != expected_labels[i])
319 const float percent_mismatches =
static_cast<float>(num_mismatches) / num_elements * 100.f;
321 ARM_COMPUTE_TEST_INFO(num_mismatches <<
" values (" << std::fixed << std::setprecision(2) << percent_mismatches <<
"%) mismatched");
BorderMode
Methods available to handle borders.
void set(size_t dimension, T value, bool increase_dim_unit=true)
Accessor to set the value of one of the dimensions.
unsigned int top
top of the border
Class reprensenting an absolute tolerance value.
TensorShape shape
Shape of the valid region.
Container for 2D border size.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
1 channel, 1 U8 per channel
size_t element_size_from_data_type(DataType dt)
The size in bytes of the data type.
half_float::half half
16-bit floating point type
1 channel, 1 F32 per channel
1 channel, 1 U16 per channel
unsigned int bottom
bottom of the border
#define ARM_COMPUTE_EXPECT_EQUAL(X, Y, LEVEL)
virtual TensorShape shape() const =0
Shape of the tensor.
#define ARM_COMPUTE_TEST_INFO(INFO)
Copyright (c) 2017-2021 Arm Limited.
SimpleTensor< uint8_t > compare(ComparisonOperation op, const SimpleTensor< T > &src1, const SimpleTensor< T > &src2)
1 channel, 1 F16 per channel
1 channel, 1 S32 per channel
1 channel, 1 U32 per channel
validate(CLAccessor(output_state), expected_output)
virtual int num_elements() const =0
Number of elements of the tensor.
Coordinates index2coord(const TensorShape &shape, int index)
Convert a linear index into n-dimensional coordinates.
unsigned int left
left of the border
unsigned int right
right of the border
1 channel, 1 S16 per channel
virtual DataType data_type() const =0
Data type of the tensor.
Borders are left undefined.
Pixels outside the image are assumed to have the same value as the closest image pixel.
Common interface to provide information and access to tensor like structures.
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
#define ARM_COMPUTE_ASSERT(cond)
64-bit floating-point number
Container for valid region of a window.
virtual int num_channels() const =0
Number of channels of the tensor.
DataType
Available data types.
Coordinates anchor
Anchor for the start of the valid region.