blob: fef1f6b6262686d69d8f52239b0cbc5cf4dbce35 [file] [log] [blame]
Isabella Gottardi83be7452017-08-29 13:47:03 +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_WARP_AFFINE_FIXTURE
25#define ARM_COMPUTE_TEST_WARP_AFFINE_FIXTURE
26
27#include <memory>
28
29#include "arm_compute/core/TensorShape.h"
30#include "arm_compute/core/Types.h"
31#include "tests/AssetsLibrary.h"
32#include "tests/Globals.h"
33#include "tests/IAccessor.h"
34#include "tests/framework/Asserts.h"
35#include "tests/framework/Fixture.h"
36#include "tests/validation/CPP/Utils.h"
37#include "tests/validation/CPP/WarpAffine.h"
38
39namespace arm_compute
40{
41namespace test
42{
43namespace validation
44{
45template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
46class WarpAffineValidationFixture : public framework::Fixture
47{
48public:
49 template <typename...>
50 void setup(TensorShape shape, DataType data_type, InterpolationPolicy policy, BorderMode border_mode)
51 {
52 // Generate a random constant value if border_mode is constant
53 std::mt19937 gen(library->seed());
54 std::uniform_int_distribution<uint8_t> distribution_u8(0, 255);
55 uint8_t constant_border_value = distribution_u8(gen);
56
57 // Create the matrix
58 std::array<float, 6> matrix{ {} };
Pablo Tellod616cb92017-09-27 10:07:45 +010059 fill_warp_matrix<6>(matrix);
Isabella Gottardi83be7452017-08-29 13:47:03 +010060
61 _target = compute_target(shape, data_type, matrix.data(), policy, border_mode, constant_border_value);
62 _reference = compute_reference(shape, data_type, matrix.data(), policy, border_mode, constant_border_value);
63 }
64
65protected:
66 template <typename U>
67 void fill(U &&tensor)
68 {
69 library->fill_tensor_uniform(tensor, 0);
70 }
71
72 TensorType compute_target(const TensorShape &shape, DataType data_type, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value)
73 {
74 // Create tensors
75 TensorType src = create_tensor<TensorType>(shape, data_type);
76 TensorType dst = create_tensor<TensorType>(shape, data_type);
77
78 // Create and configure function
79 FunctionType warp_affine;
80 warp_affine.configure(&src, &dst, matrix, policy, border_mode, constant_border_value);
81
82 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
83 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
84
85 // Allocate tensors
86 src.allocator()->allocate();
87 dst.allocator()->allocate();
88 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
89 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
90
91 // Fill tensors
92 fill(AccessorType(src));
93
94 // Compute function
95 warp_affine.run();
96
97 return dst;
98 }
99
100 SimpleTensor<T> compute_reference(const TensorShape &shape, DataType data_type, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value)
101 {
102 // Create reference
103 SimpleTensor<T> src{ shape, data_type };
104
105 // Create the valid mask Tensor
106 _valid_mask = SimpleTensor<T>(shape, data_type);
107
108 // Fill reference
109 fill(src);
110
111 return reference::warp_affine<T>(src, _valid_mask, matrix, policy, border_mode, constant_border_value);
112 }
113
114 TensorType _target{};
115 SimpleTensor<T> _reference{};
116 SimpleTensor<T> _valid_mask{};
117};
118} // namespace validation
119} // namespace test
120} // namespace arm_compute
Pablo Tellod616cb92017-09-27 10:07:45 +0100121#endif /* ARM_COMPUTE_TEST_WARP_AFFINE_FIXTURE */