blob: 487ce19bc7eb4ce676b29e04795fa0d6704ed8bc [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
Manuel Bottini8529bd62018-11-21 11:53:04 +0000129class SmallGatherDataset final : public GatherDataset
130{
131public:
132 SmallGatherDataset()
133 {
134 // 2D input
135 add_config(TensorShape(15U, 15U), TensorShape(5U), 0);
136 add_config(TensorShape(15U, 15U), TensorShape(5U), 1);
137 add_config(TensorShape(5U, 5U), TensorShape(80U), -1);
138
139 // 3D input
140 add_config(TensorShape(5U, 5U, 5U), TensorShape(19U), 0);
141 add_config(TensorShape(5U, 4U, 6U), TensorShape(30U), 1);
142 add_config(TensorShape(3U, 5U, 7U), TensorShape(20U), 2);
143 add_config(TensorShape(5U, 4U, 6U), TensorShape(30U), -1);
144 add_config(TensorShape(3U, 5U, 7U), TensorShape(20U), -2);
145
146 // 4D input
147 add_config(TensorShape(4U, 3U, 4U, 5U), TensorShape(4U), 0);
148 add_config(TensorShape(4U, 3U, 5U, 5U), TensorShape(5U), 1);
149 add_config(TensorShape(4U, 3U, 2U, 5U), TensorShape(6U), 2);
150 add_config(TensorShape(3U, 4U, 4U, 6U), TensorShape(7U), 3);
151 add_config(TensorShape(4U, 3U, 5U, 5U), TensorShape(5U), -1);
152 add_config(TensorShape(4U, 3U, 2U, 5U), TensorShape(6U), -2);
153 add_config(TensorShape(3U, 4U, 4U, 6U), TensorShape(7U), -3);
154 }
155};
156
157class LargeGatherDataset final : public GatherDataset
158{
159public:
160 LargeGatherDataset()
161 {
162 // 2D input
163 add_config(TensorShape(150U, 150U), TensorShape(50U), 0);
164 add_config(TensorShape(150U, 150U), TensorShape(50U), 1);
165 add_config(TensorShape(150U, 150U), TensorShape(50U), -1);
166
167 // 3D input
168 add_config(TensorShape(50U, 40U, 60U), TensorShape(33U), 0);
169 add_config(TensorShape(40U, 50U, 60U), TensorShape(24U), 1);
170 add_config(TensorShape(70U, 80U, 100U), TensorShape(50U), 2);
171 add_config(TensorShape(40U, 50U, 60U), TensorShape(24U), -1);
172 add_config(TensorShape(70U, 80U, 100U), TensorShape(50U), -2);
173
174 // 4D input
175 add_config(TensorShape(30U, 40U, 20U, 20U), TensorShape(33U), 0);
176 add_config(TensorShape(23U, 10U, 60U, 20U), TensorShape(24U), 1);
177 add_config(TensorShape(14U, 20U, 10U, 31U), TensorShape(30U), 2);
178 add_config(TensorShape(34U, 10U, 40U, 20U), TensorShape(50U), 3);
179 add_config(TensorShape(23U, 10U, 60U, 20U), TensorShape(24U), -1);
180 add_config(TensorShape(14U, 20U, 10U, 31U), TensorShape(30U), -2);
181 add_config(TensorShape(34U, 10U, 40U, 20U), TensorShape(50U), -3);
182 }
183};
184
185} // namespace datasets
186} // namespace test
187} // namespace arm_compute
188
189#endif /* ARM_COMPUTE_TEST_GATHER_DATASET */