blob: 03d2bcd962266139f20a11764c7c7e4835b455da [file] [log] [blame]
John Richardson6f4d49f2017-09-07 11:21:10 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017 Arm Limited.
John Richardson6f4d49f2017-09-07 11:21:10 +01003 *
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_NONLINEAR_FILTER_FIXTURE
25#define ARM_COMPUTE_TEST_NONLINEAR_FILTER_FIXTURE
26
27#include "arm_compute/core/TensorShape.h"
28#include "arm_compute/core/Types.h"
29#include "tests/AssetsLibrary.h"
30#include "tests/Globals.h"
31#include "tests/IAccessor.h"
32#include "tests/framework/Asserts.h"
33#include "tests/framework/Fixture.h"
John Richardson6f4d49f2017-09-07 11:21:10 +010034#include "tests/validation/Helpers.h"
Georgios Pinitas5a7e7762017-12-01 16:27:29 +000035#include "tests/validation/reference/NonLinearFilter.h"
John Richardson6f4d49f2017-09-07 11:21:10 +010036
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
43template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
44class NonLinearFilterValidationFixture : public framework::Fixture
45{
46public:
47 template <typename...>
48 void setup(TensorShape shape, NonLinearFilterFunction function, unsigned int mask_size, MatrixPattern pattern, BorderMode border_mode, DataType data_type)
49 {
50 std::mt19937 generator(library->seed());
51 std::uniform_int_distribution<uint8_t> distribution_u8(0, 255);
52 const uint8_t constant_border_value = distribution_u8(generator);
53
54 // Create the mask
55 std::vector<uint8_t> mask(mask_size * mask_size);
56 fill_mask_from_pattern(mask.data(), mask_size, mask_size, pattern);
57
58 _border_size = BorderSize(static_cast<int>(mask_size / 2));
59 _target = compute_target(shape, data_type, function, mask_size, pattern, mask.data(), border_mode, constant_border_value);
60 _reference = compute_reference(shape, data_type, function, mask_size, pattern, mask.data(), border_mode, constant_border_value);
61 }
62
63protected:
64 template <typename U>
65 void fill(U &&tensor)
66 {
67 library->fill_tensor_uniform(tensor, 0);
68 }
69
70 TensorType compute_target(const TensorShape &shape, DataType data_type, NonLinearFilterFunction function, unsigned int mask_size, MatrixPattern pattern, const uint8_t *mask, BorderMode border_mode,
71 uint8_t constant_border_value)
72 {
73 // Create tensors
74 TensorType src = create_tensor<TensorType>(shape, data_type);
75 TensorType dst = create_tensor<TensorType>(shape, data_type);
76
77 // Create and configure function
78 FunctionType non_linear_filter;
79 non_linear_filter.configure(&src, &dst, function, mask_size, pattern, mask, border_mode, constant_border_value);
80
81 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
82 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
83
84 // Allocate tensors
85 src.allocator()->allocate();
86 dst.allocator()->allocate();
87 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
88 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
89
90 // Fill tensors
91 fill(AccessorType(src));
92
93 // Compute function
94 non_linear_filter.run();
95
96 return dst;
97 }
98
99 SimpleTensor<T> compute_reference(const TensorShape &shape, DataType data_type, NonLinearFilterFunction function, unsigned int mask_size, MatrixPattern pattern, const uint8_t *mask,
100 BorderMode border_mode, uint8_t constant_border_value)
101 {
102 // Create reference
103 SimpleTensor<T> src{ shape, data_type };
104
105 // Fill reference
106 fill(src);
107
108 return reference::non_linear_filter<T>(src, function, mask_size, pattern, mask, border_mode, constant_border_value);
109 }
110
111 BorderMode _border_mode{};
112 BorderSize _border_size{};
113 TensorType _target{};
114 SimpleTensor<T> _reference{};
115};
116} // namespace validation
117} // namespace test
118} // namespace arm_compute
119#endif /* ARM_COMPUTE_TEST_NONLINEAR_FILTER_FIXTURE */