Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Abe Mbise | 562fe0f | 2018-02-09 14:13:02 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 3 | * |
| 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 | */ |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 24 | #ifndef __ARM_COMPUTE_TEST_VALIDATION_H__ |
| 25 | #define __ARM_COMPUTE_TEST_VALIDATION_H__ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 26 | |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/FixedPoint.h" |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 28 | #include "arm_compute/core/IArray.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 29 | #include "arm_compute/core/Types.h" |
Ioan-Cristian Szabo | 33fd07b | 2017-10-26 15:42:24 +0100 | [diff] [blame] | 30 | #include "support/ToolchainSupport.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 31 | #include "tests/IAccessor.h" |
| 32 | #include "tests/SimpleTensor.h" |
John Richardson | f89a49f | 2017-09-05 11:21:56 +0100 | [diff] [blame] | 33 | #include "tests/Types.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 34 | #include "tests/Utils.h" |
| 35 | #include "tests/framework/Asserts.h" |
| 36 | #include "tests/framework/Exceptions.h" |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 37 | #include "utils/TypePrinter.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 38 | |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 39 | #include <iomanip> |
| 40 | #include <ios> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 41 | #include <vector> |
| 42 | |
| 43 | namespace arm_compute |
| 44 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 45 | namespace test |
| 46 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 47 | namespace validation |
| 48 | { |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 49 | /** Class reprensenting an absolute tolerance value. */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 50 | template <typename T> |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 51 | class AbsoluteTolerance |
| 52 | { |
| 53 | public: |
| 54 | /** Underlying type. */ |
| 55 | using value_type = T; |
| 56 | |
| 57 | /* Default constructor. |
| 58 | * |
| 59 | * Initialises the tolerance to 0. |
| 60 | */ |
| 61 | AbsoluteTolerance() = default; |
| 62 | |
| 63 | /** Constructor. |
| 64 | * |
| 65 | * @param[in] value Absolute tolerance value. |
| 66 | */ |
| 67 | explicit constexpr AbsoluteTolerance(T value) |
| 68 | : _value{ value } |
| 69 | { |
| 70 | } |
| 71 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 72 | /** Implicit conversion to the underlying type. |
| 73 | * |
| 74 | * @return the underlying type. |
| 75 | */ |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 76 | constexpr operator T() const |
| 77 | { |
| 78 | return _value; |
| 79 | } |
| 80 | |
| 81 | private: |
| 82 | T _value{ std::numeric_limits<T>::epsilon() }; |
| 83 | }; |
| 84 | |
| 85 | /** Class reprensenting a relative tolerance value. */ |
steniu01 | 3e05e4e | 2017-08-25 17:18:01 +0100 | [diff] [blame] | 86 | template <typename T> |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 87 | class RelativeTolerance |
| 88 | { |
| 89 | public: |
| 90 | /** Underlying type. */ |
steniu01 | 3e05e4e | 2017-08-25 17:18:01 +0100 | [diff] [blame] | 91 | using value_type = T; |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 92 | |
| 93 | /* Default constructor. |
| 94 | * |
| 95 | * Initialises the tolerance to 0. |
| 96 | */ |
| 97 | RelativeTolerance() = default; |
| 98 | |
| 99 | /** Constructor. |
| 100 | * |
| 101 | * @param[in] value Relative tolerance value. |
| 102 | */ |
| 103 | explicit constexpr RelativeTolerance(value_type value) |
| 104 | : _value{ value } |
| 105 | { |
| 106 | } |
| 107 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 108 | /** Implicit conversion to the underlying type. |
| 109 | * |
| 110 | * @return the underlying type. |
| 111 | */ |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 112 | constexpr operator value_type() const |
| 113 | { |
| 114 | return _value; |
| 115 | } |
| 116 | |
| 117 | private: |
steniu01 | 3e05e4e | 2017-08-25 17:18:01 +0100 | [diff] [blame] | 118 | value_type _value{ std::numeric_limits<T>::epsilon() }; |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 119 | }; |
| 120 | |
| 121 | /** Print AbsoluteTolerance type. */ |
| 122 | template <typename T> |
| 123 | inline ::std::ostream &operator<<(::std::ostream &os, const AbsoluteTolerance<T> &tolerance) |
| 124 | { |
| 125 | os << static_cast<typename AbsoluteTolerance<T>::value_type>(tolerance); |
| 126 | |
| 127 | return os; |
| 128 | } |
| 129 | |
| 130 | /** Print RelativeTolerance type. */ |
steniu01 | 3e05e4e | 2017-08-25 17:18:01 +0100 | [diff] [blame] | 131 | template <typename T> |
| 132 | inline ::std::ostream &operator<<(::std::ostream &os, const RelativeTolerance<T> &tolerance) |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 133 | { |
steniu01 | 3e05e4e | 2017-08-25 17:18:01 +0100 | [diff] [blame] | 134 | os << static_cast<typename RelativeTolerance<T>::value_type>(tolerance); |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 135 | |
| 136 | return os; |
| 137 | } |
| 138 | |
| 139 | template <typename T> |
| 140 | bool compare_dimensions(const Dimensions<T> &dimensions1, const Dimensions<T> &dimensions2) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 141 | { |
| 142 | if(dimensions1.num_dimensions() != dimensions2.num_dimensions()) |
| 143 | { |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 144 | return false; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | for(unsigned int i = 0; i < dimensions1.num_dimensions(); ++i) |
| 148 | { |
| 149 | if(dimensions1[i] != dimensions2[i]) |
| 150 | { |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 151 | return false; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | |
| 155 | return true; |
| 156 | } |
| 157 | |
| 158 | /** Validate valid regions. |
| 159 | * |
| 160 | * - Dimensionality has to be the same. |
| 161 | * - Anchors have to match. |
| 162 | * - Shapes have to match. |
| 163 | */ |
| 164 | void validate(const arm_compute::ValidRegion ®ion, const arm_compute::ValidRegion &reference); |
| 165 | |
| 166 | /** Validate padding. |
| 167 | * |
| 168 | * Padding on all sides has to be the same. |
| 169 | */ |
| 170 | void validate(const arm_compute::PaddingSize &padding, const arm_compute::PaddingSize &reference); |
| 171 | |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 172 | /** Validate padding. |
| 173 | * |
| 174 | * Padding on all sides has to be the same. |
| 175 | */ |
| 176 | void validate(const arm_compute::PaddingSize &padding, const arm_compute::PaddingSize &width_reference, const arm_compute::PaddingSize &height_reference); |
| 177 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 178 | /** Validate tensors. |
| 179 | * |
| 180 | * - Dimensionality has to be the same. |
| 181 | * - All values have to match. |
| 182 | * |
| 183 | * @note: wrap_range allows cases where reference tensor rounds up to the wrapping point, causing it to wrap around to |
| 184 | * zero while the test tensor stays at wrapping point to pass. This may permit true erroneous cases (difference between |
| 185 | * reference tensor and test tensor is multiple of wrap_range), but such errors would be detected by |
| 186 | * other test cases. |
| 187 | */ |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 188 | template <typename T, typename U = AbsoluteTolerance<T>> |
Michele Di Giorgio | ff6c260 | 2018-02-26 15:22:16 +0000 | [diff] [blame] | 189 | void validate(const IAccessor &tensor, const SimpleTensor<T> &reference, U tolerance_value = U(), float tolerance_number = 0.f, float absolute_tolerance_value = 0.f); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 190 | |
| 191 | /** Validate tensors with valid region. |
| 192 | * |
| 193 | * - Dimensionality has to be the same. |
| 194 | * - All values have to match. |
| 195 | * |
| 196 | * @note: wrap_range allows cases where reference tensor rounds up to the wrapping point, causing it to wrap around to |
| 197 | * zero while the test tensor stays at wrapping point to pass. This may permit true erroneous cases (difference between |
| 198 | * reference tensor and test tensor is multiple of wrap_range), but such errors would be detected by |
| 199 | * other test cases. |
| 200 | */ |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 201 | template <typename T, typename U = AbsoluteTolerance<T>> |
Michele Di Giorgio | ff6c260 | 2018-02-26 15:22:16 +0000 | [diff] [blame] | 202 | void 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 Gottardi | 6203153 | 2017-07-04 11:21:28 +0100 | [diff] [blame] | 203 | |
Isabella Gottardi | 83be745 | 2017-08-29 13:47:03 +0100 | [diff] [blame] | 204 | /** Validate tensors with valid mask. |
| 205 | * |
| 206 | * - Dimensionality has to be the same. |
| 207 | * - All values have to match. |
| 208 | * |
| 209 | * @note: wrap_range allows cases where reference tensor rounds up to the wrapping point, causing it to wrap around to |
| 210 | * zero while the test tensor stays at wrapping point to pass. This may permit true erroneous cases (difference between |
| 211 | * reference tensor and test tensor is multiple of wrap_range), but such errors would be detected by |
| 212 | * other test cases. |
| 213 | */ |
| 214 | template <typename T, typename U = AbsoluteTolerance<T>> |
Michele Di Giorgio | ff6c260 | 2018-02-26 15:22:16 +0000 | [diff] [blame] | 215 | void validate(const IAccessor &tensor, const SimpleTensor<T> &reference, const SimpleTensor<T> &valid_mask, U tolerance_value = U(), float tolerance_number = 0.f, |
| 216 | float absolute_tolerance_value = 0.f); |
Isabella Gottardi | 83be745 | 2017-08-29 13:47:03 +0100 | [diff] [blame] | 217 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 218 | /** Validate tensors against constant value. |
| 219 | * |
| 220 | * - All values have to match. |
| 221 | */ |
| 222 | void validate(const IAccessor &tensor, const void *reference_value); |
| 223 | |
| 224 | /** Validate border against a constant value. |
| 225 | * |
| 226 | * - All border values have to match the specified value if mode is CONSTANT. |
| 227 | * - All border values have to be replicated if mode is REPLICATE. |
| 228 | * - Nothing is validated for mode UNDEFINED. |
| 229 | */ |
| 230 | void validate(const IAccessor &tensor, BorderSize border_size, const BorderMode &border_mode, const void *border_value); |
| 231 | |
| 232 | /** Validate classified labels against expected ones. |
| 233 | * |
| 234 | * - All values should match |
| 235 | */ |
| 236 | void validate(std::vector<unsigned int> classified_labels, std::vector<unsigned int> expected_labels); |
steniu01 | 960b084 | 2017-06-23 11:44:34 +0100 | [diff] [blame] | 237 | |
| 238 | /** Validate float value. |
| 239 | * |
| 240 | * - All values should match |
| 241 | */ |
Moritz Pflanzer | 7655a67 | 2017-09-23 11:57:33 +0100 | [diff] [blame] | 242 | template <typename T, typename U = AbsoluteTolerance<T>> |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 243 | bool validate(T target, T reference, U tolerance = AbsoluteTolerance<T>()); |
| 244 | |
| 245 | /** Validate key points. */ |
| 246 | template <typename T, typename U, typename V = AbsoluteTolerance<float>> |
Georgios Pinitas | 5962f13 | 2017-12-11 16:59:29 +0000 | [diff] [blame] | 247 | void validate_keypoints(T target_first, T target_last, U reference_first, U reference_last, V tolerance = AbsoluteTolerance<float>(), |
| 248 | float allowed_missing_percentage = 5.f, float allowed_mismatch_percentage = 5.f); |
steniu01 | 960b084 | 2017-06-23 11:44:34 +0100 | [diff] [blame] | 249 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 250 | /** Compare values with a tolerance. */ |
Michele Di Giorgio | ef4b4ae | 2017-07-04 17:19:43 +0100 | [diff] [blame] | 251 | template <typename T> |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 252 | struct compare_base |
Michele Di Giorgio | ef4b4ae | 2017-07-04 17:19:43 +0100 | [diff] [blame] | 253 | { |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 254 | /** Construct a comparison object. |
| 255 | * |
| 256 | * @param[in] target Target value. |
| 257 | * @param[in] reference Reference value. |
| 258 | * @param[in] tolerance Allowed tolerance. |
| 259 | */ |
John Richardson | 9c450cc | 2017-11-22 12:00:41 +0000 | [diff] [blame] | 260 | compare_base(typename T::value_type target, typename T::value_type reference, T tolerance = T(0)) |
| 261 | : _target{ target }, _reference{ reference }, _tolerance{ tolerance } |
Michele Di Giorgio | ef4b4ae | 2017-07-04 17:19:43 +0100 | [diff] [blame] | 262 | { |
Michele Di Giorgio | ef4b4ae | 2017-07-04 17:19:43 +0100 | [diff] [blame] | 263 | } |
| 264 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 265 | typename T::value_type _target{}; /**< Target value */ |
| 266 | typename T::value_type _reference{}; /**< Reference value */ |
| 267 | T _tolerance{}; /**< Tolerance value */ |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 268 | }; |
Michele Di Giorgio | ef4b4ae | 2017-07-04 17:19:43 +0100 | [diff] [blame] | 269 | |
Moritz Pflanzer | 5b61fd3 | 2017-09-12 15:51:33 +0100 | [diff] [blame] | 270 | template <typename T> |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 271 | struct compare; |
| 272 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 273 | /** Compare values with an absolute tolerance */ |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 274 | template <typename U> |
Moritz Pflanzer | 5b61fd3 | 2017-09-12 15:51:33 +0100 | [diff] [blame] | 275 | struct compare<AbsoluteTolerance<U>> : public compare_base<AbsoluteTolerance<U>> |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 276 | { |
| 277 | using compare_base<AbsoluteTolerance<U>>::compare_base; |
| 278 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 279 | /** Perform comparison */ |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 280 | operator bool() const |
| 281 | { |
Ioan-Cristian Szabo | 33fd07b | 2017-10-26 15:42:24 +0100 | [diff] [blame] | 282 | if(!support::cpp11::isfinite(this->_target) || !support::cpp11::isfinite(this->_reference)) |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 283 | { |
| 284 | return false; |
| 285 | } |
| 286 | else if(this->_target == this->_reference) |
| 287 | { |
| 288 | return true; |
| 289 | } |
| 290 | |
Moritz Pflanzer | 5b61fd3 | 2017-09-12 15:51:33 +0100 | [diff] [blame] | 291 | using comparison_type = typename std::conditional<std::is_integral<U>::value, int64_t, U>::type; |
| 292 | |
| 293 | const comparison_type abs_difference(std::abs(static_cast<comparison_type>(this->_target) - static_cast<comparison_type>(this->_reference))); |
| 294 | |
| 295 | return abs_difference <= static_cast<comparison_type>(this->_tolerance); |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 296 | } |
| 297 | }; |
| 298 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 299 | /** Compare values with a relative tolerance */ |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 300 | template <typename U> |
Moritz Pflanzer | 5b61fd3 | 2017-09-12 15:51:33 +0100 | [diff] [blame] | 301 | struct compare<RelativeTolerance<U>> : public compare_base<RelativeTolerance<U>> |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 302 | { |
steniu01 | 3e05e4e | 2017-08-25 17:18:01 +0100 | [diff] [blame] | 303 | using compare_base<RelativeTolerance<U>>::compare_base; |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 304 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 305 | /** Perform comparison */ |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 306 | operator bool() const |
| 307 | { |
Ioan-Cristian Szabo | 33fd07b | 2017-10-26 15:42:24 +0100 | [diff] [blame] | 308 | if(!support::cpp11::isfinite(this->_target) || !support::cpp11::isfinite(this->_reference)) |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 309 | { |
| 310 | return false; |
| 311 | } |
steniu01 | 3e05e4e | 2017-08-25 17:18:01 +0100 | [diff] [blame] | 312 | else if(this->_target == this->_reference) |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 313 | { |
| 314 | return true; |
| 315 | } |
| 316 | |
Moritz Pflanzer | ff1c360 | 2017-09-22 12:41:25 +0100 | [diff] [blame] | 317 | 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 Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 318 | |
steniu01 | 3e05e4e | 2017-08-25 17:18:01 +0100 | [diff] [blame] | 319 | if(std::abs(static_cast<double>(this->_reference) - static_cast<double>(this->_target)) <= epsilon) |
| 320 | { |
| 321 | return true; |
| 322 | } |
| 323 | else |
| 324 | { |
| 325 | 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 |
| 326 | { |
| 327 | return false; |
| 328 | } |
| 329 | |
Isabella Gottardi | 8df6c45 | 2018-03-12 13:26:28 +0000 | [diff] [blame] | 330 | const double relative_change = std::abs((static_cast<double>(this->_target) - static_cast<double>(this->_reference)) / this->_reference); |
steniu01 | 3e05e4e | 2017-08-25 17:18:01 +0100 | [diff] [blame] | 331 | |
| 332 | return relative_change <= static_cast<U>(this->_tolerance); |
| 333 | } |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 334 | } |
| 335 | }; |
| 336 | |
| 337 | template <typename T, typename U> |
Michele Di Giorgio | ff6c260 | 2018-02-26 15:22:16 +0000 | [diff] [blame] | 338 | void validate(const IAccessor &tensor, const SimpleTensor<T> &reference, U tolerance_value, float tolerance_number, float absolute_tolerance_value) |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 339 | { |
| 340 | // Validate with valid region covering the entire shape |
Michele Di Giorgio | ff6c260 | 2018-02-26 15:22:16 +0000 | [diff] [blame] | 341 | validate(tensor, reference, shape_to_valid_region(tensor.shape()), tolerance_value, tolerance_number, absolute_tolerance_value); |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 342 | } |
| 343 | |
John Richardson | 9c450cc | 2017-11-22 12:00:41 +0000 | [diff] [blame] | 344 | template <typename T, typename U, typename = typename std::enable_if<std::is_integral<T>::value>::type> |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 345 | void validate_wrap(const IAccessor &tensor, const SimpleTensor<T> &reference, U tolerance_value, float tolerance_number) |
| 346 | { |
| 347 | // Validate with valid region covering the entire shape |
| 348 | validate_wrap(tensor, reference, shape_to_valid_region(tensor.shape()), tolerance_value, tolerance_number); |
| 349 | } |
| 350 | |
| 351 | template <typename T, typename U> |
Michele Di Giorgio | ff6c260 | 2018-02-26 15:22:16 +0000 | [diff] [blame] | 352 | void validate(const IAccessor &tensor, const SimpleTensor<T> &reference, const ValidRegion &valid_region, U tolerance_value, float tolerance_number, float absolute_tolerance_value) |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 353 | { |
| 354 | int64_t num_mismatches = 0; |
| 355 | int64_t num_elements = 0; |
| 356 | |
| 357 | ARM_COMPUTE_EXPECT_EQUAL(tensor.element_size(), reference.element_size(), framework::LogLevel::ERRORS); |
| 358 | ARM_COMPUTE_EXPECT_EQUAL(tensor.data_type(), reference.data_type(), framework::LogLevel::ERRORS); |
| 359 | |
| 360 | if(reference.format() != Format::UNKNOWN) |
| 361 | { |
| 362 | ARM_COMPUTE_EXPECT_EQUAL(tensor.format(), reference.format(), framework::LogLevel::ERRORS); |
| 363 | } |
| 364 | |
| 365 | ARM_COMPUTE_EXPECT_EQUAL(tensor.num_channels(), reference.num_channels(), framework::LogLevel::ERRORS); |
| 366 | ARM_COMPUTE_EXPECT(compare_dimensions(tensor.shape(), reference.shape()), framework::LogLevel::ERRORS); |
| 367 | |
| 368 | const int min_elements = std::min(tensor.num_elements(), reference.num_elements()); |
| 369 | const int min_channels = std::min(tensor.num_channels(), reference.num_channels()); |
| 370 | |
| 371 | // Iterate over all elements within valid region, e.g. U8, S16, RGB888, ... |
| 372 | for(int element_idx = 0; element_idx < min_elements; ++element_idx) |
| 373 | { |
| 374 | const Coordinates id = index2coord(reference.shape(), element_idx); |
| 375 | |
| 376 | if(is_in_valid_region(valid_region, id)) |
| 377 | { |
| 378 | // Iterate over all channels within one element |
| 379 | for(int c = 0; c < min_channels; ++c) |
| 380 | { |
| 381 | const T &target_value = reinterpret_cast<const T *>(tensor(id))[c]; |
| 382 | const T &reference_value = reinterpret_cast<const T *>(reference(id))[c]; |
| 383 | |
Michalis Spyrou | 23fe7c2 | 2018-02-26 10:42:01 +0000 | [diff] [blame] | 384 | if(!compare<U>(target_value, reference_value, tolerance_value)) |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 385 | { |
Michele Di Giorgio | ff6c260 | 2018-02-26 15:22:16 +0000 | [diff] [blame] | 386 | if(absolute_tolerance_value != 0.f) |
| 387 | { |
| 388 | const AbsoluteTolerance<float> abs_tolerance(absolute_tolerance_value); |
| 389 | if(compare<AbsoluteTolerance<float>>(target_value, reference_value, abs_tolerance)) |
| 390 | { |
| 391 | continue; |
| 392 | } |
| 393 | } |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 394 | ARM_COMPUTE_TEST_INFO("id = " << id); |
| 395 | ARM_COMPUTE_TEST_INFO("channel = " << c); |
| 396 | ARM_COMPUTE_TEST_INFO("target = " << std::setprecision(5) << framework::make_printable(target_value)); |
| 397 | ARM_COMPUTE_TEST_INFO("reference = " << std::setprecision(5) << framework::make_printable(reference_value)); |
| 398 | ARM_COMPUTE_TEST_INFO("tolerance = " << std::setprecision(5) << framework::make_printable(static_cast<typename U::value_type>(tolerance_value))); |
steniu01 | 172c58d | 2017-08-31 13:49:08 +0100 | [diff] [blame] | 399 | framework::ARM_COMPUTE_PRINT_INFO(); |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 400 | |
| 401 | ++num_mismatches; |
| 402 | } |
| 403 | |
| 404 | ++num_elements; |
| 405 | } |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | if(num_elements > 0) |
| 410 | { |
| 411 | const int64_t absolute_tolerance_number = tolerance_number * num_elements; |
| 412 | const float percent_mismatches = static_cast<float>(num_mismatches) / num_elements * 100.f; |
| 413 | |
| 414 | ARM_COMPUTE_TEST_INFO(num_mismatches << " values (" << std::fixed << std::setprecision(2) << percent_mismatches |
| 415 | << "%) mismatched (maximum tolerated " << std::setprecision(2) << tolerance_number << "%)"); |
| 416 | ARM_COMPUTE_EXPECT(num_mismatches <= absolute_tolerance_number, framework::LogLevel::ERRORS); |
Michele Di Giorgio | ef4b4ae | 2017-07-04 17:19:43 +0100 | [diff] [blame] | 417 | } |
| 418 | } |
Giorgio Arena | fc2817d | 2017-06-27 17:26:37 +0100 | [diff] [blame] | 419 | |
John Richardson | 9c450cc | 2017-11-22 12:00:41 +0000 | [diff] [blame] | 420 | template <typename T, typename U, typename = typename std::enable_if<std::is_integral<T>::value>::type> |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 421 | void validate_wrap(const IAccessor &tensor, const SimpleTensor<T> &reference, const ValidRegion &valid_region, U tolerance_value, float tolerance_number) |
| 422 | { |
| 423 | int64_t num_mismatches = 0; |
| 424 | int64_t num_elements = 0; |
| 425 | |
| 426 | ARM_COMPUTE_EXPECT_EQUAL(tensor.element_size(), reference.element_size(), framework::LogLevel::ERRORS); |
| 427 | ARM_COMPUTE_EXPECT_EQUAL(tensor.data_type(), reference.data_type(), framework::LogLevel::ERRORS); |
| 428 | |
| 429 | if(reference.format() != Format::UNKNOWN) |
| 430 | { |
| 431 | ARM_COMPUTE_EXPECT_EQUAL(tensor.format(), reference.format(), framework::LogLevel::ERRORS); |
| 432 | } |
| 433 | |
| 434 | ARM_COMPUTE_EXPECT_EQUAL(tensor.num_channels(), reference.num_channels(), framework::LogLevel::ERRORS); |
| 435 | ARM_COMPUTE_EXPECT(compare_dimensions(tensor.shape(), reference.shape()), framework::LogLevel::ERRORS); |
| 436 | |
| 437 | const int min_elements = std::min(tensor.num_elements(), reference.num_elements()); |
| 438 | const int min_channels = std::min(tensor.num_channels(), reference.num_channels()); |
| 439 | |
| 440 | // Iterate over all elements within valid region, e.g. U8, S16, RGB888, ... |
| 441 | for(int element_idx = 0; element_idx < min_elements; ++element_idx) |
| 442 | { |
| 443 | const Coordinates id = index2coord(reference.shape(), element_idx); |
| 444 | |
| 445 | if(is_in_valid_region(valid_region, id)) |
| 446 | { |
| 447 | // Iterate over all channels within one element |
| 448 | for(int c = 0; c < min_channels; ++c) |
| 449 | { |
| 450 | const T &target_value = reinterpret_cast<const T *>(tensor(id))[c]; |
| 451 | const T &reference_value = reinterpret_cast<const T *>(reference(id))[c]; |
| 452 | |
| 453 | bool equal = compare<U>(target_value, reference_value, tolerance_value); |
| 454 | |
John Richardson | 9c450cc | 2017-11-22 12:00:41 +0000 | [diff] [blame] | 455 | // check for wrapping |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 456 | if(!equal) |
| 457 | { |
John Richardson | 9c450cc | 2017-11-22 12:00:41 +0000 | [diff] [blame] | 458 | if(!support::cpp11::isfinite(target_value) || !support::cpp11::isfinite(reference_value)) |
| 459 | { |
| 460 | equal = false; |
| 461 | } |
| 462 | else |
| 463 | { |
| 464 | using limits_type = typename std::make_unsigned<T>::type; |
| 465 | |
| 466 | uint64_t max = std::numeric_limits<limits_type>::max(); |
| 467 | uint64_t abs_sum = std::abs(static_cast<int64_t>(target_value)) + std::abs(static_cast<int64_t>(reference_value)); |
| 468 | uint64_t wrap_difference = max - abs_sum; |
| 469 | |
| 470 | equal = wrap_difference < static_cast<uint64_t>(tolerance_value); |
| 471 | } |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | if(!equal) |
| 475 | { |
| 476 | ARM_COMPUTE_TEST_INFO("id = " << id); |
| 477 | ARM_COMPUTE_TEST_INFO("channel = " << c); |
| 478 | ARM_COMPUTE_TEST_INFO("target = " << std::setprecision(5) << framework::make_printable(target_value)); |
| 479 | ARM_COMPUTE_TEST_INFO("reference = " << std::setprecision(5) << framework::make_printable(reference_value)); |
John Richardson | 9c450cc | 2017-11-22 12:00:41 +0000 | [diff] [blame] | 480 | ARM_COMPUTE_TEST_INFO("wrap_tolerance = " << std::setprecision(5) << framework::make_printable(static_cast<typename U::value_type>(tolerance_value))); |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 481 | framework::ARM_COMPUTE_PRINT_INFO(); |
| 482 | |
| 483 | ++num_mismatches; |
| 484 | } |
| 485 | |
| 486 | ++num_elements; |
| 487 | } |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | if(num_elements > 0) |
| 492 | { |
| 493 | const int64_t absolute_tolerance_number = tolerance_number * num_elements; |
| 494 | const float percent_mismatches = static_cast<float>(num_mismatches) / num_elements * 100.f; |
| 495 | |
| 496 | ARM_COMPUTE_TEST_INFO(num_mismatches << " values (" << std::fixed << std::setprecision(2) << percent_mismatches |
| 497 | << "%) mismatched (maximum tolerated " << std::setprecision(2) << tolerance_number << "%)"); |
| 498 | ARM_COMPUTE_EXPECT(num_mismatches <= absolute_tolerance_number, framework::LogLevel::ERRORS); |
| 499 | } |
| 500 | } |
| 501 | |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 502 | template <typename T, typename U> |
Michele Di Giorgio | ff6c260 | 2018-02-26 15:22:16 +0000 | [diff] [blame] | 503 | void validate(const IAccessor &tensor, const SimpleTensor<T> &reference, const SimpleTensor<T> &valid_mask, U tolerance_value, float tolerance_number, float absolute_tolerance_value) |
Isabella Gottardi | 83be745 | 2017-08-29 13:47:03 +0100 | [diff] [blame] | 504 | { |
| 505 | int64_t num_mismatches = 0; |
| 506 | int64_t num_elements = 0; |
| 507 | |
| 508 | ARM_COMPUTE_EXPECT_EQUAL(tensor.element_size(), reference.element_size(), framework::LogLevel::ERRORS); |
| 509 | ARM_COMPUTE_EXPECT_EQUAL(tensor.data_type(), reference.data_type(), framework::LogLevel::ERRORS); |
| 510 | |
| 511 | if(reference.format() != Format::UNKNOWN) |
| 512 | { |
| 513 | ARM_COMPUTE_EXPECT_EQUAL(tensor.format(), reference.format(), framework::LogLevel::ERRORS); |
| 514 | } |
| 515 | |
| 516 | ARM_COMPUTE_EXPECT_EQUAL(tensor.num_channels(), reference.num_channels(), framework::LogLevel::ERRORS); |
| 517 | ARM_COMPUTE_EXPECT(compare_dimensions(tensor.shape(), reference.shape()), framework::LogLevel::ERRORS); |
| 518 | |
| 519 | const int min_elements = std::min(tensor.num_elements(), reference.num_elements()); |
| 520 | const int min_channels = std::min(tensor.num_channels(), reference.num_channels()); |
| 521 | |
| 522 | // Iterate over all elements within valid region, e.g. U8, S16, RGB888, ... |
| 523 | for(int element_idx = 0; element_idx < min_elements; ++element_idx) |
| 524 | { |
| 525 | const Coordinates id = index2coord(reference.shape(), element_idx); |
| 526 | |
| 527 | if(valid_mask[element_idx] == 1) |
| 528 | { |
| 529 | // Iterate over all channels within one element |
| 530 | for(int c = 0; c < min_channels; ++c) |
| 531 | { |
| 532 | const T &target_value = reinterpret_cast<const T *>(tensor(id))[c]; |
| 533 | const T &reference_value = reinterpret_cast<const T *>(reference(id))[c]; |
| 534 | |
| 535 | if(!compare<U>(target_value, reference_value, tolerance_value)) |
| 536 | { |
Michele Di Giorgio | ff6c260 | 2018-02-26 15:22:16 +0000 | [diff] [blame] | 537 | if(absolute_tolerance_value != 0.f) |
| 538 | { |
| 539 | const AbsoluteTolerance<float> abs_tolerance(absolute_tolerance_value); |
| 540 | if(compare<AbsoluteTolerance<float>>(target_value, reference_value, abs_tolerance)) |
| 541 | { |
| 542 | continue; |
| 543 | } |
| 544 | } |
Isabella Gottardi | 83be745 | 2017-08-29 13:47:03 +0100 | [diff] [blame] | 545 | ARM_COMPUTE_TEST_INFO("id = " << id); |
| 546 | ARM_COMPUTE_TEST_INFO("channel = " << c); |
| 547 | ARM_COMPUTE_TEST_INFO("target = " << std::setprecision(5) << framework::make_printable(target_value)); |
| 548 | ARM_COMPUTE_TEST_INFO("reference = " << std::setprecision(5) << framework::make_printable(reference_value)); |
| 549 | ARM_COMPUTE_TEST_INFO("tolerance = " << std::setprecision(5) << framework::make_printable(static_cast<typename U::value_type>(tolerance_value))); |
| 550 | framework::ARM_COMPUTE_PRINT_INFO(); |
| 551 | |
| 552 | ++num_mismatches; |
| 553 | } |
| 554 | |
| 555 | ++num_elements; |
| 556 | } |
| 557 | } |
| 558 | else |
| 559 | { |
| 560 | ++num_elements; |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | if(num_elements > 0) |
| 565 | { |
| 566 | const int64_t absolute_tolerance_number = tolerance_number * num_elements; |
| 567 | const float percent_mismatches = static_cast<float>(num_mismatches) / num_elements * 100.f; |
| 568 | |
| 569 | ARM_COMPUTE_TEST_INFO(num_mismatches << " values (" << std::fixed << std::setprecision(2) << percent_mismatches |
| 570 | << "%) mismatched (maximum tolerated " << std::setprecision(2) << tolerance_number << "%)"); |
| 571 | ARM_COMPUTE_EXPECT(num_mismatches <= absolute_tolerance_number, framework::LogLevel::ERRORS); |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | template <typename T, typename U> |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 576 | bool validate(T target, T reference, U tolerance) |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 577 | { |
| 578 | ARM_COMPUTE_TEST_INFO("reference = " << std::setprecision(5) << framework::make_printable(reference)); |
| 579 | ARM_COMPUTE_TEST_INFO("target = " << std::setprecision(5) << framework::make_printable(target)); |
| 580 | ARM_COMPUTE_TEST_INFO("tolerance = " << std::setprecision(5) << framework::make_printable(static_cast<typename U::value_type>(tolerance))); |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 581 | |
| 582 | const bool equal = compare<U>(target, reference, tolerance); |
| 583 | |
| 584 | ARM_COMPUTE_EXPECT(equal, framework::LogLevel::ERRORS); |
| 585 | |
| 586 | return equal; |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 587 | } |
John Richardson | f89a49f | 2017-09-05 11:21:56 +0100 | [diff] [blame] | 588 | |
| 589 | template <typename T, typename U> |
| 590 | void validate_min_max_loc(const MinMaxLocationValues<T> &target, const MinMaxLocationValues<U> &reference) |
| 591 | { |
| 592 | ARM_COMPUTE_EXPECT_EQUAL(target.min, reference.min, framework::LogLevel::ERRORS); |
| 593 | ARM_COMPUTE_EXPECT_EQUAL(target.max, reference.max, framework::LogLevel::ERRORS); |
| 594 | |
| 595 | ARM_COMPUTE_EXPECT_EQUAL(target.min_loc.size(), reference.min_loc.size(), framework::LogLevel::ERRORS); |
| 596 | ARM_COMPUTE_EXPECT_EQUAL(target.max_loc.size(), reference.max_loc.size(), framework::LogLevel::ERRORS); |
| 597 | |
| 598 | for(uint32_t i = 0; i < target.min_loc.size(); ++i) |
| 599 | { |
| 600 | const auto same_coords = std::find_if(reference.min_loc.begin(), reference.min_loc.end(), [&target, i](Coordinates2D coord) |
| 601 | { |
| 602 | return coord.x == target.min_loc.at(i).x && coord.y == target.min_loc.at(i).y; |
| 603 | }); |
| 604 | |
| 605 | ARM_COMPUTE_EXPECT(same_coords != reference.min_loc.end(), framework::LogLevel::ERRORS); |
| 606 | } |
| 607 | |
| 608 | for(uint32_t i = 0; i < target.max_loc.size(); ++i) |
| 609 | { |
| 610 | const auto same_coords = std::find_if(reference.max_loc.begin(), reference.max_loc.end(), [&target, i](Coordinates2D coord) |
| 611 | { |
| 612 | return coord.x == target.max_loc.at(i).x && coord.y == target.max_loc.at(i).y; |
| 613 | }); |
| 614 | |
| 615 | ARM_COMPUTE_EXPECT(same_coords != reference.max_loc.end(), framework::LogLevel::ERRORS); |
| 616 | } |
| 617 | } |
| 618 | |
Abe Mbise | 562fe0f | 2018-02-09 14:13:02 +0000 | [diff] [blame] | 619 | /** Check which keypoints from [first1, last1) are missing in [first2, last2) */ |
| 620 | template <typename T, typename U, typename V> |
| 621 | std::pair<int64_t, int64_t> compare_keypoints(T first1, T last1, U first2, U last2, V tolerance, bool check_mismatches = true) |
| 622 | { |
| 623 | /* Keypoint (x,y) should have similar strength (within tolerance) and other properties in both reference and target */ |
| 624 | const auto compare_props_eq = [&](const KeyPoint & lhs, const KeyPoint & rhs) |
| 625 | { |
| 626 | return compare<V>(lhs.strength, rhs.strength, tolerance) |
| 627 | && lhs.tracking_status == rhs.tracking_status |
| 628 | && lhs.scale == rhs.scale |
| 629 | && lhs.orientation == rhs.orientation |
| 630 | && lhs.error == rhs.error; |
| 631 | }; |
| 632 | |
| 633 | /* Used to sort KeyPoints by coordinates (x, y) */ |
| 634 | const auto compare_coords_lt = [](const KeyPoint & lhs, const KeyPoint & rhs) |
| 635 | { |
| 636 | return std::tie(lhs.x, lhs.y) < std::tie(rhs.x, rhs.y); |
| 637 | }; |
| 638 | |
| 639 | std::sort(first1, last1, compare_coords_lt); |
| 640 | std::sort(first2, last2, compare_coords_lt); |
| 641 | |
| 642 | if(check_mismatches) |
| 643 | { |
| 644 | ARM_COMPUTE_TEST_INFO("Checking for mismatches: ref count = " << std::distance(first1, last1) << " \ttarget count = " << std::distance(first2, last2)); |
| 645 | } |
| 646 | |
| 647 | int64_t num_missing = 0; |
| 648 | int64_t num_mismatches = 0; |
| 649 | bool rest_missing = false; |
| 650 | |
| 651 | while(first1 != last1) |
| 652 | { |
| 653 | if(first2 == last2) |
| 654 | { |
| 655 | rest_missing = true; |
| 656 | break; |
| 657 | } |
| 658 | |
| 659 | if(compare_coords_lt(*first1, *first2)) |
| 660 | { |
| 661 | ++num_missing; |
| 662 | ARM_COMPUTE_TEST_INFO("Key point not found"); |
| 663 | ARM_COMPUTE_TEST_INFO("keypoint1 = " << *first1++); |
| 664 | } |
| 665 | else |
| 666 | { |
| 667 | if(!compare_coords_lt(*first2, *first1)) // Equal coordinates |
| 668 | { |
| 669 | if(check_mismatches && !compare_props_eq(*first1, *first2)) // Check other properties |
| 670 | { |
| 671 | ++num_mismatches; |
| 672 | ARM_COMPUTE_TEST_INFO("Mismatching keypoint"); |
| 673 | ARM_COMPUTE_TEST_INFO("keypoint1 [ref] = " << *first1); |
| 674 | ARM_COMPUTE_TEST_INFO("keypoint2 [tgt] = " << *first2); |
| 675 | } |
| 676 | ++first1; |
| 677 | } |
| 678 | ++first2; |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | if(rest_missing) |
| 683 | { |
| 684 | while(first1 != last1) |
| 685 | { |
| 686 | ++num_missing; |
| 687 | ARM_COMPUTE_TEST_INFO("Key point not found"); |
| 688 | ARM_COMPUTE_TEST_INFO("keypoint1 = " << *first1++); |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | return std::make_pair(num_missing, num_mismatches); |
| 693 | } |
| 694 | |
| 695 | template <typename T, typename U, typename V> |
| 696 | void validate_keypoints(T target_first, T target_last, U reference_first, U reference_last, V tolerance, float allowed_missing_percentage, float allowed_mismatch_percentage) |
| 697 | { |
| 698 | const int64_t num_elements_target = std::distance(target_first, target_last); |
| 699 | const int64_t num_elements_reference = std::distance(reference_first, reference_last); |
| 700 | |
| 701 | int64_t num_missing = 0; |
| 702 | int64_t num_mismatches = 0; |
| 703 | |
| 704 | if(num_elements_reference > 0) |
| 705 | { |
| 706 | std::tie(num_missing, num_mismatches) = compare_keypoints(reference_first, reference_last, target_first, target_last, tolerance); |
| 707 | |
| 708 | const float percent_missing = static_cast<float>(num_missing) / num_elements_reference * 100.f; |
| 709 | const float percent_mismatches = static_cast<float>(num_mismatches) / num_elements_reference * 100.f; |
| 710 | |
| 711 | ARM_COMPUTE_TEST_INFO(num_missing << " keypoints (" << std::fixed << std::setprecision(2) << percent_missing << "%) in ref are missing from target"); |
| 712 | ARM_COMPUTE_TEST_INFO("Missing (not in tgt): " << num_missing << "/" << num_elements_reference << " = " << std::fixed << std::setprecision(2) << percent_missing |
| 713 | << "% \tMax allowed: " << allowed_missing_percentage << "%"); |
| 714 | ARM_COMPUTE_EXPECT(percent_missing <= allowed_missing_percentage, framework::LogLevel::ERRORS); |
| 715 | |
| 716 | ARM_COMPUTE_TEST_INFO(num_mismatches << " keypoints (" << std::fixed << std::setprecision(2) << percent_mismatches << "%) mismatched"); |
| 717 | ARM_COMPUTE_TEST_INFO("Mismatched keypoints: " << num_mismatches << "/" << num_elements_reference << " = " << std::fixed << std::setprecision(2) << percent_mismatches |
| 718 | << "% \tMax allowed: " << allowed_mismatch_percentage << "%"); |
| 719 | ARM_COMPUTE_EXPECT(percent_mismatches <= allowed_mismatch_percentage, framework::LogLevel::ERRORS); |
| 720 | } |
| 721 | |
| 722 | if(num_elements_target > 0) |
| 723 | { |
| 724 | // Note: no need to check for mismatches a second time (last argument is 'false') |
| 725 | std::tie(num_missing, num_mismatches) = compare_keypoints(target_first, target_last, reference_first, reference_last, tolerance, false); |
| 726 | |
| 727 | const float percent_missing = static_cast<float>(num_missing) / num_elements_target * 100.f; |
| 728 | |
| 729 | ARM_COMPUTE_TEST_INFO(num_missing << " keypoints (" << std::fixed << std::setprecision(2) << percent_missing << "%) in target are missing from ref"); |
| 730 | ARM_COMPUTE_TEST_INFO("Missing (not in ref): " << num_missing << "/" << num_elements_target << " = " << std::fixed << std::setprecision(2) << percent_missing |
| 731 | << "% \tMax allowed: " << allowed_missing_percentage << "%"); |
| 732 | ARM_COMPUTE_EXPECT(percent_missing <= allowed_missing_percentage, framework::LogLevel::ERRORS); |
| 733 | } |
| 734 | } |
| 735 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 736 | } // namespace validation |
| 737 | } // namespace test |
| 738 | } // namespace arm_compute |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 739 | #endif /* __ARM_COMPUTE_TEST_REFERENCE_VALIDATION_H__ */ |