24 #ifndef ARM_COMPUTE_TEST_VALIDATION_H 25 #define ARM_COMPUTE_TEST_VALIDATION_H 75 constexpr
operator T()
const 121 template <
typename T>
124 os << static_cast<typename AbsoluteTolerance<T>::value_type>(tolerance);
130 template <
typename T>
133 os << static_cast<typename RelativeTolerance<T>::value_type>(tolerance);
138 template <
typename T>
152 if(dimensions1[i] != dimensions2[i])
163 for(
unsigned int i = 3; i < max_dims; ++i)
165 if(dimensions1[i] != dimensions2[i])
172 if((dimensions1[0] != dimensions2[2]) || (dimensions1[1] != dimensions2[0]) || (dimensions1[2] != dimensions2[1]))
211 template <
typename T,
typename U = AbsoluteTolerance<T>>
212 void validate(
const IAccessor &tensor,
const SimpleTensor<T> &reference, U tolerance_value =
U(),
float tolerance_number = 0.f,
float absolute_tolerance_value = 0.f);
224 template <
typename T,
typename U = AbsoluteTolerance<T>>
237 template <
typename T,
typename U = AbsoluteTolerance<T>>
239 float absolute_tolerance_value = 0.f);
259 void validate(std::vector<unsigned int> classified_labels, std::vector<unsigned int> expected_labels);
265 template <
typename T,
typename U = AbsoluteTolerance<T>>
266 bool validate(T target, T reference, U tolerance = AbsoluteTolerance<T>());
268 template <
typename T>
277 compare_base(
typename T::value_type target,
typename T::value_type reference, T tolerance = T(0))
287 template <
typename T>
291 template <
typename U>
297 operator bool()
const 303 else if(this->_target == this->_reference)
308 using comparison_type =
typename std::conditional<std::is_integral<U>::value, int64_t,
U>
::type;
310 const comparison_type abs_difference(std::abs(static_cast<comparison_type>(this->_target) - static_cast<comparison_type>(this->_reference)));
312 return abs_difference <= static_cast<comparison_type>(this->_tolerance);
317 template <
typename U>
323 operator bool()
const 329 else if(this->_target == this->_reference)
336 if(std::abs(static_cast<double>(this->_reference) - static_cast<double>(this->_target)) <=
epsilon)
342 if(static_cast<double>(this->_reference) == 0.0f)
347 const double relative_change = std::abs((static_cast<double>(this->_target) - static_cast<double>(this->_reference)) / this->_reference);
349 return relative_change <= static_cast<U>(this->_tolerance);
354 template <
typename T,
typename U>
361 template <typename T, typename U, typename = typename std::enable_if<std::is_integral<T>::value>
::type>
368 template <
typename T,
typename U>
376 uint64_t num_mismatches = 0;
377 uint64_t num_elements = 0;
394 for(
int element_idx = 0; element_idx < min_elements; ++element_idx)
407 for(
int c = 0; c < min_channels; ++c)
409 const T &target_value = reinterpret_cast<const T *>(tensor(target_id))[c];
410 const T &reference_value = reinterpret_cast<const T *>(reference(
id))[c];
412 if(!
compare<U>(target_value, reference_value, tolerance_value))
414 if(absolute_tolerance_value != 0.f)
437 if(num_elements != 0)
439 const uint64_t absolute_tolerance_number = tolerance_number * num_elements;
440 const float percent_mismatches = static_cast<float>(num_mismatches) / num_elements * 100.f;
442 ARM_COMPUTE_TEST_INFO(num_mismatches <<
" values (" << std::fixed << std::setprecision(2) << percent_mismatches
443 <<
"%) mismatched (maximum tolerated " << std::setprecision(2) << tolerance_number * 100 <<
"%)");
448 template <typename T, typename U, typename = typename std::enable_if<std::is_integral<T>::value>
::type>
456 uint64_t num_mismatches = 0;
457 uint64_t num_elements = 0;
474 for(
int element_idx = 0; element_idx < min_elements; ++element_idx)
487 for(
int c = 0; c < min_channels; ++c)
489 const T &target_value = reinterpret_cast<const T *>(tensor(target_id))[c];
490 const T &reference_value = reinterpret_cast<const T *>(reference(
id))[c];
492 bool equal =
compare<U>(target_value, reference_value, tolerance_value);
505 uint64_t max = std::numeric_limits<limits_type>::max();
506 uint64_t abs_sum = std::abs(static_cast<int64_t>(target_value)) + std::abs(static_cast<int64_t>(reference_value));
507 uint64_t wrap_difference = max - abs_sum;
509 equal = wrap_difference < static_cast<uint64_t>(tolerance_value);
530 if(num_elements != 0)
532 const uint64_t absolute_tolerance_number = tolerance_number * num_elements;
533 const float percent_mismatches = static_cast<float>(num_mismatches) / num_elements * 100.f;
535 ARM_COMPUTE_TEST_INFO(num_mismatches <<
" values (" << std::fixed << std::setprecision(2) << percent_mismatches
536 <<
"%) mismatched (maximum tolerated " << std::setprecision(2) << tolerance_number * 100 <<
"%)");
541 template <
typename T,
typename U>
549 uint64_t num_mismatches = 0;
550 uint64_t num_elements = 0;
567 for(
int element_idx = 0; element_idx < min_elements; ++element_idx)
577 if(valid_mask[element_idx] == 1)
580 for(
int c = 0; c < min_channels; ++c)
582 const T &target_value = reinterpret_cast<const T *>(tensor(target_id))[c];
583 const T &reference_value = reinterpret_cast<const T *>(reference(
id))[c];
585 if(!
compare<U>(target_value, reference_value, tolerance_value))
587 if(absolute_tolerance_value != 0.f)
614 if(num_elements != 0)
616 const uint64_t absolute_tolerance_number = tolerance_number * num_elements;
617 const float percent_mismatches = static_cast<float>(num_mismatches) / num_elements * 100.f;
619 ARM_COMPUTE_TEST_INFO(num_mismatches <<
" values (" << std::fixed << std::setprecision(2) << percent_mismatches
620 <<
"%) mismatched (maximum tolerated " << std::setprecision(2) << tolerance_number * 100 <<
"%)");
625 template <
typename T,
typename U>
637 const bool equal =
compare<U>(target, reference, tolerance);
644 template <
typename T,
typename U>
658 for(uint32_t i = 0; i < target.
min_loc.size(); ++i)
662 return coord.x == target.
min_loc.at(i).x && coord.y == target.
min_loc.at(i).y;
668 for(uint32_t i = 0; i < target.
max_loc.size(); ++i)
672 return coord.x == target.
max_loc.at(i).x && coord.y == target.
max_loc.at(i).y;
constexpr AbsoluteTolerance(T value)
Constructor.
BorderMode
Methods available to handle borders.
U value_type
Underlying type.
size_t element_size() const override
Size of each element in the tensor in bytes.
Class reprensenting an absolute tolerance value.
std::vector< Coordinates2D > min_loc
Min value location.
virtual Format format() const =0
Image format of the tensor.
Container for 2D border size.
int make_printable(int8_t value)
Format format() const override
Image format of the tensor.
DataType data_type() const override
Data type of the tensor.
ARM_COMPUTE_EXPECT(has_error==expected, framework::LogLevel::ERRORS)
T::value_type _reference
Reference value.
Strides PermutationVector
Permutation vector.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
const DataLayout data_layout
compare_base(typename T::value_type target, typename T::value_type reference, T tolerance=T(0))
Construct a comparison object.
TensorShape shape() const override
Shape of the tensor.
bool compare_dimensions(const Dimensions< T > &dimensions1, const Dimensions< T > &dimensions2, const DataLayout &data_layout=DataLayout::NCHW)
const ValidRegion valid_region
decltype(strategy::transforms) typedef type
#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.
static Framework & get()
Access to the singleton.
U value_type
Underlying type.
void permute(Dimensions< T > &dimensions, const PermutationVector &perm)
Permutes given Dimensions according to a permutation vector.
T _tolerance
Tolerance value.
void validate_min_max_loc(const MinMaxLocationValues< T > &target, const MinMaxLocationValues< U > &reference)
RelativeTolerance()=default
bool is_in_valid_region(const ValidRegion &valid_region, Coordinates coord)
Check if a coordinate is within a valid region.
Dimensions with dimensionality.
Min and max values and locations.
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.
virtual DataLayout data_layout() const =0
Data layout of the tensor.
Num samples, channels, height, width.
void ARM_COMPUTE_PRINT_INFO()
Simple tensor object that stores elements in a consecutive chunk of memory.
int num_channels() const override
Number of channels of the tensor.
T::value_type _target
Target value.
Class reprensenting a relative tolerance value.
virtual DataType data_type() const =0
Data type of the tensor.
Common interface to provide information and access to tensor like structures.
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
Num samples, height, width, channels.
int num_elements() const override
Number of elements of the tensor.
virtual size_t element_size() const =0
Size of each element in the tensor in bytes.
constexpr RelativeTolerance(value_type value)
Constructor.
Container for valid region of a window.
virtual int num_channels() const =0
Number of channels of the tensor.
DataLayout
[DataLayout enum definition]
ValidRegion shape_to_valid_region(const TensorShape &a_shape, bool border_undefined=false, BorderSize border_size=BorderSize(0))
Create a valid region based on tensor shape, border mode and border size.
inline ::std::ostream & operator<<(::std::ostream &os, const AbsoluteTolerance< T > &tolerance)
Print AbsoluteTolerance type.
void validate_wrap(const IAccessor &tensor, const SimpleTensor< T > &reference, U tolerance_value, float tolerance_number)
std::vector< Coordinates2D > max_loc
Max value location.
AbsoluteTolerance()=default