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