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 | #ifndef __ARM_COMPUTE_TEST_REFERENCE_VALIDATION_H__ |
| 25 | #define __ARM_COMPUTE_TEST_REFERENCE_VALIDATION_H__ |
| 26 | |
| 27 | #include "arm_compute/core/Types.h" |
Giorgio Arena | 2ca209e | 2017-06-13 15:49:37 +0100 | [diff] [blame] | 28 | #include "arm_compute/runtime/Array.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 29 | |
| 30 | #include "boost_wrapper.h" |
| 31 | |
| 32 | #include <vector> |
| 33 | |
| 34 | namespace arm_compute |
| 35 | { |
| 36 | class Tensor; |
| 37 | |
| 38 | namespace test |
| 39 | { |
| 40 | class RawTensor; |
| 41 | class IAccessor; |
| 42 | |
| 43 | namespace validation |
| 44 | { |
| 45 | template <typename T> |
| 46 | boost::test_tools::predicate_result compare_dimensions(const Dimensions<T> &dimensions1, const Dimensions<T> &dimensions2) |
| 47 | { |
| 48 | if(dimensions1.num_dimensions() != dimensions2.num_dimensions()) |
| 49 | { |
| 50 | boost::test_tools::predicate_result result(false); |
| 51 | result.message() << "Different dimensionality [" << dimensions1.num_dimensions() << "!=" << dimensions2.num_dimensions() << "]"; |
| 52 | return result; |
| 53 | } |
| 54 | |
| 55 | for(unsigned int i = 0; i < dimensions1.num_dimensions(); ++i) |
| 56 | { |
| 57 | if(dimensions1[i] != dimensions2[i]) |
| 58 | { |
| 59 | boost::test_tools::predicate_result result(false); |
| 60 | result.message() << "Mismatch in dimension " << i << " [" << dimensions1[i] << "!=" << dimensions2[i] << "]"; |
| 61 | return result; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | return true; |
| 66 | } |
| 67 | |
| 68 | /** Validate valid regions. |
| 69 | * |
| 70 | * - Dimensionality has to be the same. |
| 71 | * - Anchors have to match. |
| 72 | * - Shapes have to match. |
| 73 | */ |
| 74 | void validate(const arm_compute::ValidRegion ®ion, const arm_compute::ValidRegion &reference); |
| 75 | |
| 76 | /** Validate padding. |
| 77 | * |
| 78 | * Padding on all sides has to be the same. |
| 79 | */ |
| 80 | void validate(const arm_compute::PaddingSize &padding, const arm_compute::PaddingSize &reference); |
| 81 | |
| 82 | /** Validate tensors. |
| 83 | * |
| 84 | * - Dimensionality has to be the same. |
| 85 | * - All values have to match. |
| 86 | * |
| 87 | * @note: wrap_range allows cases where reference tensor rounds up to the wrapping point, causing it to wrap around to |
| 88 | * zero while the test tensor stays at wrapping point to pass. This may permit true erroneous cases (difference between |
| 89 | * reference tensor and test tensor is multiple of wrap_range), but such errors would be detected by |
| 90 | * other test cases. |
| 91 | */ |
| 92 | void validate(const IAccessor &tensor, const RawTensor &reference, float tolerance_value = 0.f, float tolerance_number = 0.f, uint64_t wrap_range = 0); |
| 93 | |
| 94 | /** Validate tensors with valid region. |
| 95 | * |
| 96 | * - Dimensionality has to be the same. |
| 97 | * - All values have to match. |
| 98 | * |
| 99 | * @note: wrap_range allows cases where reference tensor rounds up to the wrapping point, causing it to wrap around to |
| 100 | * zero while the test tensor stays at wrapping point to pass. This may permit true erroneous cases (difference between |
| 101 | * reference tensor and test tensor is multiple of wrap_range), but such errors would be detected by |
| 102 | * other test cases. |
| 103 | */ |
| 104 | void validate(const IAccessor &tensor, const RawTensor &reference, const ValidRegion &valid_region, float tolerance_value = 0.f, float tolerance_number = 0.f, uint64_t wrap_range = 0); |
| 105 | |
| 106 | /** Validate tensors against constant value. |
| 107 | * |
| 108 | * - All values have to match. |
| 109 | */ |
| 110 | void validate(const IAccessor &tensor, const void *reference_value); |
| 111 | |
| 112 | /** Validate border against a constant value. |
| 113 | * |
| 114 | * - All border values have to match the specified value if mode is CONSTANT. |
| 115 | * - All border values have to be replicated if mode is REPLICATE. |
| 116 | * - Nothing is validated for mode UNDEFINED. |
| 117 | */ |
| 118 | void validate(const IAccessor &tensor, BorderSize border_size, const BorderMode &border_mode, const void *border_value); |
| 119 | |
| 120 | /** Validate classified labels against expected ones. |
| 121 | * |
| 122 | * - All values should match |
| 123 | */ |
| 124 | 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] | 125 | |
| 126 | /** Validate float value. |
| 127 | * |
| 128 | * - All values should match |
| 129 | */ |
| 130 | void validate(float target, float ref, float tolerance_abs_error = std::numeric_limits<float>::epsilon(), float tolerance_relative_error = 0.0001f); |
| 131 | |
Giorgio Arena | 2ca209e | 2017-06-13 15:49:37 +0100 | [diff] [blame] | 132 | /** Validate min max location. |
| 133 | * |
| 134 | * - All values should match |
| 135 | */ |
| 136 | void validate_min_max_loc(int32_t min, int32_t ref_min, int32_t max, int32_t ref_max, |
Giorgio Arena | 935deee | 2017-06-14 13:40:36 +0100 | [diff] [blame] | 137 | IArray<Coordinates2D> &min_loc, IArray<Coordinates2D> &ref_min_loc, IArray<Coordinates2D> &max_loc, IArray<Coordinates2D> &ref_max_loc, |
Giorgio Arena | 2ca209e | 2017-06-13 15:49:37 +0100 | [diff] [blame] | 138 | uint32_t min_count, uint32_t ref_min_count, uint32_t max_count, uint32_t ref_max_count); |
| 139 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 140 | } // namespace validation |
| 141 | } // namespace test |
| 142 | } // namespace arm_compute |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 143 | #endif /* __ARM_COMPUTE_TEST_REFERENCE_VALIDATION_H__ */ |