blob: b38252a48931b5ffa1a66f6149e58c7a0744b6da [file] [log] [blame]
Georgios Pinitase1a352c2018-09-03 12:42:19 +01001/*
2 * Copyright (c) 2018 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_SPLIT_DATASET
25#define ARM_COMPUTE_TEST_SPLIT_DATASET
26
27#include "utils/TypePrinter.h"
28
29#include "arm_compute/core/Types.h"
30
31namespace arm_compute
32{
33namespace test
34{
35namespace datasets
36{
37class SplitDataset
38{
39public:
40 using type = std::tuple<TensorShape, unsigned int, unsigned int>;
41
42 struct iterator
43 {
44 iterator(std::vector<TensorShape>::const_iterator tensor_shapes_it,
45 std::vector<unsigned int>::const_iterator axis_values_it,
46 std::vector<unsigned int>::const_iterator splits_values_it)
47 : _tensor_shapes_it{ std::move(tensor_shapes_it) },
48 _axis_values_it{ std::move(axis_values_it) },
49 _splits_values_it{ std::move(splits_values_it) }
50 {
51 }
52
53 std::string description() const
54 {
55 std::stringstream description;
56 description << "Shape=" << *_tensor_shapes_it << ":";
57 description << "Axis=" << *_axis_values_it << ":";
58 description << "Splits=" << *_splits_values_it << ":";
59 return description.str();
60 }
61
62 SplitDataset::type operator*() const
63 {
64 return std::make_tuple(*_tensor_shapes_it, *_axis_values_it, *_splits_values_it);
65 }
66
67 iterator &operator++()
68 {
69 ++_tensor_shapes_it;
70 ++_axis_values_it;
71 ++_splits_values_it;
72 return *this;
73 }
74
75 private:
76 std::vector<TensorShape>::const_iterator _tensor_shapes_it;
77 std::vector<unsigned int>::const_iterator _axis_values_it;
78 std::vector<unsigned int>::const_iterator _splits_values_it;
79 };
80
81 iterator begin() const
82 {
83 return iterator(_tensor_shapes.begin(), _axis_values.begin(), _splits_values.begin());
84 }
85
86 int size() const
87 {
88 return std::min(_tensor_shapes.size(), std::min(_axis_values.size(), _splits_values.size()));
89 }
90
91 void add_config(TensorShape shape, unsigned int axis, unsigned int splits)
92 {
93 _tensor_shapes.emplace_back(std::move(shape));
94 _axis_values.emplace_back(axis);
95 _splits_values.emplace_back(splits);
96 }
97
98protected:
99 SplitDataset() = default;
100 SplitDataset(SplitDataset &&) = default;
101
102private:
103 std::vector<TensorShape> _tensor_shapes{};
104 std::vector<unsigned int> _axis_values{};
105 std::vector<unsigned int> _splits_values{};
106};
107
108class SmallSplitDataset final : public SplitDataset
109{
110public:
111 SmallSplitDataset()
112 {
113 add_config(TensorShape(128U), 0U, 4U);
114 add_config(TensorShape(6U, 3U, 4U), 2U, 2U);
115 add_config(TensorShape(27U, 14U, 2U), 1U, 2U);
116 add_config(TensorShape(64U, 32U, 4U, 6U), 3U, 3U);
117 }
118};
119
120class LargeSplitDataset final : public SplitDataset
121{
122public:
123 LargeSplitDataset()
124 {
125 add_config(TensorShape(512U), 0U, 8U);
126 add_config(TensorShape(128U, 64U, 8U), 2U, 2U);
127 add_config(TensorShape(128U, 64U, 8U, 2U), 1U, 2U);
128 add_config(TensorShape(128U, 64U, 32U, 4U), 3U, 4U);
129 }
130};
131} // namespace datasets
132} // namespace test
133} // namespace arm_compute
134#endif /* ARM_COMPUTE_TEST_SPLIT_DATASET */