• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2018-2019 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 
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 
32 namespace arm_compute
33 {
34 namespace test
35 {
36 namespace datasets
37 {
38 class GatherDataset
39 {
40 public:
41     using type = std::tuple<TensorShape, TensorShape, int>;
42 
43     struct iterator
44     {
iteratoriterator45         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 
descriptioniterator54         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 
begin()82     iterator begin() const
83     {
84         return iterator(_input_shapes.begin(), _indices_shapes.begin(), _axis.begin());
85     }
86 
size()87     int size() const
88     {
89         return std::min(_input_shapes.size(), std::min(_indices_shapes.size(), _axis.size()));
90     }
91 
add_config(TensorShape input_shape,TensorShape indices_shape,int axis)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 
99 protected:
100     GatherDataset()                 = default;
101     GatherDataset(GatherDataset &&) = default;
102 
103 private:
104     std::vector<TensorShape> _input_shapes{};
105     std::vector<TensorShape> _indices_shapes{};
106     std::vector<int>         _axis{};
107 };
108 
109 class SmallGatherDataset final : public GatherDataset
110 {
111 public:
SmallGatherDataset()112     SmallGatherDataset()
113     {
114         // 2D input
115         add_config(TensorShape(15U, 15U), TensorShape(5U), 0);
116         add_config(TensorShape(15U, 15U), TensorShape(5U), 1);
117         add_config(TensorShape(5U, 5U), TensorShape(80U), -1);
118 
119         // 3D input
120         add_config(TensorShape(5U, 5U, 5U), TensorShape(19U), 0);
121         add_config(TensorShape(5U, 4U, 6U), TensorShape(30U), 1);
122         add_config(TensorShape(3U, 5U, 7U), TensorShape(20U), 2);
123         add_config(TensorShape(5U, 4U, 6U), TensorShape(30U), -1);
124         add_config(TensorShape(3U, 5U, 7U), TensorShape(20U), -2);
125 
126         // 4D input
127         add_config(TensorShape(4U, 3U, 4U, 5U), TensorShape(4U), 0);
128         add_config(TensorShape(4U, 3U, 5U, 5U), TensorShape(5U), 1);
129         add_config(TensorShape(4U, 3U, 2U, 5U), TensorShape(6U), 2);
130         add_config(TensorShape(3U, 4U, 4U, 6U), TensorShape(7U), 3);
131         add_config(TensorShape(4U, 3U, 5U, 5U), TensorShape(5U), -1);
132         add_config(TensorShape(4U, 3U, 2U, 5U), TensorShape(6U), -2);
133         add_config(TensorShape(3U, 4U, 4U, 6U), TensorShape(7U), -3);
134     }
135 };
136 
137 class LargeGatherDataset final : public GatherDataset
138 {
139 public:
LargeGatherDataset()140     LargeGatherDataset()
141     {
142         // 2D input
143         add_config(TensorShape(150U, 150U), TensorShape(50U), 0);
144         add_config(TensorShape(150U, 150U), TensorShape(50U), 1);
145         add_config(TensorShape(150U, 150U), TensorShape(50U), -1);
146 
147         // 3D input
148         add_config(TensorShape(50U, 40U, 60U), TensorShape(33U), 0);
149         add_config(TensorShape(40U, 50U, 60U), TensorShape(24U), 1);
150         add_config(TensorShape(70U, 80U, 100U), TensorShape(50U), 2);
151         add_config(TensorShape(40U, 50U, 60U), TensorShape(24U), -1);
152         add_config(TensorShape(70U, 80U, 100U), TensorShape(50U), -2);
153 
154         // 4D input
155         add_config(TensorShape(30U, 40U, 20U, 20U), TensorShape(33U), 0);
156         add_config(TensorShape(23U, 10U, 60U, 20U), TensorShape(24U), 1);
157         add_config(TensorShape(14U, 20U, 10U, 31U), TensorShape(30U), 2);
158         add_config(TensorShape(34U, 10U, 40U, 20U), TensorShape(50U), 3);
159         add_config(TensorShape(23U, 10U, 60U, 20U), TensorShape(24U), -1);
160         add_config(TensorShape(14U, 20U, 10U, 31U), TensorShape(30U), -2);
161         add_config(TensorShape(34U, 10U, 40U, 20U), TensorShape(50U), -3);
162     }
163 };
164 
165 } // namespace datasets
166 } // namespace test
167 } // namespace arm_compute
168 
169 #endif /* ARM_COMPUTE_TEST_GATHER_DATASET */
170