blob: e851cdb4df41474676cb7e1eb56e485d1a06d09b [file] [log] [blame]
Sanghoon Leefc35b512017-10-18 12:09:04 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017-2018 Arm Limited.
Sanghoon Leefc35b512017-10-18 12:09:04 +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_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);
Pablo Tellofc1ffe62018-01-23 08:31:41 +000053 const T constant_border_value = static_cast<T>(distribution(gen));
Sanghoon Leefc35b512017-10-18 12:09:04 +010054
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>
Pablo Tellofc1ffe62018-01-23 08:31:41 +000061 void fill(U &&tensor, int i, float min, float max)
Sanghoon Leefc35b512017-10-18 12:09:04 +010062 {
Pablo Tellofc1ffe62018-01-23 08:31:41 +000063 std::uniform_int_distribution<> distribution((int)min, (int)max);
64 library->fill(tensor, distribution, i);
Sanghoon Leefc35b512017-10-18 12:09:04 +010065 }
66
67 TensorType compute_target(const TensorShape &shape, InterpolationPolicy policy, DataType data_type, BorderMode border_mode, T constant_border_value)
68 {
69 // Create tensors
70 TensorType src = create_tensor<TensorType>(shape, data_type);
71 TensorType map_x = create_tensor<TensorType>(shape, DataType::F32);
72 TensorType map_y = create_tensor<TensorType>(shape, DataType::F32);
73 TensorType dst = create_tensor<TensorType>(shape, data_type);
74
75 // Create and configure function
76 FunctionType remap;
77 remap.configure(&src, &map_x, &map_y, &dst, policy, border_mode, constant_border_value);
78
79 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
80 ARM_COMPUTE_EXPECT(map_x.info()->is_resizable(), framework::LogLevel::ERRORS);
81 ARM_COMPUTE_EXPECT(map_y.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 map_x.allocator()->allocate();
87 map_y.allocator()->allocate();
88 dst.allocator()->allocate();
89
90 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
91 ARM_COMPUTE_EXPECT(!map_x.info()->is_resizable(), framework::LogLevel::ERRORS);
92 ARM_COMPUTE_EXPECT(!map_y.info()->is_resizable(), framework::LogLevel::ERRORS);
93 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
94
95 // Fill tensors
Pablo Tellofc1ffe62018-01-23 08:31:41 +000096 fill(AccessorType(src), 0, 0, 255);
97 fill(AccessorType(map_x), 1, -5, shape.x() + 5);
98 fill(AccessorType(map_y), 2, -5, shape.y() + 5);
Sanghoon Leefc35b512017-10-18 12:09:04 +010099
100 // Compute function
101 remap.run();
102
103 return dst;
104 }
105
106 SimpleTensor<T> compute_reference(const TensorShape &shape, InterpolationPolicy policy, DataType data_type, BorderMode border_mode, T constant_border_value)
107 {
108 ARM_COMPUTE_ERROR_ON(data_type != DataType::U8);
109
110 // Create reference
111 SimpleTensor<T> src{ shape, data_type };
112 SimpleTensor<float> map_x{ shape, DataType::F32 };
113 SimpleTensor<float> map_y{ shape, DataType::F32 };
114
115 // Create the valid mask Tensor
116 _valid_mask = SimpleTensor<T> { shape, data_type };
117
118 // Fill reference
Pablo Tellofc1ffe62018-01-23 08:31:41 +0000119 fill(src, 0, 0, 255);
120 fill(map_x, 1, -5, shape.x() + 5);
121 fill(map_y, 2, -5, shape.y() + 5);
Sanghoon Leefc35b512017-10-18 12:09:04 +0100122
123 // Compute reference
124 return reference::remap<T>(src, map_x, map_y, _valid_mask, policy, border_mode, constant_border_value);
125 }
126
127 TensorType _target{};
128 SimpleTensor<T> _reference{};
129 SimpleTensor<T> _valid_mask{};
130};
131} // namespace validation
132} // namespace test
133} // namespace arm_compute
134#endif /* ARM_COMPUTE_TEST_REMAP_FIXTURE */