24 #ifndef ARM_COMPUTE_TEST_VALIDATION_H
25 #define ARM_COMPUTE_TEST_VALIDATION_H
52 inline bool are_equal_infs(T val0, T val1)
86 constexpr
operator T()
const
132 template <
typename T>
135 os << static_cast<typename AbsoluteTolerance<T>::value_type>(tolerance);
141 template <
typename T>
144 os << static_cast<typename RelativeTolerance<T>::value_type>(tolerance);
149 template <
typename T>
163 if(dimensions1[i] != dimensions2[i])
174 for(
unsigned int i = 3; i < max_dims; ++i)
176 if(dimensions1[i] != dimensions2[i])
183 if((dimensions1[0] != dimensions2[2]) || (dimensions1[1] != dimensions2[0]) || (dimensions1[2] != dimensions2[1]))
222 template <
typename T,
typename U = AbsoluteTolerance<T>>
235 template <
typename T,
typename U = AbsoluteTolerance<T>>
248 template <
typename T,
typename U = AbsoluteTolerance<T>>
250 float absolute_tolerance_value = 0.f);
270 void validate(std::vector<unsigned int> classified_labels, std::vector<unsigned int> expected_labels);
276 template <
typename T,
typename U = AbsoluteTolerance<T>>
277 bool validate(T target, T reference, U tolerance = AbsoluteTolerance<T>());
279 template <
typename T>
288 compare_base(
typename T::value_type target,
typename T::value_type reference, T tolerance = T(0))
298 template <
typename T>
302 template <
typename U>
308 operator bool()
const
310 if(are_equal_infs(this->_target, this->_reference))
314 else if(this->_target == this->_reference)
319 using comparison_type =
typename std::conditional<std::is_integral<U>::value, int64_t,
U>
::type;
321 const comparison_type abs_difference(std::abs(
static_cast<comparison_type
>(this->_target) -
static_cast<comparison_type
>(this->_reference)));
323 return abs_difference <= static_cast<comparison_type>(this->_tolerance);
328 template <
typename U>
334 operator bool()
const
336 if(are_equal_infs(this->_target, this->_reference))
340 else if(this->_target == this->_reference)
347 if(std::abs(
static_cast<double>(this->_reference) -
static_cast<double>(this->_target)) <=
epsilon)
353 if(
static_cast<double>(this->_reference) == 0.0f)
358 const double relative_change = std::abs((
static_cast<double>(this->_target) -
static_cast<double>(this->_reference)) / this->_reference);
360 return relative_change <= static_cast<U>(this->_tolerance);
365 template <
typename T,
typename U>
372 template <typename T, typename U, typename = typename std::enable_if<std::is_integral<T>::value>
::type>
379 template <
typename T,
typename U>
387 uint64_t num_mismatches = 0;
388 uint64_t num_elements = 0;
405 for(
int element_idx = 0; element_idx < min_elements; ++element_idx)
418 for(
int c = 0; c < min_channels; ++c)
420 const T &target_value =
reinterpret_cast<const T *
>(
tensor(target_id))[c];
421 const T &reference_value =
reinterpret_cast<const T *
>(reference(
id))[c];
423 if(!
compare<U>(target_value, reference_value, tolerance_value))
425 if(absolute_tolerance_value != 0.f)
448 if(num_elements != 0)
450 const uint64_t absolute_tolerance_number = tolerance_number * num_elements;
451 const float percent_mismatches =
static_cast<float>(num_mismatches) / num_elements * 100.f;
453 ARM_COMPUTE_TEST_INFO(num_mismatches <<
" values (" << std::fixed << std::setprecision(2) << percent_mismatches
454 <<
"%) mismatched (maximum tolerated " << std::setprecision(2) << tolerance_number * 100 <<
"%)");
459 template <typename T, typename U, typename = typename std::enable_if<std::is_integral<T>::value>
::type>
467 uint64_t num_mismatches = 0;
468 uint64_t num_elements = 0;
485 for(
int element_idx = 0; element_idx < min_elements; ++element_idx)
498 for(
int c = 0; c < min_channels; ++c)
500 const T &target_value =
reinterpret_cast<const T *
>(
tensor(target_id))[c];
501 const T &reference_value =
reinterpret_cast<const T *
>(reference(
id))[c];
503 bool equal =
compare<U>(target_value, reference_value, tolerance_value);
508 if(are_equal_infs(target_value, reference_value))
516 uint64_t max = std::numeric_limits<limits_type>::max();
517 uint64_t abs_sum = std::abs(
static_cast<int64_t
>(target_value)) + std::abs(
static_cast<int64_t
>(reference_value));
518 uint64_t wrap_difference = max - abs_sum;
520 equal = wrap_difference < static_cast<uint64_t>(tolerance_value);
541 if(num_elements != 0)
543 const uint64_t absolute_tolerance_number = tolerance_number * num_elements;
544 const float percent_mismatches =
static_cast<float>(num_mismatches) / num_elements * 100.f;
546 ARM_COMPUTE_TEST_INFO(num_mismatches <<
" values (" << std::fixed << std::setprecision(2) << percent_mismatches
547 <<
"%) mismatched (maximum tolerated " << std::setprecision(2) << tolerance_number * 100 <<
"%)");
552 template <
typename T,
typename U>
560 uint64_t num_mismatches = 0;
561 uint64_t num_elements = 0;
578 for(
int element_idx = 0; element_idx < min_elements; ++element_idx)
588 if(valid_mask[element_idx] == 1)
591 for(
int c = 0; c < min_channels; ++c)
593 const T &target_value =
reinterpret_cast<const T *
>(
tensor(target_id))[c];
594 const T &reference_value =
reinterpret_cast<const T *
>(reference(
id))[c];
596 if(!
compare<U>(target_value, reference_value, tolerance_value))
598 if(absolute_tolerance_value != 0.f)
625 if(num_elements != 0)
627 const uint64_t absolute_tolerance_number = tolerance_number * num_elements;
628 const float percent_mismatches =
static_cast<float>(num_mismatches) / num_elements * 100.f;
630 ARM_COMPUTE_TEST_INFO(num_mismatches <<
" values (" << std::fixed << std::setprecision(2) << percent_mismatches
631 <<
"%) mismatched (maximum tolerated " << std::setprecision(2) << tolerance_number * 100 <<
"%)");
636 template <
typename T,
typename U>
648 const bool equal =
compare<U>(target, reference, tolerance);
655 template <
typename T,
typename U>
669 for(uint32_t i = 0; i < target.
min_loc.size(); ++i)
673 return coord.x == target.min_loc.at(i).x && coord.y == target.min_loc.at(i).y;
679 for(uint32_t i = 0; i < target.
max_loc.size(); ++i)
683 return coord.x == target.max_loc.at(i).x && coord.y == target.max_loc.at(i).y;