blob: f0630c1d3ed68782735e5a5754e0cade999dec2e [file] [log] [blame]
Moritz Pflanzera09de0c2017-09-01 20:41:12 +01001/*
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"
28#include "arm_compute/runtime/Array.h"
29#include "tests/RawTensor.h"
30
31#include "tests/validation_old/boost_wrapper.h"
32
33#include <vector>
34
35namespace arm_compute
36{
37class Tensor;
38
39namespace test
40{
41class IAccessor;
42
43namespace validation
44{
45template <typename T>
46boost::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 */
74void validate(const arm_compute::ValidRegion &region, const arm_compute::ValidRegion &reference);
75
76/** Validate padding.
77 *
78 * Padding on all sides has to be the same.
79 */
80void 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 */
92void 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 */
104void 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 with valid mask.
107 *
108 * - Dimensionality has to be the same.
109 * - All values have to match.
110 *
111 * @note: wrap_range allows cases where reference tensor rounds up to the wrapping point, causing it to wrap around to
112 * zero while the test tensor stays at wrapping point to pass. This may permit true erroneous cases (difference between
113 * reference tensor and test tensor is multiple of wrap_range), but such errors would be detected by
114 * other test cases.
115 */
116void validate(const IAccessor &tensor, const RawTensor &reference, const RawTensor &valid_mask, float tolerance_value = 0.f, float tolerance_number = 0.f, uint64_t wrap_range = 0);
117
118/** Validate tensors against constant value.
119 *
120 * - All values have to match.
121 */
122void validate(const IAccessor &tensor, const void *reference_value);
123
124/** Validate border against a constant value.
125 *
126 * - All border values have to match the specified value if mode is CONSTANT.
127 * - All border values have to be replicated if mode is REPLICATE.
128 * - Nothing is validated for mode UNDEFINED.
129 */
130void validate(const IAccessor &tensor, BorderSize border_size, const BorderMode &border_mode, const void *border_value);
131
132/** Validate classified labels against expected ones.
133 *
134 * - All values should match
135 */
136void validate(std::vector<unsigned int> classified_labels, std::vector<unsigned int> expected_labels);
137
138/** Validate float value.
139 *
140 * - All values should match
141 */
142void validate(float target, float ref, float tolerance_abs_error = std::numeric_limits<float>::epsilon(), float tolerance_relative_error = 0.0001f);
143
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100144/** Validate KeyPoint arrays.
145 *
146 * - All values should match
147 */
148void validate(IArray<KeyPoint> &target, IArray<KeyPoint> &ref, int64_t tolerance = 0);
149} // namespace validation
150} // namespace test
151} // namespace arm_compute
152#endif /* __ARM_COMPUTE_TEST_REFERENCE_VALIDATION_H__ */