blob: 66bb2be2cac96adc068677fec1ac02196a4cbf74 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +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"
Giorgio Arena2ca209e2017-06-13 15:49:37 +010028#include "arm_compute/runtime/Array.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010029
30#include "boost_wrapper.h"
31
32#include <vector>
33
34namespace arm_compute
35{
36class Tensor;
37
38namespace test
39{
40class RawTensor;
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 against constant value.
107 *
108 * - All values have to match.
109 */
110void 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 */
118void 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 */
124void validate(std::vector<unsigned int> classified_labels, std::vector<unsigned int> expected_labels);
steniu01960b0842017-06-23 11:44:34 +0100125
126/** Validate float value.
127 *
128 * - All values should match
129 */
130void validate(float target, float ref, float tolerance_abs_error = std::numeric_limits<float>::epsilon(), float tolerance_relative_error = 0.0001f);
131
Giorgio Arena2ca209e2017-06-13 15:49:37 +0100132/** Validate min max location.
133 *
134 * - All values should match
135 */
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100136template <typename T>
137void validate_min_max_loc(T min, T ref_min, T max, T ref_max,
Giorgio Arena935deee2017-06-14 13:40:36 +0100138 IArray<Coordinates2D> &min_loc, IArray<Coordinates2D> &ref_min_loc, IArray<Coordinates2D> &max_loc, IArray<Coordinates2D> &ref_max_loc,
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100139 uint32_t min_count, uint32_t ref_min_count, uint32_t max_count, uint32_t ref_max_count)
140{
141 BOOST_TEST(min == ref_min);
142 BOOST_TEST(max == ref_max);
Giorgio Arena2ca209e2017-06-13 15:49:37 +0100143
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100144 BOOST_TEST(min_count == min_loc.num_values());
145 BOOST_TEST(max_count == max_loc.num_values());
146 BOOST_TEST(ref_min_count == ref_min_loc.num_values());
147 BOOST_TEST(ref_max_count == ref_max_loc.num_values());
148
149 BOOST_TEST(min_count == ref_min_count);
150 BOOST_TEST(max_count == ref_max_count);
151
152 for(uint32_t i = 0; i < min_count; i++)
153 {
154 Coordinates2D *same_coords = std::find_if(ref_min_loc.buffer(), ref_min_loc.buffer() + min_count, [&min_loc, i](Coordinates2D coord)
155 {
156 return coord.x == min_loc.at(i).x && coord.y == min_loc.at(i).y;
157 });
158
159 BOOST_TEST(same_coords != ref_min_loc.buffer() + min_count);
160 }
161
162 for(uint32_t i = 0; i < max_count; i++)
163 {
164 Coordinates2D *same_coords = std::find_if(ref_max_loc.buffer(), ref_max_loc.buffer() + max_count, [&max_loc, i](Coordinates2D coord)
165 {
166 return coord.x == max_loc.at(i).x && coord.y == max_loc.at(i).y;
167 });
168
169 BOOST_TEST(same_coords != ref_max_loc.buffer() + max_count);
170 }
171}
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100172} // namespace validation
173} // namespace test
174} // namespace arm_compute
Anthony Barbierac69aa12017-07-03 17:39:37 +0100175#endif /* __ARM_COMPUTE_TEST_REFERENCE_VALIDATION_H__ */