blob: 267cdd5123dd7963ba4fce565cd8fc4f264d2d32 [file] [log] [blame]
Georgios Pinitas77589b52018-08-21 14:41:35 +01001/*
Georgios Pinitasc6f95102021-03-30 10:03:01 +01002 * Copyright (c) 2018-2021 Arm Limited.
Georgios Pinitas77589b52018-08-21 14:41:35 +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 */
Georgios Pinitase1a352c2018-09-03 12:42:19 +010024#ifndef ARM_COMPUTE_TEST_SLICE_OPERATIONS_FIXTURE
25#define ARM_COMPUTE_TEST_SLICE_OPERATIONS_FIXTURE
Georgios Pinitas77589b52018-08-21 14:41:35 +010026
27#include "arm_compute/core/TensorShape.h"
28#include "arm_compute/core/Types.h"
29
30#include "tests/AssetsLibrary.h"
31#include "tests/Globals.h"
32#include "tests/IAccessor.h"
Georgios Pinitas77589b52018-08-21 14:41:35 +010033#include "tests/framework/Asserts.h"
34#include "tests/framework/Fixture.h"
35#include "tests/validation/Helpers.h"
Georgios Pinitasc1a72452018-08-24 11:25:32 +010036#include "tests/validation/reference/SliceOperations.h"
Georgios Pinitas77589b52018-08-21 14:41:35 +010037
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
Georgios Pinitasc1a72452018-08-24 11:25:32 +010045class SliceFixture : public framework::Fixture
46{
47public:
48 template <typename...>
49 void setup(TensorShape shape, Coordinates starts, Coordinates ends, DataType data_type)
50 {
51 _target = compute_target(shape, starts, ends, data_type);
52 _reference = compute_reference(shape, starts, ends, data_type);
53 }
54
55protected:
56 template <typename U>
57 void fill(U &&tensor, int i)
58 {
59 library->fill_tensor_uniform(tensor, i);
60 }
61
62 TensorType compute_target(const TensorShape &shape, const Coordinates &starts, const Coordinates &ends, DataType data_type)
63 {
64 // Create tensors
65 TensorType src = create_tensor<TensorType>(shape, data_type);
66 TensorType dst;
67
68 // Create and configure function
69 FunctionType slice;
70 slice.configure(&src, &dst, starts, ends);
71
Michele Di Giorgio4fc10b32021-04-30 18:30:41 +010072 ARM_COMPUTE_ASSERT(src.info()->is_resizable());
73 ARM_COMPUTE_ASSERT(dst.info()->is_resizable());
Georgios Pinitasc1a72452018-08-24 11:25:32 +010074
75 // Allocate tensors
76 src.allocator()->allocate();
77 dst.allocator()->allocate();
78
Michele Di Giorgio4fc10b32021-04-30 18:30:41 +010079 ARM_COMPUTE_ASSERT(!src.info()->is_resizable());
80 ARM_COMPUTE_ASSERT(!dst.info()->is_resizable());
Georgios Pinitasc1a72452018-08-24 11:25:32 +010081
82 // Fill tensors
83 fill(AccessorType(src), 0);
84 fill(AccessorType(dst), 1);
85
86 // Compute function
87 slice.run();
88
89 return dst;
90 }
91
92 SimpleTensor<T> compute_reference(const TensorShape &shape, const Coordinates &starts, const Coordinates &ends, DataType data_type)
93 {
94 // Create reference
95 SimpleTensor<T> src{ shape, data_type };
96
97 // Fill reference
98 fill(src, 0);
99
100 return reference::slice(src, starts, ends);
101 }
102
103 TensorType _target{};
104 SimpleTensor<T> _reference{};
105};
106
107template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
Georgios Pinitas77589b52018-08-21 14:41:35 +0100108class StridedSliceFixture : public framework::Fixture
109{
110public:
111 template <typename...>
112 void setup(TensorShape shape,
113 Coordinates starts, Coordinates ends, BiStrides strides,
114 int32_t begin_mask, int32_t end_mask, int32_t shrink_mask,
115 DataType data_type)
116 {
117 _target = compute_target(shape, starts, ends, strides, begin_mask, end_mask, shrink_mask, data_type);
118 _reference = compute_reference(shape, starts, ends, strides, begin_mask, end_mask, shrink_mask, data_type);
119 }
120
121protected:
122 template <typename U>
123 void fill(U &&tensor, int i)
124 {
125 library->fill_tensor_uniform(tensor, i);
126 }
127
128 TensorType compute_target(const TensorShape &shape,
129 const Coordinates &starts, const Coordinates &ends, const BiStrides &strides,
130 int32_t begin_mask, int32_t end_mask, int32_t shrink_mask,
131 DataType data_type)
132 {
133 // Create tensors
134 TensorType src = create_tensor<TensorType>(shape, data_type);
135 TensorType dst;
136
137 // Create and configure function
138 FunctionType strided_slice;
139 strided_slice.configure(&src, &dst, starts, ends, strides, begin_mask, end_mask, shrink_mask);
140
Michele Di Giorgio4fc10b32021-04-30 18:30:41 +0100141 ARM_COMPUTE_ASSERT(src.info()->is_resizable());
142 ARM_COMPUTE_ASSERT(dst.info()->is_resizable());
Georgios Pinitas77589b52018-08-21 14:41:35 +0100143
144 // Allocate tensors
145 src.allocator()->allocate();
146 dst.allocator()->allocate();
147
Michele Di Giorgio4fc10b32021-04-30 18:30:41 +0100148 ARM_COMPUTE_ASSERT(!src.info()->is_resizable());
149 ARM_COMPUTE_ASSERT(!dst.info()->is_resizable());
Georgios Pinitas77589b52018-08-21 14:41:35 +0100150
151 // Fill tensors
152 fill(AccessorType(src), 0);
153 fill(AccessorType(dst), 1);
154
155 // Compute function
156 strided_slice.run();
157
158 return dst;
159 }
160
161 SimpleTensor<T> compute_reference(const TensorShape &shape,
162 const Coordinates &starts, const Coordinates &ends, const BiStrides &strides,
163 int32_t begin_mask, int32_t end_mask, int32_t shrink_mask,
164 DataType data_type)
165 {
166 // Create reference
167 SimpleTensor<T> src{ shape, data_type };
168
169 // Fill reference
170 fill(src, 0);
171
172 return reference::strided_slice(src, starts, ends, strides, begin_mask, end_mask, shrink_mask);
173 }
174
175 TensorType _target{};
176 SimpleTensor<T> _reference{};
177};
178} // namespace validation
179} // namespace test
180} // namespace arm_compute
Georgios Pinitase1a352c2018-09-03 12:42:19 +0100181#endif /* ARM_COMPUTE_TEST_SLICE_OPERATIONS_FIXTURE */