blob: 846ebf44a20b89d479b1d6df6e6ca2364614c88d [file] [log] [blame]
Sanghoon Leefc35b512017-10-18 12:09:04 +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_REMAP_FIXTURE
25#define ARM_COMPUTE_TEST_REMAP_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"
Georgios Pinitas5a7e7762017-12-01 16:27:29 +000034#include "tests/validation/reference/Remap.h"
Sanghoon Leefc35b512017-10-18 12:09:04 +010035
36#include <random>
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
45class RemapValidationFixture : public framework::Fixture
46{
47public:
48 template <typename...>
49 void setup(TensorShape shape, InterpolationPolicy policy, DataType data_type, BorderMode border_mode)
50 {
51 std::mt19937 gen(library->seed());
52 std::uniform_int_distribution<uint8_t> distribution(0, 255);
53 T constant_border_value = static_cast<T>(distribution(gen));
54
55 _target = compute_target(shape, policy, data_type, border_mode, constant_border_value);
56 _reference = compute_reference(shape, policy, data_type, border_mode, constant_border_value);
57 }
58
59protected:
60 template <typename U>
61 void fill(U &&tensor, int i)
62 {
63 library->fill_tensor_uniform(tensor, i);
64 }
65
66 TensorType compute_target(const TensorShape &shape, InterpolationPolicy policy, DataType data_type, BorderMode border_mode, T constant_border_value)
67 {
68 // Create tensors
69 TensorType src = create_tensor<TensorType>(shape, data_type);
70 TensorType map_x = create_tensor<TensorType>(shape, DataType::F32);
71 TensorType map_y = create_tensor<TensorType>(shape, DataType::F32);
72 TensorType dst = create_tensor<TensorType>(shape, data_type);
73
74 // Create and configure function
75 FunctionType remap;
76 remap.configure(&src, &map_x, &map_y, &dst, policy, border_mode, constant_border_value);
77
78 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
79 ARM_COMPUTE_EXPECT(map_x.info()->is_resizable(), framework::LogLevel::ERRORS);
80 ARM_COMPUTE_EXPECT(map_y.info()->is_resizable(), framework::LogLevel::ERRORS);
81 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
82
83 // Allocate tensors
84 src.allocator()->allocate();
85 map_x.allocator()->allocate();
86 map_y.allocator()->allocate();
87 dst.allocator()->allocate();
88
89 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
90 ARM_COMPUTE_EXPECT(!map_x.info()->is_resizable(), framework::LogLevel::ERRORS);
91 ARM_COMPUTE_EXPECT(!map_y.info()->is_resizable(), framework::LogLevel::ERRORS);
92 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
93
94 // Fill tensors
95 fill(AccessorType(src), 0);
96 fill(AccessorType(map_x), 1);
97 fill(AccessorType(map_y), 2);
98
99 // Compute function
100 remap.run();
101
102 return dst;
103 }
104
105 SimpleTensor<T> compute_reference(const TensorShape &shape, InterpolationPolicy policy, DataType data_type, BorderMode border_mode, T constant_border_value)
106 {
107 ARM_COMPUTE_ERROR_ON(data_type != DataType::U8);
108
109 // Create reference
110 SimpleTensor<T> src{ shape, data_type };
111 SimpleTensor<float> map_x{ shape, DataType::F32 };
112 SimpleTensor<float> map_y{ shape, DataType::F32 };
113
114 // Create the valid mask Tensor
115 _valid_mask = SimpleTensor<T> { shape, data_type };
116
117 // Fill reference
118 fill(src, 0);
119 fill(map_x, 1);
120 fill(map_y, 2);
121
122 // Compute reference
123 return reference::remap<T>(src, map_x, map_y, _valid_mask, policy, border_mode, constant_border_value);
124 }
125
126 TensorType _target{};
127 SimpleTensor<T> _reference{};
128 SimpleTensor<T> _valid_mask{};
129};
130} // namespace validation
131} // namespace test
132} // namespace arm_compute
133#endif /* ARM_COMPUTE_TEST_REMAP_FIXTURE */