blob: d356f05b70a7671b52f5fe38c469cae3cf5670b0 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Giorgio Arena68e29da2021-02-08 16:31:10 +00002 * Copyright (c) 2017-2021 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_TEST_VALIDATION_H
25#define ARM_COMPUTE_TEST_VALIDATION_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +010027#include "arm_compute/core/IArray.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010028#include "arm_compute/core/Types.h"
Ioan-Cristian Szabo33fd07b2017-10-26 15:42:24 +010029#include "support/ToolchainSupport.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010030#include "tests/IAccessor.h"
31#include "tests/SimpleTensor.h"
John Richardsonf89a49f2017-09-05 11:21:56 +010032#include "tests/Types.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010033#include "tests/Utils.h"
34#include "tests/framework/Asserts.h"
35#include "tests/framework/Exceptions.h"
Anthony Barbier2a07e182017-08-04 18:20:27 +010036#include "utils/TypePrinter.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010037
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010038#include <iomanip>
39#include <ios>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010040#include <vector>
41
42namespace arm_compute
43{
Anthony Barbier6ff3b192017-09-04 18:44:23 +010044namespace test
45{
Anthony Barbier6ff3b192017-09-04 18:44:23 +010046namespace validation
47{
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010048/** Class reprensenting an absolute tolerance value. */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010049template <typename T>
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010050class AbsoluteTolerance
51{
52public:
53 /** Underlying type. */
54 using value_type = T;
55
56 /* Default constructor.
57 *
58 * Initialises the tolerance to 0.
59 */
60 AbsoluteTolerance() = default;
61
62 /** Constructor.
63 *
64 * @param[in] value Absolute tolerance value.
65 */
66 explicit constexpr AbsoluteTolerance(T value)
67 : _value{ value }
68 {
69 }
70
Alex Gildayc357c472018-03-21 13:54:09 +000071 /** Implicit conversion to the underlying type.
72 *
73 * @return the underlying type.
74 */
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010075 constexpr operator T() const
76 {
77 return _value;
78 }
79
80private:
81 T _value{ std::numeric_limits<T>::epsilon() };
82};
83
84/** Class reprensenting a relative tolerance value. */
steniu013e05e4e2017-08-25 17:18:01 +010085template <typename T>
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010086class RelativeTolerance
87{
88public:
89 /** Underlying type. */
steniu013e05e4e2017-08-25 17:18:01 +010090 using value_type = T;
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010091
92 /* Default constructor.
93 *
94 * Initialises the tolerance to 0.
95 */
96 RelativeTolerance() = default;
97
98 /** Constructor.
99 *
100 * @param[in] value Relative tolerance value.
101 */
102 explicit constexpr RelativeTolerance(value_type value)
103 : _value{ value }
104 {
105 }
106
Alex Gildayc357c472018-03-21 13:54:09 +0000107 /** Implicit conversion to the underlying type.
108 *
109 * @return the underlying type.
110 */
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100111 constexpr operator value_type() const
112 {
113 return _value;
114 }
115
116private:
steniu013e05e4e2017-08-25 17:18:01 +0100117 value_type _value{ std::numeric_limits<T>::epsilon() };
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100118};
119
120/** Print AbsoluteTolerance type. */
121template <typename T>
122inline ::std::ostream &operator<<(::std::ostream &os, const AbsoluteTolerance<T> &tolerance)
123{
124 os << static_cast<typename AbsoluteTolerance<T>::value_type>(tolerance);
125
126 return os;
127}
128
129/** Print RelativeTolerance type. */
steniu013e05e4e2017-08-25 17:18:01 +0100130template <typename T>
131inline ::std::ostream &operator<<(::std::ostream &os, const RelativeTolerance<T> &tolerance)
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100132{
steniu013e05e4e2017-08-25 17:18:01 +0100133 os << static_cast<typename RelativeTolerance<T>::value_type>(tolerance);
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100134
135 return os;
136}
137
138template <typename T>
Giorgio Arena563494c2018-04-30 17:29:41 +0100139bool compare_dimensions(const Dimensions<T> &dimensions1, const Dimensions<T> &dimensions2, const DataLayout &data_layout = DataLayout::NCHW)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100140{
Giorgio Arena563494c2018-04-30 17:29:41 +0100141 ARM_COMPUTE_ERROR_ON(data_layout == DataLayout::UNKNOWN);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100142
Giorgio Arena563494c2018-04-30 17:29:41 +0100143 if(data_layout == DataLayout::NCHW)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100144 {
Giorgio Arena563494c2018-04-30 17:29:41 +0100145 if(dimensions1.num_dimensions() != dimensions2.num_dimensions())
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100146 {
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100147 return false;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100148 }
Giorgio Arena563494c2018-04-30 17:29:41 +0100149
150 for(unsigned int i = 0; i < dimensions1.num_dimensions(); ++i)
151 {
152 if(dimensions1[i] != dimensions2[i])
153 {
154 return false;
155 }
156 }
157 }
158 else
159 {
160 // In case a 2D shape becomes 3D after permutation, the permuted tensor will have one dimension more and the first value will be 1
161 if((dimensions1.num_dimensions() != dimensions2.num_dimensions()) && ((dimensions1.num_dimensions() != (dimensions2.num_dimensions() + 1)) || (dimensions1.x() != 1)))
162 {
163 return false;
164 }
165
166 if((dimensions1[0] != dimensions2[2]) || (dimensions1[1] != dimensions2[0]) || (dimensions1[2] != dimensions2[1]))
167 {
168 return false;
169 }
170
171 for(unsigned int i = 3; i < dimensions1.num_dimensions(); ++i)
172 {
173 if(dimensions1[i] != dimensions2[i])
174 {
175 return false;
176 }
177 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100178 }
179
180 return true;
181}
182
183/** Validate valid regions.
184 *
185 * - Dimensionality has to be the same.
186 * - Anchors have to match.
187 * - Shapes have to match.
188 */
189void validate(const arm_compute::ValidRegion &region, const arm_compute::ValidRegion &reference);
190
191/** Validate padding.
192 *
193 * Padding on all sides has to be the same.
194 */
195void validate(const arm_compute::PaddingSize &padding, const arm_compute::PaddingSize &reference);
196
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000197/** Validate padding.
198 *
199 * Padding on all sides has to be the same.
200 */
201void validate(const arm_compute::PaddingSize &padding, const arm_compute::PaddingSize &width_reference, const arm_compute::PaddingSize &height_reference);
202
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100203/** Validate tensors.
204 *
205 * - Dimensionality has to be the same.
206 * - All values have to match.
207 *
208 * @note: wrap_range allows cases where reference tensor rounds up to the wrapping point, causing it to wrap around to
209 * zero while the test tensor stays at wrapping point to pass. This may permit true erroneous cases (difference between
210 * reference tensor and test tensor is multiple of wrap_range), but such errors would be detected by
211 * other test cases.
212 */
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100213template <typename T, typename U = AbsoluteTolerance<T>>
Michele Di Giorgioff6c2602018-02-26 15:22:16 +0000214void validate(const IAccessor &tensor, const SimpleTensor<T> &reference, U tolerance_value = U(), float tolerance_number = 0.f, float absolute_tolerance_value = 0.f);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100215
216/** Validate tensors with valid region.
217 *
218 * - Dimensionality has to be the same.
219 * - All values have to match.
220 *
221 * @note: wrap_range allows cases where reference tensor rounds up to the wrapping point, causing it to wrap around to
222 * zero while the test tensor stays at wrapping point to pass. This may permit true erroneous cases (difference between
223 * reference tensor and test tensor is multiple of wrap_range), but such errors would be detected by
224 * other test cases.
225 */
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100226template <typename T, typename U = AbsoluteTolerance<T>>
Michele Di Giorgioff6c2602018-02-26 15:22:16 +0000227void validate(const IAccessor &tensor, const SimpleTensor<T> &reference, const ValidRegion &valid_region, U tolerance_value = U(), float tolerance_number = 0.f, float absolute_tolerance_value = 0.f);
Isabella Gottardi62031532017-07-04 11:21:28 +0100228
Isabella Gottardi83be7452017-08-29 13:47:03 +0100229/** Validate tensors with valid mask.
230 *
231 * - Dimensionality has to be the same.
232 * - All values have to match.
233 *
234 * @note: wrap_range allows cases where reference tensor rounds up to the wrapping point, causing it to wrap around to
235 * zero while the test tensor stays at wrapping point to pass. This may permit true erroneous cases (difference between
236 * reference tensor and test tensor is multiple of wrap_range), but such errors would be detected by
237 * other test cases.
238 */
239template <typename T, typename U = AbsoluteTolerance<T>>
Michele Di Giorgioff6c2602018-02-26 15:22:16 +0000240void validate(const IAccessor &tensor, const SimpleTensor<T> &reference, const SimpleTensor<T> &valid_mask, U tolerance_value = U(), float tolerance_number = 0.f,
241 float absolute_tolerance_value = 0.f);
Isabella Gottardi83be7452017-08-29 13:47:03 +0100242
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100243/** Validate tensors against constant value.
244 *
245 * - All values have to match.
246 */
247void validate(const IAccessor &tensor, const void *reference_value);
248
249/** Validate border against a constant value.
250 *
251 * - All border values have to match the specified value if mode is CONSTANT.
252 * - All border values have to be replicated if mode is REPLICATE.
253 * - Nothing is validated for mode UNDEFINED.
254 */
255void validate(const IAccessor &tensor, BorderSize border_size, const BorderMode &border_mode, const void *border_value);
256
257/** Validate classified labels against expected ones.
258 *
259 * - All values should match
260 */
261void validate(std::vector<unsigned int> classified_labels, std::vector<unsigned int> expected_labels);
steniu01960b0842017-06-23 11:44:34 +0100262
263/** Validate float value.
264 *
265 * - All values should match
266 */
Moritz Pflanzer7655a672017-09-23 11:57:33 +0100267template <typename T, typename U = AbsoluteTolerance<T>>
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +0100268bool validate(T target, T reference, U tolerance = AbsoluteTolerance<T>());
269
270/** Validate key points. */
271template <typename T, typename U, typename V = AbsoluteTolerance<float>>
Georgios Pinitas5962f132017-12-11 16:59:29 +0000272void validate_keypoints(T target_first, T target_last, U reference_first, U reference_last, V tolerance = AbsoluteTolerance<float>(),
273 float allowed_missing_percentage = 5.f, float allowed_mismatch_percentage = 5.f);
steniu01960b0842017-06-23 11:44:34 +0100274
John Richardson684cb0f2018-01-09 11:17:00 +0000275/** Validate detection windows. */
276template <typename T, typename U, typename V = AbsoluteTolerance<float>>
277void validate_detection_windows(T target_first, T target_last, U reference_first, U reference_last, V tolerance = AbsoluteTolerance<float>(),
278 float allowed_missing_percentage = 5.f, float allowed_mismatch_percentage = 5.f);
279
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100280template <typename T>
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100281struct compare_base
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100282{
Alex Gildayc357c472018-03-21 13:54:09 +0000283 /** Construct a comparison object.
284 *
285 * @param[in] target Target value.
286 * @param[in] reference Reference value.
287 * @param[in] tolerance Allowed tolerance.
288 */
John Richardson9c450cc2017-11-22 12:00:41 +0000289 compare_base(typename T::value_type target, typename T::value_type reference, T tolerance = T(0))
290 : _target{ target }, _reference{ reference }, _tolerance{ tolerance }
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100291 {
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100292 }
293
Alex Gildayc357c472018-03-21 13:54:09 +0000294 typename T::value_type _target{}; /**< Target value */
295 typename T::value_type _reference{}; /**< Reference value */
296 T _tolerance{}; /**< Tolerance value */
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100297};
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100298
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +0100299template <typename T>
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100300struct compare;
301
Alex Gildayc357c472018-03-21 13:54:09 +0000302/** Compare values with an absolute tolerance */
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100303template <typename U>
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +0100304struct compare<AbsoluteTolerance<U>> : public compare_base<AbsoluteTolerance<U>>
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100305{
306 using compare_base<AbsoluteTolerance<U>>::compare_base;
307
Alex Gildayc357c472018-03-21 13:54:09 +0000308 /** Perform comparison */
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100309 operator bool() const
310 {
Ioan-Cristian Szabo33fd07b2017-10-26 15:42:24 +0100311 if(!support::cpp11::isfinite(this->_target) || !support::cpp11::isfinite(this->_reference))
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100312 {
313 return false;
314 }
315 else if(this->_target == this->_reference)
316 {
317 return true;
318 }
319
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +0100320 using comparison_type = typename std::conditional<std::is_integral<U>::value, int64_t, U>::type;
321
322 const comparison_type abs_difference(std::abs(static_cast<comparison_type>(this->_target) - static_cast<comparison_type>(this->_reference)));
323
324 return abs_difference <= static_cast<comparison_type>(this->_tolerance);
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100325 }
326};
327
Alex Gildayc357c472018-03-21 13:54:09 +0000328/** Compare values with a relative tolerance */
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100329template <typename U>
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +0100330struct compare<RelativeTolerance<U>> : public compare_base<RelativeTolerance<U>>
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100331{
steniu013e05e4e2017-08-25 17:18:01 +0100332 using compare_base<RelativeTolerance<U>>::compare_base;
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100333
Alex Gildayc357c472018-03-21 13:54:09 +0000334 /** Perform comparison */
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100335 operator bool() const
336 {
Ioan-Cristian Szabo33fd07b2017-10-26 15:42:24 +0100337 if(!support::cpp11::isfinite(this->_target) || !support::cpp11::isfinite(this->_reference))
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100338 {
339 return false;
340 }
steniu013e05e4e2017-08-25 17:18:01 +0100341 else if(this->_target == this->_reference)
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100342 {
343 return true;
344 }
345
Moritz Pflanzerff1c3602017-09-22 12:41:25 +0100346 const U epsilon = (std::is_same<half, typename std::remove_cv<U>::type>::value || (this->_reference == 0)) ? static_cast<U>(0.01) : static_cast<U>(1e-05);
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100347
steniu013e05e4e2017-08-25 17:18:01 +0100348 if(std::abs(static_cast<double>(this->_reference) - static_cast<double>(this->_target)) <= epsilon)
349 {
350 return true;
351 }
352 else
353 {
354 if(static_cast<double>(this->_reference) == 0.0f) // We have checked whether _reference and _target is closing. If _reference is 0 but not closed to _target, it should return false
355 {
356 return false;
357 }
358
Isabella Gottardi8df6c452018-03-12 13:26:28 +0000359 const double relative_change = std::abs((static_cast<double>(this->_target) - static_cast<double>(this->_reference)) / this->_reference);
steniu013e05e4e2017-08-25 17:18:01 +0100360
361 return relative_change <= static_cast<U>(this->_tolerance);
362 }
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100363 }
364};
365
366template <typename T, typename U>
Michele Di Giorgioff6c2602018-02-26 15:22:16 +0000367void validate(const IAccessor &tensor, const SimpleTensor<T> &reference, U tolerance_value, float tolerance_number, float absolute_tolerance_value)
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100368{
369 // Validate with valid region covering the entire shape
Giorgio Arena563494c2018-04-30 17:29:41 +0100370 validate(tensor, reference, shape_to_valid_region(reference.shape()), tolerance_value, tolerance_number, absolute_tolerance_value);
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100371}
372
John Richardson9c450cc2017-11-22 12:00:41 +0000373template <typename T, typename U, typename = typename std::enable_if<std::is_integral<T>::value>::type>
John Richardsondd715f22017-09-18 16:10:48 +0100374void validate_wrap(const IAccessor &tensor, const SimpleTensor<T> &reference, U tolerance_value, float tolerance_number)
375{
376 // Validate with valid region covering the entire shape
Giorgio Arena563494c2018-04-30 17:29:41 +0100377 validate_wrap(tensor, reference, shape_to_valid_region(reference.shape()), tolerance_value, tolerance_number);
John Richardsondd715f22017-09-18 16:10:48 +0100378}
379
380template <typename T, typename U>
Michele Di Giorgioff6c2602018-02-26 15:22:16 +0000381void validate(const IAccessor &tensor, const SimpleTensor<T> &reference, const ValidRegion &valid_region, U tolerance_value, float tolerance_number, float absolute_tolerance_value)
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100382{
Giorgio Arena68e29da2021-02-08 16:31:10 +0000383 if(framework::Framework::get().configure_only() && framework::Framework::get().new_fixture_call())
384 {
385 return;
386 }
387
Michalis Spyroufae513c2019-10-16 17:41:33 +0100388 uint64_t num_mismatches = 0;
389 uint64_t num_elements = 0;
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100390
391 ARM_COMPUTE_EXPECT_EQUAL(tensor.element_size(), reference.element_size(), framework::LogLevel::ERRORS);
392 ARM_COMPUTE_EXPECT_EQUAL(tensor.data_type(), reference.data_type(), framework::LogLevel::ERRORS);
393
394 if(reference.format() != Format::UNKNOWN)
395 {
396 ARM_COMPUTE_EXPECT_EQUAL(tensor.format(), reference.format(), framework::LogLevel::ERRORS);
397 }
398
399 ARM_COMPUTE_EXPECT_EQUAL(tensor.num_channels(), reference.num_channels(), framework::LogLevel::ERRORS);
Giorgio Arena563494c2018-04-30 17:29:41 +0100400 ARM_COMPUTE_EXPECT(compare_dimensions(tensor.shape(), reference.shape(), tensor.data_layout()), framework::LogLevel::ERRORS);
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100401
402 const int min_elements = std::min(tensor.num_elements(), reference.num_elements());
403 const int min_channels = std::min(tensor.num_channels(), reference.num_channels());
404
405 // Iterate over all elements within valid region, e.g. U8, S16, RGB888, ...
406 for(int element_idx = 0; element_idx < min_elements; ++element_idx)
407 {
408 const Coordinates id = index2coord(reference.shape(), element_idx);
409
Giorgio Arena563494c2018-04-30 17:29:41 +0100410 Coordinates target_id(id);
411 if(tensor.data_layout() == DataLayout::NHWC)
412 {
413 permute(target_id, PermutationVector(2U, 0U, 1U));
414 }
415
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100416 if(is_in_valid_region(valid_region, id))
417 {
418 // Iterate over all channels within one element
419 for(int c = 0; c < min_channels; ++c)
420 {
Giorgio Arena563494c2018-04-30 17:29:41 +0100421 const T &target_value = reinterpret_cast<const T *>(tensor(target_id))[c];
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100422 const T &reference_value = reinterpret_cast<const T *>(reference(id))[c];
423
Michalis Spyrou23fe7c22018-02-26 10:42:01 +0000424 if(!compare<U>(target_value, reference_value, tolerance_value))
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100425 {
Michele Di Giorgioff6c2602018-02-26 15:22:16 +0000426 if(absolute_tolerance_value != 0.f)
427 {
428 const AbsoluteTolerance<float> abs_tolerance(absolute_tolerance_value);
429 if(compare<AbsoluteTolerance<float>>(target_value, reference_value, abs_tolerance))
430 {
431 continue;
432 }
433 }
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100434 ARM_COMPUTE_TEST_INFO("id = " << id);
435 ARM_COMPUTE_TEST_INFO("channel = " << c);
436 ARM_COMPUTE_TEST_INFO("target = " << std::setprecision(5) << framework::make_printable(target_value));
437 ARM_COMPUTE_TEST_INFO("reference = " << std::setprecision(5) << framework::make_printable(reference_value));
438 ARM_COMPUTE_TEST_INFO("tolerance = " << std::setprecision(5) << framework::make_printable(static_cast<typename U::value_type>(tolerance_value)));
steniu01172c58d2017-08-31 13:49:08 +0100439 framework::ARM_COMPUTE_PRINT_INFO();
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100440
441 ++num_mismatches;
442 }
443
444 ++num_elements;
445 }
446 }
447 }
448
Michalis Spyroufae513c2019-10-16 17:41:33 +0100449 if(num_elements != 0)
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100450 {
Michalis Spyroufae513c2019-10-16 17:41:33 +0100451 const uint64_t absolute_tolerance_number = tolerance_number * num_elements;
452 const float percent_mismatches = static_cast<float>(num_mismatches) / num_elements * 100.f;
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100453
454 ARM_COMPUTE_TEST_INFO(num_mismatches << " values (" << std::fixed << std::setprecision(2) << percent_mismatches
Abe Mbise1b993382017-12-19 13:51:59 +0000455 << "%) mismatched (maximum tolerated " << std::setprecision(2) << tolerance_number * 100 << "%)");
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100456 ARM_COMPUTE_EXPECT(num_mismatches <= absolute_tolerance_number, framework::LogLevel::ERRORS);
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100457 }
458}
Giorgio Arenafc2817d2017-06-27 17:26:37 +0100459
John Richardson9c450cc2017-11-22 12:00:41 +0000460template <typename T, typename U, typename = typename std::enable_if<std::is_integral<T>::value>::type>
John Richardsondd715f22017-09-18 16:10:48 +0100461void validate_wrap(const IAccessor &tensor, const SimpleTensor<T> &reference, const ValidRegion &valid_region, U tolerance_value, float tolerance_number)
462{
Giorgio Arena68e29da2021-02-08 16:31:10 +0000463 if(framework::Framework::get().configure_only() && framework::Framework::get().new_fixture_call())
464 {
465 return;
466 }
467
Michalis Spyroufae513c2019-10-16 17:41:33 +0100468 uint64_t num_mismatches = 0;
469 uint64_t num_elements = 0;
John Richardsondd715f22017-09-18 16:10:48 +0100470
471 ARM_COMPUTE_EXPECT_EQUAL(tensor.element_size(), reference.element_size(), framework::LogLevel::ERRORS);
472 ARM_COMPUTE_EXPECT_EQUAL(tensor.data_type(), reference.data_type(), framework::LogLevel::ERRORS);
473
474 if(reference.format() != Format::UNKNOWN)
475 {
476 ARM_COMPUTE_EXPECT_EQUAL(tensor.format(), reference.format(), framework::LogLevel::ERRORS);
477 }
478
479 ARM_COMPUTE_EXPECT_EQUAL(tensor.num_channels(), reference.num_channels(), framework::LogLevel::ERRORS);
Giorgio Arena563494c2018-04-30 17:29:41 +0100480 ARM_COMPUTE_EXPECT(compare_dimensions(tensor.shape(), reference.shape(), tensor.data_layout()), framework::LogLevel::ERRORS);
John Richardsondd715f22017-09-18 16:10:48 +0100481
482 const int min_elements = std::min(tensor.num_elements(), reference.num_elements());
483 const int min_channels = std::min(tensor.num_channels(), reference.num_channels());
484
485 // Iterate over all elements within valid region, e.g. U8, S16, RGB888, ...
486 for(int element_idx = 0; element_idx < min_elements; ++element_idx)
487 {
488 const Coordinates id = index2coord(reference.shape(), element_idx);
489
Giorgio Arena563494c2018-04-30 17:29:41 +0100490 Coordinates target_id(id);
491 if(tensor.data_layout() == DataLayout::NHWC)
492 {
493 permute(target_id, PermutationVector(2U, 0U, 1U));
494 }
495
John Richardsondd715f22017-09-18 16:10:48 +0100496 if(is_in_valid_region(valid_region, id))
497 {
498 // Iterate over all channels within one element
499 for(int c = 0; c < min_channels; ++c)
500 {
Giorgio Arena563494c2018-04-30 17:29:41 +0100501 const T &target_value = reinterpret_cast<const T *>(tensor(target_id))[c];
John Richardsondd715f22017-09-18 16:10:48 +0100502 const T &reference_value = reinterpret_cast<const T *>(reference(id))[c];
503
504 bool equal = compare<U>(target_value, reference_value, tolerance_value);
505
John Richardson9c450cc2017-11-22 12:00:41 +0000506 // check for wrapping
John Richardsondd715f22017-09-18 16:10:48 +0100507 if(!equal)
508 {
John Richardson9c450cc2017-11-22 12:00:41 +0000509 if(!support::cpp11::isfinite(target_value) || !support::cpp11::isfinite(reference_value))
510 {
511 equal = false;
512 }
513 else
514 {
515 using limits_type = typename std::make_unsigned<T>::type;
516
517 uint64_t max = std::numeric_limits<limits_type>::max();
518 uint64_t abs_sum = std::abs(static_cast<int64_t>(target_value)) + std::abs(static_cast<int64_t>(reference_value));
519 uint64_t wrap_difference = max - abs_sum;
520
521 equal = wrap_difference < static_cast<uint64_t>(tolerance_value);
522 }
John Richardsondd715f22017-09-18 16:10:48 +0100523 }
524
525 if(!equal)
526 {
527 ARM_COMPUTE_TEST_INFO("id = " << id);
528 ARM_COMPUTE_TEST_INFO("channel = " << c);
529 ARM_COMPUTE_TEST_INFO("target = " << std::setprecision(5) << framework::make_printable(target_value));
530 ARM_COMPUTE_TEST_INFO("reference = " << std::setprecision(5) << framework::make_printable(reference_value));
John Richardson9c450cc2017-11-22 12:00:41 +0000531 ARM_COMPUTE_TEST_INFO("wrap_tolerance = " << std::setprecision(5) << framework::make_printable(static_cast<typename U::value_type>(tolerance_value)));
John Richardsondd715f22017-09-18 16:10:48 +0100532 framework::ARM_COMPUTE_PRINT_INFO();
533
534 ++num_mismatches;
535 }
536
537 ++num_elements;
538 }
539 }
540 }
541
Michalis Spyroufae513c2019-10-16 17:41:33 +0100542 if(num_elements != 0)
John Richardsondd715f22017-09-18 16:10:48 +0100543 {
Michalis Spyroufae513c2019-10-16 17:41:33 +0100544 const uint64_t absolute_tolerance_number = tolerance_number * num_elements;
545 const float percent_mismatches = static_cast<float>(num_mismatches) / num_elements * 100.f;
John Richardsondd715f22017-09-18 16:10:48 +0100546
547 ARM_COMPUTE_TEST_INFO(num_mismatches << " values (" << std::fixed << std::setprecision(2) << percent_mismatches
Abe Mbise1b993382017-12-19 13:51:59 +0000548 << "%) mismatched (maximum tolerated " << std::setprecision(2) << tolerance_number * 100 << "%)");
John Richardsondd715f22017-09-18 16:10:48 +0100549 ARM_COMPUTE_EXPECT(num_mismatches <= absolute_tolerance_number, framework::LogLevel::ERRORS);
550 }
551}
552
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100553template <typename T, typename U>
Michele Di Giorgioff6c2602018-02-26 15:22:16 +0000554void validate(const IAccessor &tensor, const SimpleTensor<T> &reference, const SimpleTensor<T> &valid_mask, U tolerance_value, float tolerance_number, float absolute_tolerance_value)
Isabella Gottardi83be7452017-08-29 13:47:03 +0100555{
Giorgio Arena68e29da2021-02-08 16:31:10 +0000556 if(framework::Framework::get().configure_only() && framework::Framework::get().new_fixture_call())
557 {
558 return;
559 }
560
Michalis Spyroufae513c2019-10-16 17:41:33 +0100561 uint64_t num_mismatches = 0;
562 uint64_t num_elements = 0;
Isabella Gottardi83be7452017-08-29 13:47:03 +0100563
564 ARM_COMPUTE_EXPECT_EQUAL(tensor.element_size(), reference.element_size(), framework::LogLevel::ERRORS);
565 ARM_COMPUTE_EXPECT_EQUAL(tensor.data_type(), reference.data_type(), framework::LogLevel::ERRORS);
566
567 if(reference.format() != Format::UNKNOWN)
568 {
569 ARM_COMPUTE_EXPECT_EQUAL(tensor.format(), reference.format(), framework::LogLevel::ERRORS);
570 }
571
572 ARM_COMPUTE_EXPECT_EQUAL(tensor.num_channels(), reference.num_channels(), framework::LogLevel::ERRORS);
Giorgio Arena563494c2018-04-30 17:29:41 +0100573 ARM_COMPUTE_EXPECT(compare_dimensions(tensor.shape(), reference.shape(), tensor.data_layout()), framework::LogLevel::ERRORS);
Isabella Gottardi83be7452017-08-29 13:47:03 +0100574
575 const int min_elements = std::min(tensor.num_elements(), reference.num_elements());
576 const int min_channels = std::min(tensor.num_channels(), reference.num_channels());
577
578 // Iterate over all elements within valid region, e.g. U8, S16, RGB888, ...
579 for(int element_idx = 0; element_idx < min_elements; ++element_idx)
580 {
581 const Coordinates id = index2coord(reference.shape(), element_idx);
582
Giorgio Arena563494c2018-04-30 17:29:41 +0100583 Coordinates target_id(id);
584 if(tensor.data_layout() == DataLayout::NHWC)
585 {
586 permute(target_id, PermutationVector(2U, 0U, 1U));
587 }
588
Isabella Gottardi83be7452017-08-29 13:47:03 +0100589 if(valid_mask[element_idx] == 1)
590 {
591 // Iterate over all channels within one element
592 for(int c = 0; c < min_channels; ++c)
593 {
Giorgio Arena563494c2018-04-30 17:29:41 +0100594 const T &target_value = reinterpret_cast<const T *>(tensor(target_id))[c];
Isabella Gottardi83be7452017-08-29 13:47:03 +0100595 const T &reference_value = reinterpret_cast<const T *>(reference(id))[c];
596
597 if(!compare<U>(target_value, reference_value, tolerance_value))
598 {
Michele Di Giorgioff6c2602018-02-26 15:22:16 +0000599 if(absolute_tolerance_value != 0.f)
600 {
601 const AbsoluteTolerance<float> abs_tolerance(absolute_tolerance_value);
602 if(compare<AbsoluteTolerance<float>>(target_value, reference_value, abs_tolerance))
603 {
604 continue;
605 }
606 }
Isabella Gottardi83be7452017-08-29 13:47:03 +0100607 ARM_COMPUTE_TEST_INFO("id = " << id);
608 ARM_COMPUTE_TEST_INFO("channel = " << c);
609 ARM_COMPUTE_TEST_INFO("target = " << std::setprecision(5) << framework::make_printable(target_value));
610 ARM_COMPUTE_TEST_INFO("reference = " << std::setprecision(5) << framework::make_printable(reference_value));
611 ARM_COMPUTE_TEST_INFO("tolerance = " << std::setprecision(5) << framework::make_printable(static_cast<typename U::value_type>(tolerance_value)));
612 framework::ARM_COMPUTE_PRINT_INFO();
613
614 ++num_mismatches;
615 }
616
617 ++num_elements;
618 }
619 }
620 else
621 {
622 ++num_elements;
623 }
624 }
625
Michalis Spyroufae513c2019-10-16 17:41:33 +0100626 if(num_elements != 0)
Isabella Gottardi83be7452017-08-29 13:47:03 +0100627 {
Michalis Spyroufae513c2019-10-16 17:41:33 +0100628 const uint64_t absolute_tolerance_number = tolerance_number * num_elements;
629 const float percent_mismatches = static_cast<float>(num_mismatches) / num_elements * 100.f;
Isabella Gottardi83be7452017-08-29 13:47:03 +0100630
631 ARM_COMPUTE_TEST_INFO(num_mismatches << " values (" << std::fixed << std::setprecision(2) << percent_mismatches
Abe Mbise1b993382017-12-19 13:51:59 +0000632 << "%) mismatched (maximum tolerated " << std::setprecision(2) << tolerance_number * 100 << "%)");
Isabella Gottardi83be7452017-08-29 13:47:03 +0100633 ARM_COMPUTE_EXPECT(num_mismatches <= absolute_tolerance_number, framework::LogLevel::ERRORS);
634 }
635}
636
637template <typename T, typename U>
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +0100638bool validate(T target, T reference, U tolerance)
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100639{
Giorgio Arena68e29da2021-02-08 16:31:10 +0000640 if(framework::Framework::get().configure_only() && framework::Framework::get().new_fixture_call())
641 {
642 return true;
643 }
644
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100645 ARM_COMPUTE_TEST_INFO("reference = " << std::setprecision(5) << framework::make_printable(reference));
646 ARM_COMPUTE_TEST_INFO("target = " << std::setprecision(5) << framework::make_printable(target));
647 ARM_COMPUTE_TEST_INFO("tolerance = " << std::setprecision(5) << framework::make_printable(static_cast<typename U::value_type>(tolerance)));
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +0100648
649 const bool equal = compare<U>(target, reference, tolerance);
650
651 ARM_COMPUTE_EXPECT(equal, framework::LogLevel::ERRORS);
652
653 return equal;
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100654}
John Richardsonf89a49f2017-09-05 11:21:56 +0100655
656template <typename T, typename U>
657void validate_min_max_loc(const MinMaxLocationValues<T> &target, const MinMaxLocationValues<U> &reference)
658{
Giorgio Arena68e29da2021-02-08 16:31:10 +0000659 if(framework::Framework::get().configure_only() && framework::Framework::get().new_fixture_call())
660 {
661 return;
662 }
663
John Richardsonf89a49f2017-09-05 11:21:56 +0100664 ARM_COMPUTE_EXPECT_EQUAL(target.min, reference.min, framework::LogLevel::ERRORS);
665 ARM_COMPUTE_EXPECT_EQUAL(target.max, reference.max, framework::LogLevel::ERRORS);
666
667 ARM_COMPUTE_EXPECT_EQUAL(target.min_loc.size(), reference.min_loc.size(), framework::LogLevel::ERRORS);
668 ARM_COMPUTE_EXPECT_EQUAL(target.max_loc.size(), reference.max_loc.size(), framework::LogLevel::ERRORS);
669
670 for(uint32_t i = 0; i < target.min_loc.size(); ++i)
671 {
672 const auto same_coords = std::find_if(reference.min_loc.begin(), reference.min_loc.end(), [&target, i](Coordinates2D coord)
673 {
674 return coord.x == target.min_loc.at(i).x && coord.y == target.min_loc.at(i).y;
675 });
676
677 ARM_COMPUTE_EXPECT(same_coords != reference.min_loc.end(), framework::LogLevel::ERRORS);
678 }
679
680 for(uint32_t i = 0; i < target.max_loc.size(); ++i)
681 {
682 const auto same_coords = std::find_if(reference.max_loc.begin(), reference.max_loc.end(), [&target, i](Coordinates2D coord)
683 {
684 return coord.x == target.max_loc.at(i).x && coord.y == target.max_loc.at(i).y;
685 });
686
687 ARM_COMPUTE_EXPECT(same_coords != reference.max_loc.end(), framework::LogLevel::ERRORS);
688 }
689}
690
Abe Mbise562fe0f2018-02-09 14:13:02 +0000691/** Check which keypoints from [first1, last1) are missing in [first2, last2) */
692template <typename T, typename U, typename V>
693std::pair<int64_t, int64_t> compare_keypoints(T first1, T last1, U first2, U last2, V tolerance, bool check_mismatches = true)
694{
695 /* Keypoint (x,y) should have similar strength (within tolerance) and other properties in both reference and target */
696 const auto compare_props_eq = [&](const KeyPoint & lhs, const KeyPoint & rhs)
697 {
698 return compare<V>(lhs.strength, rhs.strength, tolerance)
699 && lhs.tracking_status == rhs.tracking_status
700 && lhs.scale == rhs.scale
701 && lhs.orientation == rhs.orientation
702 && lhs.error == rhs.error;
703 };
704
705 /* Used to sort KeyPoints by coordinates (x, y) */
706 const auto compare_coords_lt = [](const KeyPoint & lhs, const KeyPoint & rhs)
707 {
708 return std::tie(lhs.x, lhs.y) < std::tie(rhs.x, rhs.y);
709 };
710
711 std::sort(first1, last1, compare_coords_lt);
712 std::sort(first2, last2, compare_coords_lt);
713
714 if(check_mismatches)
715 {
Anthony Barbier29421bd2018-11-02 18:18:47 +0000716 ARM_COMPUTE_TEST_INFO("Checking for mismatches: ref count = " << std::distance(first1, last1) << " target count = " << std::distance(first2, last2));
Abe Mbise562fe0f2018-02-09 14:13:02 +0000717 }
718
719 int64_t num_missing = 0;
720 int64_t num_mismatches = 0;
721 bool rest_missing = false;
722
723 while(first1 != last1)
724 {
725 if(first2 == last2)
726 {
727 rest_missing = true;
728 break;
729 }
730
731 if(compare_coords_lt(*first1, *first2))
732 {
733 ++num_missing;
734 ARM_COMPUTE_TEST_INFO("Key point not found");
735 ARM_COMPUTE_TEST_INFO("keypoint1 = " << *first1++);
Georgios Pinitasda19dab2018-08-30 19:55:29 +0100736 framework::ARM_COMPUTE_PRINT_INFO();
Abe Mbise562fe0f2018-02-09 14:13:02 +0000737 }
738 else
739 {
740 if(!compare_coords_lt(*first2, *first1)) // Equal coordinates
741 {
742 if(check_mismatches && !compare_props_eq(*first1, *first2)) // Check other properties
743 {
744 ++num_mismatches;
745 ARM_COMPUTE_TEST_INFO("Mismatching keypoint");
746 ARM_COMPUTE_TEST_INFO("keypoint1 [ref] = " << *first1);
747 ARM_COMPUTE_TEST_INFO("keypoint2 [tgt] = " << *first2);
Georgios Pinitasda19dab2018-08-30 19:55:29 +0100748 framework::ARM_COMPUTE_PRINT_INFO();
Abe Mbise562fe0f2018-02-09 14:13:02 +0000749 }
750 ++first1;
751 }
752 ++first2;
753 }
754 }
755
756 if(rest_missing)
757 {
758 while(first1 != last1)
759 {
760 ++num_missing;
761 ARM_COMPUTE_TEST_INFO("Key point not found");
762 ARM_COMPUTE_TEST_INFO("keypoint1 = " << *first1++);
Georgios Pinitasda19dab2018-08-30 19:55:29 +0100763 framework::ARM_COMPUTE_PRINT_INFO();
Abe Mbise562fe0f2018-02-09 14:13:02 +0000764 }
765 }
766
767 return std::make_pair(num_missing, num_mismatches);
768}
769
770template <typename T, typename U, typename V>
771void validate_keypoints(T target_first, T target_last, U reference_first, U reference_last, V tolerance, float allowed_missing_percentage, float allowed_mismatch_percentage)
772{
Giorgio Arena68e29da2021-02-08 16:31:10 +0000773 if(framework::Framework::get().configure_only() && framework::Framework::get().new_fixture_call())
774 {
775 return;
776 }
777
Abe Mbise562fe0f2018-02-09 14:13:02 +0000778 const int64_t num_elements_target = std::distance(target_first, target_last);
779 const int64_t num_elements_reference = std::distance(reference_first, reference_last);
780
781 int64_t num_missing = 0;
782 int64_t num_mismatches = 0;
783
784 if(num_elements_reference > 0)
785 {
786 std::tie(num_missing, num_mismatches) = compare_keypoints(reference_first, reference_last, target_first, target_last, tolerance);
787
788 const float percent_missing = static_cast<float>(num_missing) / num_elements_reference * 100.f;
789 const float percent_mismatches = static_cast<float>(num_mismatches) / num_elements_reference * 100.f;
790
791 ARM_COMPUTE_TEST_INFO(num_missing << " keypoints (" << std::fixed << std::setprecision(2) << percent_missing << "%) in ref are missing from target");
792 ARM_COMPUTE_TEST_INFO("Missing (not in tgt): " << num_missing << "/" << num_elements_reference << " = " << std::fixed << std::setprecision(2) << percent_missing
793 << "% \tMax allowed: " << allowed_missing_percentage << "%");
794 ARM_COMPUTE_EXPECT(percent_missing <= allowed_missing_percentage, framework::LogLevel::ERRORS);
795
796 ARM_COMPUTE_TEST_INFO(num_mismatches << " keypoints (" << std::fixed << std::setprecision(2) << percent_mismatches << "%) mismatched");
797 ARM_COMPUTE_TEST_INFO("Mismatched keypoints: " << num_mismatches << "/" << num_elements_reference << " = " << std::fixed << std::setprecision(2) << percent_mismatches
798 << "% \tMax allowed: " << allowed_mismatch_percentage << "%");
799 ARM_COMPUTE_EXPECT(percent_mismatches <= allowed_mismatch_percentage, framework::LogLevel::ERRORS);
800 }
801
802 if(num_elements_target > 0)
803 {
804 // Note: no need to check for mismatches a second time (last argument is 'false')
805 std::tie(num_missing, num_mismatches) = compare_keypoints(target_first, target_last, reference_first, reference_last, tolerance, false);
806
807 const float percent_missing = static_cast<float>(num_missing) / num_elements_target * 100.f;
808
809 ARM_COMPUTE_TEST_INFO(num_missing << " keypoints (" << std::fixed << std::setprecision(2) << percent_missing << "%) in target are missing from ref");
810 ARM_COMPUTE_TEST_INFO("Missing (not in ref): " << num_missing << "/" << num_elements_target << " = " << std::fixed << std::setprecision(2) << percent_missing
811 << "% \tMax allowed: " << allowed_missing_percentage << "%");
812 ARM_COMPUTE_EXPECT(percent_missing <= allowed_missing_percentage, framework::LogLevel::ERRORS);
813 }
814}
815
John Richardson684cb0f2018-01-09 11:17:00 +0000816/** Check which detection windows from [first1, last1) are missing in [first2, last2) */
817template <typename T, typename U, typename V>
818std::pair<int64_t, int64_t> compare_detection_windows(T first1, T last1, U first2, U last2, V tolerance)
819{
820 int64_t num_missing = 0;
821 int64_t num_mismatches = 0;
822
823 while(first1 != last1)
824 {
825 const auto window = std::find_if(first2, last2, [&](DetectionWindow window)
826 {
827 return window.x == first1->x && window.y == first1->y && window.width == first1->width && window.height == first1->height && window.idx_class == first1->idx_class;
828 });
829
830 if(window == last2)
831 {
832 ++num_missing;
833 ARM_COMPUTE_TEST_INFO("Detection window not found " << *first1)
Georgios Pinitasda19dab2018-08-30 19:55:29 +0100834 framework::ARM_COMPUTE_PRINT_INFO();
John Richardson684cb0f2018-01-09 11:17:00 +0000835 }
836 else
837 {
838 if(!compare<V>(window->score, first1->score, tolerance))
839 {
840 ++num_mismatches;
841 ARM_COMPUTE_TEST_INFO("Mismatching detection window")
842 ARM_COMPUTE_TEST_INFO("detection window 1= " << *first1)
843 ARM_COMPUTE_TEST_INFO("detection window 2= " << *window)
Georgios Pinitasda19dab2018-08-30 19:55:29 +0100844 framework::ARM_COMPUTE_PRINT_INFO();
John Richardson684cb0f2018-01-09 11:17:00 +0000845 }
846 }
847
848 ++first1;
849 }
850
851 return std::make_pair(num_missing, num_mismatches);
852}
853
854template <typename T, typename U, typename V>
855void validate_detection_windows(T target_first, T target_last, U reference_first, U reference_last, V tolerance,
856 float allowed_missing_percentage, float allowed_mismatch_percentage)
857{
Giorgio Arena68e29da2021-02-08 16:31:10 +0000858 if(framework::Framework::get().configure_only() && framework::Framework::get().new_fixture_call())
859 {
860 return;
861 }
862
John Richardson684cb0f2018-01-09 11:17:00 +0000863 const int64_t num_elements_target = std::distance(target_first, target_last);
864 const int64_t num_elements_reference = std::distance(reference_first, reference_last);
865
866 int64_t num_missing = 0;
867 int64_t num_mismatches = 0;
868
869 if(num_elements_reference > 0)
870 {
871 std::tie(num_missing, num_mismatches) = compare_detection_windows(reference_first, reference_last, target_first, target_last, tolerance);
872
873 const float percent_missing = static_cast<float>(num_missing) / num_elements_reference * 100.f;
874 const float percent_mismatches = static_cast<float>(num_mismatches) / num_elements_reference * 100.f;
875
876 ARM_COMPUTE_TEST_INFO(num_missing << " detection windows (" << std::fixed << std::setprecision(2) << percent_missing << "%) are missing in target");
877 ARM_COMPUTE_EXPECT(percent_missing <= allowed_missing_percentage, framework::LogLevel::ERRORS);
878
879 ARM_COMPUTE_TEST_INFO(num_mismatches << " detection windows (" << std::fixed << std::setprecision(2) << percent_mismatches << "%) mismatched");
880 ARM_COMPUTE_EXPECT(percent_mismatches <= allowed_mismatch_percentage, framework::LogLevel::ERRORS);
881 }
882
883 if(num_elements_target > 0)
884 {
885 std::tie(num_missing, num_mismatches) = compare_detection_windows(target_first, target_last, reference_first, reference_last, tolerance);
886
887 const float percent_missing = static_cast<float>(num_missing) / num_elements_target * 100.f;
888
889 ARM_COMPUTE_TEST_INFO(num_missing << " detection windows (" << std::fixed << std::setprecision(2) << percent_missing << "%) are not part of target");
890 ARM_COMPUTE_EXPECT(percent_missing <= allowed_missing_percentage, framework::LogLevel::ERRORS);
891 }
892}
893
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100894} // namespace validation
895} // namespace test
896} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000897#endif /* ARM_COMPUTE_TEST_REFERENCE_VALIDATION_H */