Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 ARM Limited. |
| 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 | */ |
| 24 | #include "Validation.h" |
| 25 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 26 | #include "arm_compute/core/Coordinates.h" |
| 27 | #include "arm_compute/core/Error.h" |
| 28 | #include "arm_compute/core/FixedPoint.h" |
Giorgio Arena | fc2817d | 2017-06-27 17:26:37 +0100 | [diff] [blame] | 29 | #include "arm_compute/core/IArray.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 30 | #include "arm_compute/core/TensorShape.h" |
| 31 | #include "arm_compute/runtime/Tensor.h" |
Moritz Pflanzer | e49e266 | 2017-07-21 15:55:28 +0100 | [diff] [blame] | 32 | #include "tests/IAccessor.h" |
| 33 | #include "tests/RawTensor.h" |
| 34 | #include "tests/TypePrinter.h" |
| 35 | #include "tests/Utils.h" |
| 36 | #include "tests/validation/half.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 37 | |
| 38 | #include <array> |
| 39 | #include <cmath> |
| 40 | #include <cstddef> |
| 41 | #include <cstdint> |
| 42 | #include <iomanip> |
Giorgio Arena | fc2817d | 2017-06-27 17:26:37 +0100 | [diff] [blame] | 43 | #include <vector> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 44 | |
| 45 | namespace arm_compute |
| 46 | { |
| 47 | namespace test |
| 48 | { |
| 49 | namespace validation |
| 50 | { |
| 51 | namespace |
| 52 | { |
| 53 | /** Get the data from *ptr after casting according to @p data_type and then convert the data to double. |
| 54 | * |
| 55 | * @param[in] ptr Pointer to value. |
| 56 | * @param[in] data_type Data type of both values. |
| 57 | * |
| 58 | * @return The data from the ptr after converted to double. |
| 59 | */ |
| 60 | double get_double_data(const void *ptr, DataType data_type) |
| 61 | { |
steniu01 | 9746fd8 | 2017-06-15 10:49:37 +0100 | [diff] [blame] | 62 | if(ptr == nullptr) |
| 63 | { |
| 64 | ARM_COMPUTE_ERROR("Can't dereference a null pointer!"); |
| 65 | } |
| 66 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 67 | switch(data_type) |
| 68 | { |
| 69 | case DataType::U8: |
| 70 | return *reinterpret_cast<const uint8_t *>(ptr); |
| 71 | case DataType::S8: |
| 72 | return *reinterpret_cast<const int8_t *>(ptr); |
| 73 | case DataType::QS8: |
| 74 | return *reinterpret_cast<const qint8_t *>(ptr); |
| 75 | case DataType::U16: |
| 76 | return *reinterpret_cast<const uint16_t *>(ptr); |
| 77 | case DataType::S16: |
| 78 | return *reinterpret_cast<const int16_t *>(ptr); |
Michalis Spyrou | 0a8334c | 2017-06-14 18:00:05 +0100 | [diff] [blame] | 79 | case DataType::QS16: |
| 80 | return *reinterpret_cast<const qint16_t *>(ptr); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 81 | case DataType::U32: |
| 82 | return *reinterpret_cast<const uint32_t *>(ptr); |
| 83 | case DataType::S32: |
| 84 | return *reinterpret_cast<const int32_t *>(ptr); |
| 85 | case DataType::U64: |
| 86 | return *reinterpret_cast<const uint64_t *>(ptr); |
| 87 | case DataType::S64: |
| 88 | return *reinterpret_cast<const int64_t *>(ptr); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 89 | case DataType::F16: |
Moritz Pflanzer | e49e266 | 2017-07-21 15:55:28 +0100 | [diff] [blame] | 90 | return *reinterpret_cast<const half_float::half *>(ptr); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 91 | case DataType::F32: |
| 92 | return *reinterpret_cast<const float *>(ptr); |
| 93 | case DataType::F64: |
| 94 | return *reinterpret_cast<const double *>(ptr); |
| 95 | case DataType::SIZET: |
| 96 | return *reinterpret_cast<const size_t *>(ptr); |
| 97 | default: |
| 98 | ARM_COMPUTE_ERROR("NOT SUPPORTED!"); |
| 99 | } |
| 100 | } |
| 101 | |
steniu01 | 9746fd8 | 2017-06-15 10:49:37 +0100 | [diff] [blame] | 102 | bool is_equal(double target, double ref, double max_absolute_error = std::numeric_limits<double>::epsilon(), double max_relative_error = 0.0001f) |
| 103 | { |
| 104 | if(!std::isfinite(target) || !std::isfinite(ref)) |
| 105 | { |
| 106 | return false; |
| 107 | } |
| 108 | |
| 109 | // No need further check if they are equal |
| 110 | if(ref == target) |
| 111 | { |
| 112 | return true; |
| 113 | } |
| 114 | |
| 115 | // Need this check for the situation when the two values close to zero but have different sign |
| 116 | if(std::abs(std::abs(ref) - std::abs(target)) <= max_absolute_error) |
| 117 | { |
| 118 | return true; |
| 119 | } |
| 120 | |
| 121 | double relative_error = 0; |
| 122 | |
| 123 | if(std::abs(target) > std::abs(ref)) |
| 124 | { |
| 125 | relative_error = std::abs((target - ref) / target); |
| 126 | } |
| 127 | else |
| 128 | { |
| 129 | relative_error = std::abs((ref - target) / ref); |
| 130 | } |
| 131 | |
| 132 | return relative_error <= max_relative_error; |
| 133 | } |
| 134 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 135 | void check_border_element(const IAccessor &tensor, const Coordinates &id, |
| 136 | const BorderMode &border_mode, const void *border_value, |
| 137 | int64_t &num_elements, int64_t &num_mismatches) |
| 138 | { |
| 139 | const size_t channel_size = element_size_from_data_type(tensor.data_type()); |
| 140 | const auto ptr = static_cast<const uint8_t *>(tensor(id)); |
| 141 | |
| 142 | if(border_mode == BorderMode::REPLICATE) |
| 143 | { |
| 144 | Coordinates border_id{ id }; |
| 145 | border_id.set(1, 0); |
| 146 | border_value = tensor(border_id); |
| 147 | } |
| 148 | |
| 149 | // Iterate over all channels within one element |
| 150 | for(int channel = 0; channel < tensor.num_channels(); ++channel) |
| 151 | { |
| 152 | const size_t channel_offset = channel * channel_size; |
| 153 | const double target = get_double_data(ptr + channel_offset, tensor.data_type()); |
| 154 | const double ref = get_double_data(static_cast<const uint8_t *>(border_value) + channel_offset, tensor.data_type()); |
steniu01 | 9746fd8 | 2017-06-15 10:49:37 +0100 | [diff] [blame] | 155 | const bool equal = is_equal(target, ref); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 156 | |
| 157 | BOOST_TEST_INFO("id = " << id); |
| 158 | BOOST_TEST_INFO("channel = " << channel); |
| 159 | BOOST_TEST_INFO("reference = " << std::setprecision(5) << ref); |
| 160 | BOOST_TEST_INFO("target = " << std::setprecision(5) << target); |
steniu01 | 9746fd8 | 2017-06-15 10:49:37 +0100 | [diff] [blame] | 161 | BOOST_TEST_WARN(equal); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 162 | |
steniu01 | 9746fd8 | 2017-06-15 10:49:37 +0100 | [diff] [blame] | 163 | if(!equal) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 164 | { |
| 165 | ++num_mismatches; |
| 166 | } |
| 167 | |
| 168 | ++num_elements; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | void check_single_element(const Coordinates &id, const IAccessor &tensor, const RawTensor &reference, float tolerance_value, |
| 173 | uint64_t wrap_range, int min_channels, size_t channel_size, int64_t &num_mismatches, int64_t &num_elements) |
| 174 | { |
| 175 | const auto ptr = static_cast<const uint8_t *>(tensor(id)); |
| 176 | const auto ref_ptr = static_cast<const uint8_t *>(reference(id)); |
| 177 | |
| 178 | // Iterate over all channels within one element |
| 179 | for(int channel = 0; channel < min_channels; ++channel) |
| 180 | { |
| 181 | const size_t channel_offset = channel * channel_size; |
| 182 | const double target = get_double_data(ptr + channel_offset, reference.data_type()); |
| 183 | const double ref = get_double_data(ref_ptr + channel_offset, reference.data_type()); |
steniu01 | 9746fd8 | 2017-06-15 10:49:37 +0100 | [diff] [blame] | 184 | bool equal = is_equal(target, ref, tolerance_value); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 185 | |
steniu01 | 9746fd8 | 2017-06-15 10:49:37 +0100 | [diff] [blame] | 186 | if(wrap_range != 0 && !equal) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 187 | { |
steniu01 | 9746fd8 | 2017-06-15 10:49:37 +0100 | [diff] [blame] | 188 | equal = is_equal(target, ref, wrap_range - tolerance_value); |
| 189 | } |
| 190 | |
| 191 | if(!equal) |
| 192 | { |
| 193 | BOOST_TEST_INFO("id = " << id); |
| 194 | BOOST_TEST_INFO("channel = " << channel); |
| 195 | BOOST_TEST_INFO("reference = " << std::setprecision(5) << ref); |
| 196 | BOOST_TEST_INFO("target = " << std::setprecision(5) << target); |
| 197 | BOOST_TEST_WARN(equal); |
steniu01 | 9746fd8 | 2017-06-15 10:49:37 +0100 | [diff] [blame] | 198 | ++num_mismatches; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 199 | } |
| 200 | ++num_elements; |
| 201 | } |
| 202 | } |
| 203 | } // namespace |
| 204 | |
| 205 | void validate(const arm_compute::ValidRegion ®ion, const arm_compute::ValidRegion &reference) |
| 206 | { |
| 207 | BOOST_TEST(region.anchor.num_dimensions() == reference.anchor.num_dimensions()); |
| 208 | BOOST_TEST(region.shape.num_dimensions() == reference.shape.num_dimensions()); |
| 209 | |
| 210 | for(unsigned int d = 0; d < region.anchor.num_dimensions(); ++d) |
| 211 | { |
| 212 | BOOST_TEST(region.anchor[d] == reference.anchor[d]); |
| 213 | } |
| 214 | |
| 215 | for(unsigned int d = 0; d < region.shape.num_dimensions(); ++d) |
| 216 | { |
| 217 | BOOST_TEST(region.shape[d] == reference.shape[d]); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | void validate(const arm_compute::PaddingSize &padding, const arm_compute::PaddingSize &reference) |
| 222 | { |
| 223 | BOOST_TEST(padding.top == reference.top); |
| 224 | BOOST_TEST(padding.right == reference.right); |
| 225 | BOOST_TEST(padding.bottom == reference.bottom); |
| 226 | BOOST_TEST(padding.left == reference.left); |
| 227 | } |
| 228 | |
| 229 | void validate(const IAccessor &tensor, const RawTensor &reference, float tolerance_value, float tolerance_number, uint64_t wrap_range) |
| 230 | { |
| 231 | // Validate with valid region covering the entire shape |
| 232 | validate(tensor, reference, shape_to_valid_region(tensor.shape()), tolerance_value, tolerance_number, wrap_range); |
| 233 | } |
| 234 | |
| 235 | void validate(const IAccessor &tensor, const RawTensor &reference, const ValidRegion &valid_region, float tolerance_value, float tolerance_number, uint64_t wrap_range) |
| 236 | { |
| 237 | int64_t num_mismatches = 0; |
| 238 | int64_t num_elements = 0; |
| 239 | |
| 240 | BOOST_TEST(tensor.element_size() == reference.element_size()); |
| 241 | BOOST_TEST(tensor.format() == reference.format()); |
| 242 | BOOST_TEST(tensor.data_type() == reference.data_type()); |
| 243 | BOOST_TEST(tensor.num_channels() == reference.num_channels()); |
| 244 | BOOST_TEST(compare_dimensions(tensor.shape(), reference.shape())); |
| 245 | |
| 246 | const int min_elements = std::min(tensor.num_elements(), reference.num_elements()); |
| 247 | const int min_channels = std::min(tensor.num_channels(), reference.num_channels()); |
| 248 | const size_t channel_size = element_size_from_data_type(reference.data_type()); |
| 249 | |
| 250 | // Iterate over all elements within valid region, e.g. U8, S16, RGB888, ... |
| 251 | for(int element_idx = 0; element_idx < min_elements; ++element_idx) |
| 252 | { |
| 253 | const Coordinates id = index2coord(reference.shape(), element_idx); |
| 254 | if(is_in_valid_region(valid_region, id)) |
| 255 | { |
| 256 | check_single_element(id, tensor, reference, tolerance_value, wrap_range, min_channels, channel_size, num_mismatches, num_elements); |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | const int64_t absolute_tolerance_number = tolerance_number * num_elements; |
| 261 | const float percent_mismatches = static_cast<float>(num_mismatches) / num_elements * 100.f; |
| 262 | |
| 263 | BOOST_TEST(num_mismatches <= absolute_tolerance_number, |
| 264 | num_mismatches << " values (" << std::setprecision(2) << percent_mismatches |
| 265 | << "%) mismatched (maximum tolerated " << std::setprecision(2) << tolerance_number << "%)"); |
| 266 | } |
| 267 | |
Isabella Gottardi | 6203153 | 2017-07-04 11:21:28 +0100 | [diff] [blame] | 268 | void validate(const IAccessor &tensor, const RawTensor &reference, const RawTensor &valid_mask, float tolerance_value, float tolerance_number, uint64_t wrap_range) |
| 269 | { |
| 270 | int64_t num_mismatches = 0; |
| 271 | int64_t num_elements = 0; |
| 272 | |
| 273 | BOOST_TEST(tensor.element_size() == reference.element_size()); |
| 274 | BOOST_TEST(tensor.format() == reference.format()); |
| 275 | BOOST_TEST(tensor.data_type() == reference.data_type()); |
| 276 | BOOST_TEST(tensor.num_channels() == reference.num_channels()); |
| 277 | BOOST_TEST(compare_dimensions(tensor.shape(), reference.shape())); |
| 278 | |
| 279 | const int min_elements = std::min(tensor.num_elements(), reference.num_elements()); |
| 280 | const int min_channels = std::min(tensor.num_channels(), reference.num_channels()); |
| 281 | const size_t channel_size = element_size_from_data_type(reference.data_type()); |
| 282 | |
| 283 | // Iterate over all elements within valid region, e.g. U8, S16, RGB888, ... |
| 284 | for(int element_idx = 0; element_idx < min_elements; ++element_idx) |
| 285 | { |
| 286 | const Coordinates id = index2coord(reference.shape(), element_idx); |
| 287 | if(valid_mask[element_idx] == 1) |
| 288 | { |
| 289 | check_single_element(id, tensor, reference, tolerance_value, wrap_range, min_channels, channel_size, num_mismatches, num_elements); |
| 290 | } |
Isabella Gottardi | ffc1255 | 2017-08-17 10:49:25 +0100 | [diff] [blame^] | 291 | else |
| 292 | { |
| 293 | ++num_elements; |
| 294 | } |
Isabella Gottardi | 6203153 | 2017-07-04 11:21:28 +0100 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | const int64_t absolute_tolerance_number = tolerance_number * num_elements; |
| 298 | const float percent_mismatches = static_cast<float>(num_mismatches) / num_elements * 100.f; |
| 299 | |
| 300 | BOOST_TEST(num_mismatches <= absolute_tolerance_number, |
| 301 | num_mismatches << " values (" << std::setprecision(2) << percent_mismatches |
| 302 | << "%) mismatched (maximum tolerated " << std::setprecision(2) << tolerance_number << "%)"); |
| 303 | } |
| 304 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 305 | void validate(const IAccessor &tensor, const void *reference_value) |
| 306 | { |
| 307 | BOOST_TEST_REQUIRE((reference_value != nullptr)); |
| 308 | |
| 309 | int64_t num_mismatches = 0; |
| 310 | int64_t num_elements = 0; |
| 311 | const size_t channel_size = element_size_from_data_type(tensor.data_type()); |
| 312 | |
| 313 | // Iterate over all elements, e.g. U8, S16, RGB888, ... |
| 314 | for(int element_idx = 0; element_idx < tensor.num_elements(); ++element_idx) |
| 315 | { |
| 316 | const Coordinates id = index2coord(tensor.shape(), element_idx); |
| 317 | |
| 318 | const auto ptr = static_cast<const uint8_t *>(tensor(id)); |
| 319 | |
| 320 | // Iterate over all channels within one element |
| 321 | for(int channel = 0; channel < tensor.num_channels(); ++channel) |
| 322 | { |
| 323 | const size_t channel_offset = channel * channel_size; |
| 324 | const double target = get_double_data(ptr + channel_offset, tensor.data_type()); |
| 325 | const double ref = get_double_data(reference_value, tensor.data_type()); |
steniu01 | 9746fd8 | 2017-06-15 10:49:37 +0100 | [diff] [blame] | 326 | const bool equal = is_equal(target, ref); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 327 | |
| 328 | BOOST_TEST_INFO("id = " << id); |
| 329 | BOOST_TEST_INFO("channel = " << channel); |
| 330 | BOOST_TEST_INFO("reference = " << std::setprecision(5) << ref); |
| 331 | BOOST_TEST_INFO("target = " << std::setprecision(5) << target); |
steniu01 | 9746fd8 | 2017-06-15 10:49:37 +0100 | [diff] [blame] | 332 | BOOST_TEST_WARN(equal); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 333 | |
steniu01 | 9746fd8 | 2017-06-15 10:49:37 +0100 | [diff] [blame] | 334 | if(!equal) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 335 | { |
| 336 | ++num_mismatches; |
| 337 | } |
| 338 | |
| 339 | ++num_elements; |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | const float percent_mismatches = static_cast<float>(num_mismatches) / num_elements * 100.f; |
| 344 | |
| 345 | BOOST_TEST(num_mismatches == 0, |
| 346 | num_mismatches << " values (" << std::setprecision(2) << percent_mismatches << "%) mismatched"); |
| 347 | } |
| 348 | |
| 349 | void validate(const IAccessor &tensor, BorderSize border_size, const BorderMode &border_mode, const void *border_value) |
| 350 | { |
| 351 | if(border_mode == BorderMode::UNDEFINED) |
| 352 | { |
| 353 | return; |
| 354 | } |
| 355 | else if(border_mode == BorderMode::CONSTANT) |
| 356 | { |
| 357 | BOOST_TEST((border_value != nullptr)); |
| 358 | } |
| 359 | |
| 360 | int64_t num_mismatches = 0; |
| 361 | int64_t num_elements = 0; |
| 362 | const int slice_size = tensor.shape()[0] * tensor.shape()[1]; |
| 363 | |
| 364 | for(int element_idx = 0; element_idx < tensor.num_elements(); element_idx += slice_size) |
| 365 | { |
| 366 | Coordinates id = index2coord(tensor.shape(), element_idx); |
| 367 | |
| 368 | // Top border |
| 369 | for(int y = -border_size.top; y < 0; ++y) |
| 370 | { |
| 371 | id.set(1, y); |
| 372 | |
| 373 | for(int x = -border_size.left; x < static_cast<int>(tensor.shape()[0]) + static_cast<int>(border_size.right); ++x) |
| 374 | { |
| 375 | id.set(0, x); |
| 376 | |
| 377 | check_border_element(tensor, id, border_mode, border_value, num_elements, num_mismatches); |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | // Bottom border |
| 382 | for(int y = tensor.shape()[1]; y < static_cast<int>(tensor.shape()[1]) + static_cast<int>(border_size.bottom); ++y) |
| 383 | { |
| 384 | id.set(1, y); |
| 385 | |
| 386 | for(int x = -border_size.left; x < static_cast<int>(tensor.shape()[0]) + static_cast<int>(border_size.right); ++x) |
| 387 | { |
| 388 | id.set(0, x); |
| 389 | |
| 390 | check_border_element(tensor, id, border_mode, border_value, num_elements, num_mismatches); |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | // Left/right border |
| 395 | for(int y = 0; y < static_cast<int>(tensor.shape()[1]); ++y) |
| 396 | { |
| 397 | id.set(1, y); |
| 398 | |
| 399 | // Left border |
| 400 | for(int x = -border_size.left; x < 0; ++x) |
| 401 | { |
| 402 | id.set(0, x); |
| 403 | |
| 404 | check_border_element(tensor, id, border_mode, border_value, num_elements, num_mismatches); |
| 405 | } |
| 406 | |
| 407 | // Right border |
| 408 | for(int x = tensor.shape()[0]; x < static_cast<int>(tensor.shape()[0]) + static_cast<int>(border_size.right); ++x) |
| 409 | { |
| 410 | id.set(0, x); |
| 411 | |
| 412 | check_border_element(tensor, id, border_mode, border_value, num_elements, num_mismatches); |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | const float percent_mismatches = static_cast<float>(num_mismatches) / num_elements * 100.f; |
| 418 | |
| 419 | BOOST_TEST(num_mismatches == 0, |
| 420 | num_mismatches << " values (" << std::setprecision(2) << percent_mismatches << "%) mismatched"); |
| 421 | } |
| 422 | |
| 423 | void validate(std::vector<unsigned int> classified_labels, std::vector<unsigned int> expected_labels) |
| 424 | { |
Pablo Tello | 383deec | 2017-06-23 10:40:05 +0100 | [diff] [blame] | 425 | ARM_COMPUTE_UNUSED(classified_labels); |
| 426 | ARM_COMPUTE_UNUSED(expected_labels); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 427 | BOOST_TEST(expected_labels.size() != 0); |
| 428 | BOOST_TEST(classified_labels.size() == expected_labels.size()); |
| 429 | |
| 430 | for(unsigned int i = 0; i < expected_labels.size(); ++i) |
| 431 | { |
| 432 | BOOST_TEST(classified_labels[i] == expected_labels[i]); |
| 433 | } |
| 434 | } |
steniu01 | 423d88f | 2017-06-22 10:20:37 +0100 | [diff] [blame] | 435 | |
steniu01 | 960b084 | 2017-06-23 11:44:34 +0100 | [diff] [blame] | 436 | void validate(float target, float ref, float tolerance_abs_error, float tolerance_relative_error) |
steniu01 | 423d88f | 2017-06-22 10:20:37 +0100 | [diff] [blame] | 437 | { |
| 438 | const bool equal = is_equal(target, ref, tolerance_abs_error, tolerance_relative_error); |
| 439 | |
| 440 | BOOST_TEST_INFO("reference = " << std::setprecision(5) << ref); |
| 441 | BOOST_TEST_INFO("target = " << std::setprecision(5) << target); |
| 442 | BOOST_TEST(equal); |
| 443 | } |
Giorgio Arena | fc2817d | 2017-06-27 17:26:37 +0100 | [diff] [blame] | 444 | |
| 445 | void validate(IArray<KeyPoint> &target, IArray<KeyPoint> &ref) |
| 446 | { |
| 447 | BOOST_TEST(target.num_values() == ref.num_values()); |
| 448 | |
| 449 | for(size_t i = 0; i < target.num_values(); ++i) |
| 450 | { |
| 451 | KeyPoint *ref_val = std::find_if(ref.buffer(), ref.buffer() + ref.num_values(), [&target, i](KeyPoint key) |
| 452 | { |
| 453 | return key.x == target.at(i).x && key.y == target.at(i).y; |
| 454 | }); |
| 455 | |
| 456 | BOOST_TEST(ref_val != ref.buffer() + ref.num_values()); |
| 457 | BOOST_TEST(target.at(i).tracking_status == ref_val->tracking_status); |
| 458 | |
| 459 | validate(target.at(i).strength, ref_val->strength); |
| 460 | validate(target.at(i).scale, ref_val->scale); |
| 461 | validate(target.at(i).orientation, ref_val->orientation); |
| 462 | validate(target.at(i).error, ref_val->error); |
| 463 | } |
| 464 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 465 | } // namespace validation |
| 466 | } // namespace test |
| 467 | } // namespace arm_compute |