Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Giorgio Arena | 68e29da | 2021-02-08 16:31:10 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2021 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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [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 | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/IArray.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 28 | #include "arm_compute/core/Types.h" |
Ioan-Cristian Szabo | 33fd07b | 2017-10-26 15:42:24 +0100 | [diff] [blame] | 29 | #include "support/ToolchainSupport.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 30 | #include "tests/IAccessor.h" |
| 31 | #include "tests/SimpleTensor.h" |
John Richardson | f89a49f | 2017-09-05 11:21:56 +0100 | [diff] [blame] | 32 | #include "tests/Types.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 33 | #include "tests/Utils.h" |
| 34 | #include "tests/framework/Asserts.h" |
| 35 | #include "tests/framework/Exceptions.h" |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 36 | #include "utils/TypePrinter.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 37 | |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 38 | #include <iomanip> |
| 39 | #include <ios> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 40 | #include <vector> |
| 41 | |
| 42 | namespace arm_compute |
| 43 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 44 | namespace test |
| 45 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 46 | namespace validation |
| 47 | { |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 48 | /** Class reprensenting an absolute tolerance value. */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 49 | template <typename T> |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 50 | class AbsoluteTolerance |
| 51 | { |
| 52 | public: |
| 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 Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 71 | /** Implicit conversion to the underlying type. |
| 72 | * |
| 73 | * @return the underlying type. |
| 74 | */ |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 75 | constexpr operator T() const |
| 76 | { |
| 77 | return _value; |
| 78 | } |
| 79 | |
| 80 | private: |
| 81 | T _value{ std::numeric_limits<T>::epsilon() }; |
| 82 | }; |
| 83 | |
| 84 | /** Class reprensenting a relative tolerance value. */ |
steniu01 | 3e05e4e | 2017-08-25 17:18:01 +0100 | [diff] [blame] | 85 | template <typename T> |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 86 | class RelativeTolerance |
| 87 | { |
| 88 | public: |
| 89 | /** Underlying type. */ |
steniu01 | 3e05e4e | 2017-08-25 17:18:01 +0100 | [diff] [blame] | 90 | using value_type = T; |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 91 | |
| 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 Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 107 | /** Implicit conversion to the underlying type. |
| 108 | * |
| 109 | * @return the underlying type. |
| 110 | */ |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 111 | constexpr operator value_type() const |
| 112 | { |
| 113 | return _value; |
| 114 | } |
| 115 | |
| 116 | private: |
steniu01 | 3e05e4e | 2017-08-25 17:18:01 +0100 | [diff] [blame] | 117 | value_type _value{ std::numeric_limits<T>::epsilon() }; |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | /** Print AbsoluteTolerance type. */ |
| 121 | template <typename T> |
| 122 | inline ::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. */ |
steniu01 | 3e05e4e | 2017-08-25 17:18:01 +0100 | [diff] [blame] | 130 | template <typename T> |
| 131 | inline ::std::ostream &operator<<(::std::ostream &os, const RelativeTolerance<T> &tolerance) |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 132 | { |
steniu01 | 3e05e4e | 2017-08-25 17:18:01 +0100 | [diff] [blame] | 133 | os << static_cast<typename RelativeTolerance<T>::value_type>(tolerance); |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 134 | |
| 135 | return os; |
| 136 | } |
| 137 | |
| 138 | template <typename T> |
Giorgio Arena | 563494c | 2018-04-30 17:29:41 +0100 | [diff] [blame] | 139 | bool compare_dimensions(const Dimensions<T> &dimensions1, const Dimensions<T> &dimensions2, const DataLayout &data_layout = DataLayout::NCHW) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 140 | { |
Giorgio Arena | 563494c | 2018-04-30 17:29:41 +0100 | [diff] [blame] | 141 | ARM_COMPUTE_ERROR_ON(data_layout == DataLayout::UNKNOWN); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 142 | |
Giorgio Arena | 563494c | 2018-04-30 17:29:41 +0100 | [diff] [blame] | 143 | if(data_layout == DataLayout::NCHW) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 144 | { |
Giorgio Arena | 563494c | 2018-04-30 17:29:41 +0100 | [diff] [blame] | 145 | if(dimensions1.num_dimensions() != dimensions2.num_dimensions()) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 146 | { |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 147 | return false; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 148 | } |
Giorgio Arena | 563494c | 2018-04-30 17:29:41 +0100 | [diff] [blame] | 149 | |
| 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 | { |
SiCong Li | 37d65e4 | 2020-11-06 09:55:04 +0000 | [diff] [blame] | 160 | // In case a 1D/2D shape becomes 3D after permutation, the permuted tensor will have two/one dimension(s) more and the first (two) value(s) will be 1 |
| 161 | // clang-format off |
Gian Marco Iodice | 40471d1 | 2021-04-26 08:39:28 +0100 | [diff] [blame] | 162 | const auto max_dims = std::max(dimensions1.num_dimensions(), dimensions2.num_dimensions()); |
| 163 | for(unsigned int i = 3; i < max_dims; ++i) |
Giorgio Arena | 563494c | 2018-04-30 17:29:41 +0100 | [diff] [blame] | 164 | { |
Gian Marco Iodice | 40471d1 | 2021-04-26 08:39:28 +0100 | [diff] [blame] | 165 | if(dimensions1[i] != dimensions2[i]) |
| 166 | { |
| 167 | return false; |
| 168 | } |
Giorgio Arena | 563494c | 2018-04-30 17:29:41 +0100 | [diff] [blame] | 169 | } |
SiCong Li | 37d65e4 | 2020-11-06 09:55:04 +0000 | [diff] [blame] | 170 | // clang-format on |
Giorgio Arena | 563494c | 2018-04-30 17:29:41 +0100 | [diff] [blame] | 171 | |
| 172 | if((dimensions1[0] != dimensions2[2]) || (dimensions1[1] != dimensions2[0]) || (dimensions1[2] != dimensions2[1])) |
| 173 | { |
| 174 | return false; |
| 175 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | return true; |
| 179 | } |
| 180 | |
| 181 | /** Validate valid regions. |
| 182 | * |
| 183 | * - Dimensionality has to be the same. |
| 184 | * - Anchors have to match. |
| 185 | * - Shapes have to match. |
| 186 | */ |
| 187 | void validate(const arm_compute::ValidRegion ®ion, const arm_compute::ValidRegion &reference); |
| 188 | |
| 189 | /** Validate padding. |
| 190 | * |
| 191 | * Padding on all sides has to be the same. |
| 192 | */ |
| 193 | void validate(const arm_compute::PaddingSize &padding, const arm_compute::PaddingSize &reference); |
| 194 | |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 195 | /** Validate padding. |
| 196 | * |
| 197 | * Padding on all sides has to be the same. |
| 198 | */ |
| 199 | void validate(const arm_compute::PaddingSize &padding, const arm_compute::PaddingSize &width_reference, const arm_compute::PaddingSize &height_reference); |
| 200 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 201 | /** Validate tensors. |
| 202 | * |
| 203 | * - Dimensionality has to be the same. |
| 204 | * - All values have to match. |
| 205 | * |
| 206 | * @note: wrap_range allows cases where reference tensor rounds up to the wrapping point, causing it to wrap around to |
| 207 | * zero while the test tensor stays at wrapping point to pass. This may permit true erroneous cases (difference between |
| 208 | * reference tensor and test tensor is multiple of wrap_range), but such errors would be detected by |
| 209 | * other test cases. |
| 210 | */ |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 211 | template <typename T, typename U = AbsoluteTolerance<T>> |
Michele Di Giorgio | ff6c260 | 2018-02-26 15:22:16 +0000 | [diff] [blame] | 212 | void validate(const IAccessor &tensor, const SimpleTensor<T> &reference, U tolerance_value = U(), float tolerance_number = 0.f, float absolute_tolerance_value = 0.f); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 213 | |
| 214 | /** Validate tensors with valid region. |
| 215 | * |
| 216 | * - Dimensionality has to be the same. |
| 217 | * - All values have to match. |
| 218 | * |
| 219 | * @note: wrap_range allows cases where reference tensor rounds up to the wrapping point, causing it to wrap around to |
| 220 | * zero while the test tensor stays at wrapping point to pass. This may permit true erroneous cases (difference between |
| 221 | * reference tensor and test tensor is multiple of wrap_range), but such errors would be detected by |
| 222 | * other test cases. |
| 223 | */ |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 224 | template <typename T, typename U = AbsoluteTolerance<T>> |
Michele Di Giorgio | ff6c260 | 2018-02-26 15:22:16 +0000 | [diff] [blame] | 225 | 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] | 226 | |
Isabella Gottardi | 83be745 | 2017-08-29 13:47:03 +0100 | [diff] [blame] | 227 | /** Validate tensors with valid mask. |
| 228 | * |
| 229 | * - Dimensionality has to be the same. |
| 230 | * - All values have to match. |
| 231 | * |
| 232 | * @note: wrap_range allows cases where reference tensor rounds up to the wrapping point, causing it to wrap around to |
| 233 | * zero while the test tensor stays at wrapping point to pass. This may permit true erroneous cases (difference between |
| 234 | * reference tensor and test tensor is multiple of wrap_range), but such errors would be detected by |
| 235 | * other test cases. |
| 236 | */ |
| 237 | template <typename T, typename U = AbsoluteTolerance<T>> |
Michele Di Giorgio | ff6c260 | 2018-02-26 15:22:16 +0000 | [diff] [blame] | 238 | void validate(const IAccessor &tensor, const SimpleTensor<T> &reference, const SimpleTensor<T> &valid_mask, U tolerance_value = U(), float tolerance_number = 0.f, |
| 239 | float absolute_tolerance_value = 0.f); |
Isabella Gottardi | 83be745 | 2017-08-29 13:47:03 +0100 | [diff] [blame] | 240 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 241 | /** Validate tensors against constant value. |
| 242 | * |
| 243 | * - All values have to match. |
| 244 | */ |
| 245 | void validate(const IAccessor &tensor, const void *reference_value); |
| 246 | |
| 247 | /** Validate border against a constant value. |
| 248 | * |
| 249 | * - All border values have to match the specified value if mode is CONSTANT. |
| 250 | * - All border values have to be replicated if mode is REPLICATE. |
| 251 | * - Nothing is validated for mode UNDEFINED. |
| 252 | */ |
| 253 | void validate(const IAccessor &tensor, BorderSize border_size, const BorderMode &border_mode, const void *border_value); |
| 254 | |
| 255 | /** Validate classified labels against expected ones. |
| 256 | * |
| 257 | * - All values should match |
| 258 | */ |
| 259 | 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] | 260 | |
| 261 | /** Validate float value. |
| 262 | * |
| 263 | * - All values should match |
| 264 | */ |
Moritz Pflanzer | 7655a67 | 2017-09-23 11:57:33 +0100 | [diff] [blame] | 265 | template <typename T, typename U = AbsoluteTolerance<T>> |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 266 | bool validate(T target, T reference, U tolerance = AbsoluteTolerance<T>()); |
| 267 | |
Michele Di Giorgio | ef4b4ae | 2017-07-04 17:19:43 +0100 | [diff] [blame] | 268 | template <typename T> |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 269 | struct compare_base |
Michele Di Giorgio | ef4b4ae | 2017-07-04 17:19:43 +0100 | [diff] [blame] | 270 | { |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 271 | /** Construct a comparison object. |
| 272 | * |
| 273 | * @param[in] target Target value. |
| 274 | * @param[in] reference Reference value. |
| 275 | * @param[in] tolerance Allowed tolerance. |
| 276 | */ |
John Richardson | 9c450cc | 2017-11-22 12:00:41 +0000 | [diff] [blame] | 277 | compare_base(typename T::value_type target, typename T::value_type reference, T tolerance = T(0)) |
| 278 | : _target{ target }, _reference{ reference }, _tolerance{ tolerance } |
Michele Di Giorgio | ef4b4ae | 2017-07-04 17:19:43 +0100 | [diff] [blame] | 279 | { |
Michele Di Giorgio | ef4b4ae | 2017-07-04 17:19:43 +0100 | [diff] [blame] | 280 | } |
| 281 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 282 | typename T::value_type _target{}; /**< Target value */ |
| 283 | typename T::value_type _reference{}; /**< Reference value */ |
| 284 | T _tolerance{}; /**< Tolerance value */ |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 285 | }; |
Michele Di Giorgio | ef4b4ae | 2017-07-04 17:19:43 +0100 | [diff] [blame] | 286 | |
Moritz Pflanzer | 5b61fd3 | 2017-09-12 15:51:33 +0100 | [diff] [blame] | 287 | template <typename T> |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 288 | struct compare; |
| 289 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 290 | /** Compare values with an absolute tolerance */ |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 291 | template <typename U> |
Moritz Pflanzer | 5b61fd3 | 2017-09-12 15:51:33 +0100 | [diff] [blame] | 292 | struct compare<AbsoluteTolerance<U>> : public compare_base<AbsoluteTolerance<U>> |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 293 | { |
| 294 | using compare_base<AbsoluteTolerance<U>>::compare_base; |
| 295 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 296 | /** Perform comparison */ |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 297 | operator bool() const |
| 298 | { |
Ioan-Cristian Szabo | 33fd07b | 2017-10-26 15:42:24 +0100 | [diff] [blame] | 299 | if(!support::cpp11::isfinite(this->_target) || !support::cpp11::isfinite(this->_reference)) |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 300 | { |
| 301 | return false; |
| 302 | } |
| 303 | else if(this->_target == this->_reference) |
| 304 | { |
| 305 | return true; |
| 306 | } |
| 307 | |
Moritz Pflanzer | 5b61fd3 | 2017-09-12 15:51:33 +0100 | [diff] [blame] | 308 | using comparison_type = typename std::conditional<std::is_integral<U>::value, int64_t, U>::type; |
| 309 | |
| 310 | const comparison_type abs_difference(std::abs(static_cast<comparison_type>(this->_target) - static_cast<comparison_type>(this->_reference))); |
| 311 | |
| 312 | return abs_difference <= static_cast<comparison_type>(this->_tolerance); |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 313 | } |
| 314 | }; |
| 315 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 316 | /** Compare values with a relative tolerance */ |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 317 | template <typename U> |
Moritz Pflanzer | 5b61fd3 | 2017-09-12 15:51:33 +0100 | [diff] [blame] | 318 | struct compare<RelativeTolerance<U>> : public compare_base<RelativeTolerance<U>> |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 319 | { |
steniu01 | 3e05e4e | 2017-08-25 17:18:01 +0100 | [diff] [blame] | 320 | using compare_base<RelativeTolerance<U>>::compare_base; |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 321 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 322 | /** Perform comparison */ |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 323 | operator bool() const |
| 324 | { |
Ioan-Cristian Szabo | 33fd07b | 2017-10-26 15:42:24 +0100 | [diff] [blame] | 325 | if(!support::cpp11::isfinite(this->_target) || !support::cpp11::isfinite(this->_reference)) |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 326 | { |
| 327 | return false; |
| 328 | } |
steniu01 | 3e05e4e | 2017-08-25 17:18:01 +0100 | [diff] [blame] | 329 | else if(this->_target == this->_reference) |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 330 | { |
| 331 | return true; |
| 332 | } |
| 333 | |
Moritz Pflanzer | ff1c360 | 2017-09-22 12:41:25 +0100 | [diff] [blame] | 334 | 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] | 335 | |
steniu01 | 3e05e4e | 2017-08-25 17:18:01 +0100 | [diff] [blame] | 336 | if(std::abs(static_cast<double>(this->_reference) - static_cast<double>(this->_target)) <= epsilon) |
| 337 | { |
| 338 | return true; |
| 339 | } |
| 340 | else |
| 341 | { |
| 342 | 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 |
| 343 | { |
| 344 | return false; |
| 345 | } |
| 346 | |
Isabella Gottardi | 8df6c45 | 2018-03-12 13:26:28 +0000 | [diff] [blame] | 347 | 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] | 348 | |
| 349 | return relative_change <= static_cast<U>(this->_tolerance); |
| 350 | } |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 351 | } |
| 352 | }; |
| 353 | |
| 354 | template <typename T, typename U> |
Michele Di Giorgio | ff6c260 | 2018-02-26 15:22:16 +0000 | [diff] [blame] | 355 | 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] | 356 | { |
| 357 | // Validate with valid region covering the entire shape |
Giorgio Arena | 563494c | 2018-04-30 17:29:41 +0100 | [diff] [blame] | 358 | validate(tensor, reference, shape_to_valid_region(reference.shape()), tolerance_value, tolerance_number, absolute_tolerance_value); |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 359 | } |
| 360 | |
John Richardson | 9c450cc | 2017-11-22 12:00:41 +0000 | [diff] [blame] | 361 | 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] | 362 | void validate_wrap(const IAccessor &tensor, const SimpleTensor<T> &reference, U tolerance_value, float tolerance_number) |
| 363 | { |
| 364 | // Validate with valid region covering the entire shape |
Giorgio Arena | 563494c | 2018-04-30 17:29:41 +0100 | [diff] [blame] | 365 | validate_wrap(tensor, reference, shape_to_valid_region(reference.shape()), tolerance_value, tolerance_number); |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | template <typename T, typename U> |
Michele Di Giorgio | ff6c260 | 2018-02-26 15:22:16 +0000 | [diff] [blame] | 369 | 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] | 370 | { |
Giorgio Arena | 68e29da | 2021-02-08 16:31:10 +0000 | [diff] [blame] | 371 | if(framework::Framework::get().configure_only() && framework::Framework::get().new_fixture_call()) |
| 372 | { |
| 373 | return; |
| 374 | } |
| 375 | |
Michalis Spyrou | fae513c | 2019-10-16 17:41:33 +0100 | [diff] [blame] | 376 | uint64_t num_mismatches = 0; |
| 377 | uint64_t num_elements = 0; |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 378 | |
| 379 | ARM_COMPUTE_EXPECT_EQUAL(tensor.element_size(), reference.element_size(), framework::LogLevel::ERRORS); |
| 380 | ARM_COMPUTE_EXPECT_EQUAL(tensor.data_type(), reference.data_type(), framework::LogLevel::ERRORS); |
| 381 | |
| 382 | if(reference.format() != Format::UNKNOWN) |
| 383 | { |
| 384 | ARM_COMPUTE_EXPECT_EQUAL(tensor.format(), reference.format(), framework::LogLevel::ERRORS); |
| 385 | } |
| 386 | |
| 387 | ARM_COMPUTE_EXPECT_EQUAL(tensor.num_channels(), reference.num_channels(), framework::LogLevel::ERRORS); |
Giorgio Arena | 563494c | 2018-04-30 17:29:41 +0100 | [diff] [blame] | 388 | ARM_COMPUTE_EXPECT(compare_dimensions(tensor.shape(), reference.shape(), tensor.data_layout()), framework::LogLevel::ERRORS); |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 389 | |
| 390 | const int min_elements = std::min(tensor.num_elements(), reference.num_elements()); |
| 391 | const int min_channels = std::min(tensor.num_channels(), reference.num_channels()); |
| 392 | |
| 393 | // Iterate over all elements within valid region, e.g. U8, S16, RGB888, ... |
| 394 | for(int element_idx = 0; element_idx < min_elements; ++element_idx) |
| 395 | { |
| 396 | const Coordinates id = index2coord(reference.shape(), element_idx); |
| 397 | |
Giorgio Arena | 563494c | 2018-04-30 17:29:41 +0100 | [diff] [blame] | 398 | Coordinates target_id(id); |
| 399 | if(tensor.data_layout() == DataLayout::NHWC) |
| 400 | { |
| 401 | permute(target_id, PermutationVector(2U, 0U, 1U)); |
| 402 | } |
| 403 | |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 404 | if(is_in_valid_region(valid_region, id)) |
| 405 | { |
| 406 | // Iterate over all channels within one element |
| 407 | for(int c = 0; c < min_channels; ++c) |
| 408 | { |
Giorgio Arena | 563494c | 2018-04-30 17:29:41 +0100 | [diff] [blame] | 409 | const T &target_value = reinterpret_cast<const T *>(tensor(target_id))[c]; |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 410 | const T &reference_value = reinterpret_cast<const T *>(reference(id))[c]; |
| 411 | |
Michalis Spyrou | 23fe7c2 | 2018-02-26 10:42:01 +0000 | [diff] [blame] | 412 | if(!compare<U>(target_value, reference_value, tolerance_value)) |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 413 | { |
Michele Di Giorgio | ff6c260 | 2018-02-26 15:22:16 +0000 | [diff] [blame] | 414 | if(absolute_tolerance_value != 0.f) |
| 415 | { |
| 416 | const AbsoluteTolerance<float> abs_tolerance(absolute_tolerance_value); |
| 417 | if(compare<AbsoluteTolerance<float>>(target_value, reference_value, abs_tolerance)) |
| 418 | { |
| 419 | continue; |
| 420 | } |
| 421 | } |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 422 | ARM_COMPUTE_TEST_INFO("id = " << id); |
| 423 | ARM_COMPUTE_TEST_INFO("channel = " << c); |
| 424 | ARM_COMPUTE_TEST_INFO("target = " << std::setprecision(5) << framework::make_printable(target_value)); |
| 425 | ARM_COMPUTE_TEST_INFO("reference = " << std::setprecision(5) << framework::make_printable(reference_value)); |
| 426 | 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] | 427 | framework::ARM_COMPUTE_PRINT_INFO(); |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 428 | |
| 429 | ++num_mismatches; |
| 430 | } |
| 431 | |
| 432 | ++num_elements; |
| 433 | } |
| 434 | } |
| 435 | } |
| 436 | |
Michalis Spyrou | fae513c | 2019-10-16 17:41:33 +0100 | [diff] [blame] | 437 | if(num_elements != 0) |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 438 | { |
Michalis Spyrou | fae513c | 2019-10-16 17:41:33 +0100 | [diff] [blame] | 439 | const uint64_t absolute_tolerance_number = tolerance_number * num_elements; |
| 440 | const float percent_mismatches = static_cast<float>(num_mismatches) / num_elements * 100.f; |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 441 | |
| 442 | ARM_COMPUTE_TEST_INFO(num_mismatches << " values (" << std::fixed << std::setprecision(2) << percent_mismatches |
Abe Mbise | 1b99338 | 2017-12-19 13:51:59 +0000 | [diff] [blame] | 443 | << "%) mismatched (maximum tolerated " << std::setprecision(2) << tolerance_number * 100 << "%)"); |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 444 | ARM_COMPUTE_EXPECT(num_mismatches <= absolute_tolerance_number, framework::LogLevel::ERRORS); |
Michele Di Giorgio | ef4b4ae | 2017-07-04 17:19:43 +0100 | [diff] [blame] | 445 | } |
| 446 | } |
Giorgio Arena | fc2817d | 2017-06-27 17:26:37 +0100 | [diff] [blame] | 447 | |
John Richardson | 9c450cc | 2017-11-22 12:00:41 +0000 | [diff] [blame] | 448 | 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] | 449 | void validate_wrap(const IAccessor &tensor, const SimpleTensor<T> &reference, const ValidRegion &valid_region, U tolerance_value, float tolerance_number) |
| 450 | { |
Giorgio Arena | 68e29da | 2021-02-08 16:31:10 +0000 | [diff] [blame] | 451 | if(framework::Framework::get().configure_only() && framework::Framework::get().new_fixture_call()) |
| 452 | { |
| 453 | return; |
| 454 | } |
| 455 | |
Michalis Spyrou | fae513c | 2019-10-16 17:41:33 +0100 | [diff] [blame] | 456 | uint64_t num_mismatches = 0; |
| 457 | uint64_t num_elements = 0; |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 458 | |
| 459 | ARM_COMPUTE_EXPECT_EQUAL(tensor.element_size(), reference.element_size(), framework::LogLevel::ERRORS); |
| 460 | ARM_COMPUTE_EXPECT_EQUAL(tensor.data_type(), reference.data_type(), framework::LogLevel::ERRORS); |
| 461 | |
| 462 | if(reference.format() != Format::UNKNOWN) |
| 463 | { |
| 464 | ARM_COMPUTE_EXPECT_EQUAL(tensor.format(), reference.format(), framework::LogLevel::ERRORS); |
| 465 | } |
| 466 | |
| 467 | ARM_COMPUTE_EXPECT_EQUAL(tensor.num_channels(), reference.num_channels(), framework::LogLevel::ERRORS); |
Giorgio Arena | 563494c | 2018-04-30 17:29:41 +0100 | [diff] [blame] | 468 | ARM_COMPUTE_EXPECT(compare_dimensions(tensor.shape(), reference.shape(), tensor.data_layout()), framework::LogLevel::ERRORS); |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 469 | |
| 470 | const int min_elements = std::min(tensor.num_elements(), reference.num_elements()); |
| 471 | const int min_channels = std::min(tensor.num_channels(), reference.num_channels()); |
| 472 | |
| 473 | // Iterate over all elements within valid region, e.g. U8, S16, RGB888, ... |
| 474 | for(int element_idx = 0; element_idx < min_elements; ++element_idx) |
| 475 | { |
| 476 | const Coordinates id = index2coord(reference.shape(), element_idx); |
| 477 | |
Giorgio Arena | 563494c | 2018-04-30 17:29:41 +0100 | [diff] [blame] | 478 | Coordinates target_id(id); |
| 479 | if(tensor.data_layout() == DataLayout::NHWC) |
| 480 | { |
| 481 | permute(target_id, PermutationVector(2U, 0U, 1U)); |
| 482 | } |
| 483 | |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 484 | if(is_in_valid_region(valid_region, id)) |
| 485 | { |
| 486 | // Iterate over all channels within one element |
| 487 | for(int c = 0; c < min_channels; ++c) |
| 488 | { |
Giorgio Arena | 563494c | 2018-04-30 17:29:41 +0100 | [diff] [blame] | 489 | const T &target_value = reinterpret_cast<const T *>(tensor(target_id))[c]; |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 490 | const T &reference_value = reinterpret_cast<const T *>(reference(id))[c]; |
| 491 | |
| 492 | bool equal = compare<U>(target_value, reference_value, tolerance_value); |
| 493 | |
John Richardson | 9c450cc | 2017-11-22 12:00:41 +0000 | [diff] [blame] | 494 | // check for wrapping |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 495 | if(!equal) |
| 496 | { |
John Richardson | 9c450cc | 2017-11-22 12:00:41 +0000 | [diff] [blame] | 497 | if(!support::cpp11::isfinite(target_value) || !support::cpp11::isfinite(reference_value)) |
| 498 | { |
| 499 | equal = false; |
| 500 | } |
| 501 | else |
| 502 | { |
| 503 | using limits_type = typename std::make_unsigned<T>::type; |
| 504 | |
| 505 | uint64_t max = std::numeric_limits<limits_type>::max(); |
| 506 | uint64_t abs_sum = std::abs(static_cast<int64_t>(target_value)) + std::abs(static_cast<int64_t>(reference_value)); |
| 507 | uint64_t wrap_difference = max - abs_sum; |
| 508 | |
| 509 | equal = wrap_difference < static_cast<uint64_t>(tolerance_value); |
| 510 | } |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | if(!equal) |
| 514 | { |
| 515 | ARM_COMPUTE_TEST_INFO("id = " << id); |
| 516 | ARM_COMPUTE_TEST_INFO("channel = " << c); |
| 517 | ARM_COMPUTE_TEST_INFO("target = " << std::setprecision(5) << framework::make_printable(target_value)); |
| 518 | 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] | 519 | 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] | 520 | framework::ARM_COMPUTE_PRINT_INFO(); |
| 521 | |
| 522 | ++num_mismatches; |
| 523 | } |
| 524 | |
| 525 | ++num_elements; |
| 526 | } |
| 527 | } |
| 528 | } |
| 529 | |
Michalis Spyrou | fae513c | 2019-10-16 17:41:33 +0100 | [diff] [blame] | 530 | if(num_elements != 0) |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 531 | { |
Michalis Spyrou | fae513c | 2019-10-16 17:41:33 +0100 | [diff] [blame] | 532 | const uint64_t absolute_tolerance_number = tolerance_number * num_elements; |
| 533 | const float percent_mismatches = static_cast<float>(num_mismatches) / num_elements * 100.f; |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 534 | |
| 535 | ARM_COMPUTE_TEST_INFO(num_mismatches << " values (" << std::fixed << std::setprecision(2) << percent_mismatches |
Abe Mbise | 1b99338 | 2017-12-19 13:51:59 +0000 | [diff] [blame] | 536 | << "%) mismatched (maximum tolerated " << std::setprecision(2) << tolerance_number * 100 << "%)"); |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 537 | ARM_COMPUTE_EXPECT(num_mismatches <= absolute_tolerance_number, framework::LogLevel::ERRORS); |
| 538 | } |
| 539 | } |
| 540 | |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 541 | template <typename T, typename U> |
Michele Di Giorgio | ff6c260 | 2018-02-26 15:22:16 +0000 | [diff] [blame] | 542 | 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] | 543 | { |
Giorgio Arena | 68e29da | 2021-02-08 16:31:10 +0000 | [diff] [blame] | 544 | if(framework::Framework::get().configure_only() && framework::Framework::get().new_fixture_call()) |
| 545 | { |
| 546 | return; |
| 547 | } |
| 548 | |
Michalis Spyrou | fae513c | 2019-10-16 17:41:33 +0100 | [diff] [blame] | 549 | uint64_t num_mismatches = 0; |
| 550 | uint64_t num_elements = 0; |
Isabella Gottardi | 83be745 | 2017-08-29 13:47:03 +0100 | [diff] [blame] | 551 | |
| 552 | ARM_COMPUTE_EXPECT_EQUAL(tensor.element_size(), reference.element_size(), framework::LogLevel::ERRORS); |
| 553 | ARM_COMPUTE_EXPECT_EQUAL(tensor.data_type(), reference.data_type(), framework::LogLevel::ERRORS); |
| 554 | |
| 555 | if(reference.format() != Format::UNKNOWN) |
| 556 | { |
| 557 | ARM_COMPUTE_EXPECT_EQUAL(tensor.format(), reference.format(), framework::LogLevel::ERRORS); |
| 558 | } |
| 559 | |
| 560 | ARM_COMPUTE_EXPECT_EQUAL(tensor.num_channels(), reference.num_channels(), framework::LogLevel::ERRORS); |
Giorgio Arena | 563494c | 2018-04-30 17:29:41 +0100 | [diff] [blame] | 561 | ARM_COMPUTE_EXPECT(compare_dimensions(tensor.shape(), reference.shape(), tensor.data_layout()), framework::LogLevel::ERRORS); |
Isabella Gottardi | 83be745 | 2017-08-29 13:47:03 +0100 | [diff] [blame] | 562 | |
| 563 | const int min_elements = std::min(tensor.num_elements(), reference.num_elements()); |
| 564 | const int min_channels = std::min(tensor.num_channels(), reference.num_channels()); |
| 565 | |
| 566 | // Iterate over all elements within valid region, e.g. U8, S16, RGB888, ... |
| 567 | for(int element_idx = 0; element_idx < min_elements; ++element_idx) |
| 568 | { |
| 569 | const Coordinates id = index2coord(reference.shape(), element_idx); |
| 570 | |
Giorgio Arena | 563494c | 2018-04-30 17:29:41 +0100 | [diff] [blame] | 571 | Coordinates target_id(id); |
| 572 | if(tensor.data_layout() == DataLayout::NHWC) |
| 573 | { |
| 574 | permute(target_id, PermutationVector(2U, 0U, 1U)); |
| 575 | } |
| 576 | |
Isabella Gottardi | 83be745 | 2017-08-29 13:47:03 +0100 | [diff] [blame] | 577 | if(valid_mask[element_idx] == 1) |
| 578 | { |
| 579 | // Iterate over all channels within one element |
| 580 | for(int c = 0; c < min_channels; ++c) |
| 581 | { |
Giorgio Arena | 563494c | 2018-04-30 17:29:41 +0100 | [diff] [blame] | 582 | const T &target_value = reinterpret_cast<const T *>(tensor(target_id))[c]; |
Isabella Gottardi | 83be745 | 2017-08-29 13:47:03 +0100 | [diff] [blame] | 583 | const T &reference_value = reinterpret_cast<const T *>(reference(id))[c]; |
| 584 | |
| 585 | if(!compare<U>(target_value, reference_value, tolerance_value)) |
| 586 | { |
Michele Di Giorgio | ff6c260 | 2018-02-26 15:22:16 +0000 | [diff] [blame] | 587 | if(absolute_tolerance_value != 0.f) |
| 588 | { |
| 589 | const AbsoluteTolerance<float> abs_tolerance(absolute_tolerance_value); |
| 590 | if(compare<AbsoluteTolerance<float>>(target_value, reference_value, abs_tolerance)) |
| 591 | { |
| 592 | continue; |
| 593 | } |
| 594 | } |
Isabella Gottardi | 83be745 | 2017-08-29 13:47:03 +0100 | [diff] [blame] | 595 | ARM_COMPUTE_TEST_INFO("id = " << id); |
| 596 | ARM_COMPUTE_TEST_INFO("channel = " << c); |
| 597 | ARM_COMPUTE_TEST_INFO("target = " << std::setprecision(5) << framework::make_printable(target_value)); |
| 598 | ARM_COMPUTE_TEST_INFO("reference = " << std::setprecision(5) << framework::make_printable(reference_value)); |
| 599 | ARM_COMPUTE_TEST_INFO("tolerance = " << std::setprecision(5) << framework::make_printable(static_cast<typename U::value_type>(tolerance_value))); |
| 600 | framework::ARM_COMPUTE_PRINT_INFO(); |
| 601 | |
| 602 | ++num_mismatches; |
| 603 | } |
| 604 | |
| 605 | ++num_elements; |
| 606 | } |
| 607 | } |
| 608 | else |
| 609 | { |
| 610 | ++num_elements; |
| 611 | } |
| 612 | } |
| 613 | |
Michalis Spyrou | fae513c | 2019-10-16 17:41:33 +0100 | [diff] [blame] | 614 | if(num_elements != 0) |
Isabella Gottardi | 83be745 | 2017-08-29 13:47:03 +0100 | [diff] [blame] | 615 | { |
Michalis Spyrou | fae513c | 2019-10-16 17:41:33 +0100 | [diff] [blame] | 616 | const uint64_t absolute_tolerance_number = tolerance_number * num_elements; |
| 617 | const float percent_mismatches = static_cast<float>(num_mismatches) / num_elements * 100.f; |
Isabella Gottardi | 83be745 | 2017-08-29 13:47:03 +0100 | [diff] [blame] | 618 | |
| 619 | ARM_COMPUTE_TEST_INFO(num_mismatches << " values (" << std::fixed << std::setprecision(2) << percent_mismatches |
Abe Mbise | 1b99338 | 2017-12-19 13:51:59 +0000 | [diff] [blame] | 620 | << "%) mismatched (maximum tolerated " << std::setprecision(2) << tolerance_number * 100 << "%)"); |
Isabella Gottardi | 83be745 | 2017-08-29 13:47:03 +0100 | [diff] [blame] | 621 | ARM_COMPUTE_EXPECT(num_mismatches <= absolute_tolerance_number, framework::LogLevel::ERRORS); |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | template <typename T, typename U> |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 626 | bool validate(T target, T reference, U tolerance) |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 627 | { |
Giorgio Arena | 68e29da | 2021-02-08 16:31:10 +0000 | [diff] [blame] | 628 | if(framework::Framework::get().configure_only() && framework::Framework::get().new_fixture_call()) |
| 629 | { |
| 630 | return true; |
| 631 | } |
| 632 | |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 633 | ARM_COMPUTE_TEST_INFO("reference = " << std::setprecision(5) << framework::make_printable(reference)); |
| 634 | ARM_COMPUTE_TEST_INFO("target = " << std::setprecision(5) << framework::make_printable(target)); |
| 635 | 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] | 636 | |
| 637 | const bool equal = compare<U>(target, reference, tolerance); |
| 638 | |
| 639 | ARM_COMPUTE_EXPECT(equal, framework::LogLevel::ERRORS); |
| 640 | |
| 641 | return equal; |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 642 | } |
John Richardson | f89a49f | 2017-09-05 11:21:56 +0100 | [diff] [blame] | 643 | |
| 644 | template <typename T, typename U> |
| 645 | void validate_min_max_loc(const MinMaxLocationValues<T> &target, const MinMaxLocationValues<U> &reference) |
| 646 | { |
Giorgio Arena | 68e29da | 2021-02-08 16:31:10 +0000 | [diff] [blame] | 647 | if(framework::Framework::get().configure_only() && framework::Framework::get().new_fixture_call()) |
| 648 | { |
| 649 | return; |
| 650 | } |
| 651 | |
John Richardson | f89a49f | 2017-09-05 11:21:56 +0100 | [diff] [blame] | 652 | ARM_COMPUTE_EXPECT_EQUAL(target.min, reference.min, framework::LogLevel::ERRORS); |
| 653 | ARM_COMPUTE_EXPECT_EQUAL(target.max, reference.max, framework::LogLevel::ERRORS); |
| 654 | |
| 655 | ARM_COMPUTE_EXPECT_EQUAL(target.min_loc.size(), reference.min_loc.size(), framework::LogLevel::ERRORS); |
| 656 | ARM_COMPUTE_EXPECT_EQUAL(target.max_loc.size(), reference.max_loc.size(), framework::LogLevel::ERRORS); |
| 657 | |
| 658 | for(uint32_t i = 0; i < target.min_loc.size(); ++i) |
| 659 | { |
| 660 | const auto same_coords = std::find_if(reference.min_loc.begin(), reference.min_loc.end(), [&target, i](Coordinates2D coord) |
| 661 | { |
| 662 | return coord.x == target.min_loc.at(i).x && coord.y == target.min_loc.at(i).y; |
| 663 | }); |
| 664 | |
| 665 | ARM_COMPUTE_EXPECT(same_coords != reference.min_loc.end(), framework::LogLevel::ERRORS); |
| 666 | } |
| 667 | |
| 668 | for(uint32_t i = 0; i < target.max_loc.size(); ++i) |
| 669 | { |
| 670 | const auto same_coords = std::find_if(reference.max_loc.begin(), reference.max_loc.end(), [&target, i](Coordinates2D coord) |
| 671 | { |
| 672 | return coord.x == target.max_loc.at(i).x && coord.y == target.max_loc.at(i).y; |
| 673 | }); |
| 674 | |
| 675 | ARM_COMPUTE_EXPECT(same_coords != reference.max_loc.end(), framework::LogLevel::ERRORS); |
| 676 | } |
| 677 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 678 | } // namespace validation |
| 679 | } // namespace test |
| 680 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 681 | #endif /* ARM_COMPUTE_TEST_REFERENCE_VALIDATION_H */ |