blob: 74ea3b4a066a9153dc808729620bc9515c12f132 [file] [log] [blame]
Manuel Bottini8529bd62018-11-21 11:53:04 +00001/*
Viet-Hoa Do37c989a2023-02-24 15:52:21 +00002 * Copyright (c) 2018-2019, 2022-2023 Arm Limited.
Manuel Bottini8529bd62018-11-21 11:53:04 +00003 *
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
25#ifndef ARM_COMPUTE_TEST_GATHER_DATASET
26#define ARM_COMPUTE_TEST_GATHER_DATASET
27
28#include "utils/TypePrinter.h"
29
30#include "arm_compute/core/Types.h"
31
32namespace arm_compute
33{
34namespace test
35{
36namespace datasets
37{
38class GatherDataset
39{
40public:
41 using type = std::tuple<TensorShape, TensorShape, int>;
42
43 struct iterator
44 {
45 iterator(std::vector<TensorShape>::const_iterator input_shapes_it,
46 std::vector<TensorShape>::const_iterator starts_values_it,
47 std::vector<int>::const_iterator axis_it)
48 : _input_shapes_it{ std::move(input_shapes_it) },
49 _indices_shapes_it{ std::move(starts_values_it) },
50 _axis_it{ std::move(axis_it) }
51 {
52 }
53
54 std::string description() const
55 {
56 std::stringstream description;
57 description << "InputShape=" << *_input_shapes_it << ":";
58 description << "IndicesShape=" << *_indices_shapes_it << ":";
59 description << "Axis=" << *_axis_it << ":";
60 return description.str();
61 }
62
63 GatherDataset::type operator*() const
64 {
65 return std::make_tuple(*_input_shapes_it, *_indices_shapes_it, *_axis_it);
66 }
67
68 iterator &operator++()
69 {
70 ++_input_shapes_it;
71 ++_indices_shapes_it;
72 ++_axis_it;
73 return *this;
74 }
75
76 private:
77 std::vector<TensorShape>::const_iterator _input_shapes_it;
78 std::vector<TensorShape>::const_iterator _indices_shapes_it;
79 std::vector<int>::const_iterator _axis_it;
80 };
81
82 iterator begin() const
83 {
84 return iterator(_input_shapes.begin(), _indices_shapes.begin(), _axis.begin());
85 }
86
87 int size() const
88 {
89 return std::min(_input_shapes.size(), std::min(_indices_shapes.size(), _axis.size()));
90 }
91
92 void add_config(TensorShape input_shape, TensorShape indices_shape, int axis)
93 {
94 _input_shapes.emplace_back(std::move(input_shape));
95 _indices_shapes.emplace_back(std::move(indices_shape));
96 _axis.emplace_back(std::move(axis));
97 }
98
99protected:
100 GatherDataset() = default;
101 GatherDataset(GatherDataset &&) = default;
102
103private:
104 std::vector<TensorShape> _input_shapes{};
105 std::vector<TensorShape> _indices_shapes{};
106 std::vector<int> _axis{};
107};
108
Pablo Marquez Tello894659a2022-05-13 12:20:16 +0100109class SmallGatherMultiDimIndicesDataset final : public GatherDataset
110{
111public:
112 SmallGatherMultiDimIndicesDataset()
113 {
114 add_config(TensorShape(2U, 6U), TensorShape(4U, 9U), 1);
115 add_config(TensorShape(15U, 15U), TensorShape(3U, 2U, 2U), 1);
116 add_config(TensorShape(15U, 15U), TensorShape(2U, 11U), 1);
117 add_config(TensorShape(5U, 3U, 4U), TensorShape(2U, 7U), 1);
118 add_config(TensorShape(1U, 5U, 3U), TensorShape(1U, 7U, 3U), 1);
Viet-Hoa Do37c989a2023-02-24 15:52:21 +0000119
120 add_config(TensorShape(3U, 5U), TensorShape(2U, 3U), 0);
121 add_config(TensorShape(9U), TensorShape(3U, 2U, 4U), 0);
122 add_config(TensorShape(5U, 3U, 4U), TensorShape(5U, 6U), 0);
123
124 add_config(TensorShape(7U, 4U, 5U), TensorShape(2U, 3U), 2);
125 add_config(TensorShape(8U, 2U, 3U), TensorShape(4U, 2U, 5U), 2);
Pablo Marquez Tello894659a2022-05-13 12:20:16 +0100126 }
127};
128
Omar Al Khatibcdd1e032023-04-26 11:31:45 +0100129class CLSmallGatherMultiDimIndicesDataset final : public GatherDataset
130{
131public:
132 CLSmallGatherMultiDimIndicesDataset()
133 {
134 add_config(TensorShape(2U, 6U), TensorShape(4U, 9U), 0);
135 add_config(TensorShape(15U, 15U), TensorShape(3U, 2U, 2U), 0);
136 add_config(TensorShape(15U, 15U), TensorShape(2U, 11U), 0);
137 add_config(TensorShape(5U, 3U, 4U), TensorShape(2U, 7U), 0);
138
139 add_config(TensorShape(3U, 5U), TensorShape(2U, 3U), 0);
140 add_config(TensorShape(9U), TensorShape(3U, 2U, 4U), 0);
141 add_config(TensorShape(5U, 3U, 4U), TensorShape(5U, 6U), 0);
142
143 add_config(TensorShape(7U, 4U, 5U), TensorShape(2U, 3U),0);
144
145 add_config(TensorShape(2U, 6U), TensorShape(4U, 9U), 1);
146 add_config(TensorShape(15U, 15U), TensorShape(3U, 2U, 2U), 1);
147 add_config(TensorShape(15U, 15U), TensorShape(2U, 11U), 1);
148 add_config(TensorShape(5U, 3U, 4U), TensorShape(2U, 7U), 1);
149
150 add_config(TensorShape(3U, 5U), TensorShape(2U, 3U), 1);
151 add_config(TensorShape(9U), TensorShape(3U, 2U, 4U), 1);
152 add_config(TensorShape(5U, 3U, 4U), TensorShape(5U, 6U), 1);
153
154 add_config(TensorShape(7U, 4U, 5U), TensorShape(2U, 3U),1);
155
156 add_config(TensorShape(2U, 6U), TensorShape(4U, 9U), 2);
157 add_config(TensorShape(15U, 15U), TensorShape(2U, 11U), 2);
158 add_config(TensorShape(5U, 3U, 4U), TensorShape(2U, 7U), 2);
159
160 add_config(TensorShape(3U, 5U), TensorShape(2U, 3U), 2);
161 add_config(TensorShape(5U, 3U, 4U), TensorShape(5U, 6U), 2);
162
163 add_config(TensorShape(7U, 4U, 5U), TensorShape(2U, 3U),2);
164 }
165};
166
Manuel Bottini8529bd62018-11-21 11:53:04 +0000167class SmallGatherDataset final : public GatherDataset
168{
169public:
170 SmallGatherDataset()
171 {
172 // 2D input
173 add_config(TensorShape(15U, 15U), TensorShape(5U), 0);
174 add_config(TensorShape(15U, 15U), TensorShape(5U), 1);
175 add_config(TensorShape(5U, 5U), TensorShape(80U), -1);
176
177 // 3D input
178 add_config(TensorShape(5U, 5U, 5U), TensorShape(19U), 0);
179 add_config(TensorShape(5U, 4U, 6U), TensorShape(30U), 1);
180 add_config(TensorShape(3U, 5U, 7U), TensorShape(20U), 2);
181 add_config(TensorShape(5U, 4U, 6U), TensorShape(30U), -1);
182 add_config(TensorShape(3U, 5U, 7U), TensorShape(20U), -2);
183
184 // 4D input
185 add_config(TensorShape(4U, 3U, 4U, 5U), TensorShape(4U), 0);
186 add_config(TensorShape(4U, 3U, 5U, 5U), TensorShape(5U), 1);
187 add_config(TensorShape(4U, 3U, 2U, 5U), TensorShape(6U), 2);
188 add_config(TensorShape(3U, 4U, 4U, 6U), TensorShape(7U), 3);
189 add_config(TensorShape(4U, 3U, 5U, 5U), TensorShape(5U), -1);
190 add_config(TensorShape(4U, 3U, 2U, 5U), TensorShape(6U), -2);
191 add_config(TensorShape(3U, 4U, 4U, 6U), TensorShape(7U), -3);
192 }
193};
194
195class LargeGatherDataset final : public GatherDataset
196{
197public:
198 LargeGatherDataset()
199 {
200 // 2D input
201 add_config(TensorShape(150U, 150U), TensorShape(50U), 0);
202 add_config(TensorShape(150U, 150U), TensorShape(50U), 1);
203 add_config(TensorShape(150U, 150U), TensorShape(50U), -1);
204
205 // 3D input
206 add_config(TensorShape(50U, 40U, 60U), TensorShape(33U), 0);
207 add_config(TensorShape(40U, 50U, 60U), TensorShape(24U), 1);
208 add_config(TensorShape(70U, 80U, 100U), TensorShape(50U), 2);
209 add_config(TensorShape(40U, 50U, 60U), TensorShape(24U), -1);
210 add_config(TensorShape(70U, 80U, 100U), TensorShape(50U), -2);
211
212 // 4D input
213 add_config(TensorShape(30U, 40U, 20U, 20U), TensorShape(33U), 0);
214 add_config(TensorShape(23U, 10U, 60U, 20U), TensorShape(24U), 1);
215 add_config(TensorShape(14U, 20U, 10U, 31U), TensorShape(30U), 2);
216 add_config(TensorShape(34U, 10U, 40U, 20U), TensorShape(50U), 3);
217 add_config(TensorShape(23U, 10U, 60U, 20U), TensorShape(24U), -1);
218 add_config(TensorShape(14U, 20U, 10U, 31U), TensorShape(30U), -2);
219 add_config(TensorShape(34U, 10U, 40U, 20U), TensorShape(50U), -3);
220 }
221};
222
223} // namespace datasets
224} // namespace test
225} // namespace arm_compute
226
227#endif /* ARM_COMPUTE_TEST_GATHER_DATASET */