blob: 71c786a6414b06b7ee9763f55c5525af30729444 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2017 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_SHAPE_DATASETS_H__
25#define __ARM_COMPUTE_TEST_SHAPE_DATASETS_H__
26
27#include "arm_compute/core/TensorShape.h"
28
29#include <type_traits>
30
31#ifdef BOOST
32#include "boost_wrapper.h"
Anthony Barbierac69aa12017-07-03 17:39:37 +010033#endif /* BOOST */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010034
35namespace arm_compute
36{
37namespace test
38{
39/** Abstract data set containing tensor shapes.
40 *
41 * Can be used as input for Boost data test cases to automatically run a test
42 * case on different tensor shapes.
43 */
44template <unsigned int Size>
45class ShapeDataset
46{
47public:
48 /** Type of the samples in the data set. */
49 using sample = TensorShape;
50
51 /** Dimensionality of the data set. */
52 enum
53 {
54 arity = 1
55 };
56
57 /** Number of samples in the data set. */
58#ifdef BOOST
59 boost::unit_test::data::size_t size() const
Anthony Barbierac69aa12017-07-03 17:39:37 +010060#else /* BOOST */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010061 unsigned int size() const
Anthony Barbierac69aa12017-07-03 17:39:37 +010062#endif /* BOOST */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010063 {
64 return _shapes.size();
65 }
66
67 /** Type of the iterator used to step through all samples in the data set.
68 * Needs to support operator*() and operator++() which a pointer does.
69 */
70 using iterator = const TensorShape *;
71
72 /** Iterator to the first sample in the data set. */
73 iterator begin() const
74 {
75 return _shapes.data();
76 }
77
78protected:
79 /** Protected constructor to make the class abstract. */
80 template <typename... Ts>
81 ShapeDataset(Ts... shapes)
82 : _shapes{ { shapes... } }
83 {
84 }
85
86 /** Protected destructor to prevent deletion of derived class through a
87 * pointer to the base class.
88 */
89 ~ShapeDataset() = default;
90
91private:
92 std::array<TensorShape, Size> _shapes;
93};
94
95/** Data set containing one 1D tensor shape. */
96class Small1DShape final : public ShapeDataset<1>
97{
98public:
99 Small1DShape()
Michalis Spyroud7e82812017-06-20 15:00:14 +0100100 : ShapeDataset(TensorShape(256U))
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100101 {
102 }
103};
104
Giorgio Arenaf7959862017-06-13 15:19:51 +0100105/** Data set containing two small 2D tensor shapes. */
106class Small2DShapes final : public ShapeDataset<2>
107{
108public:
109 Small2DShapes()
110 : ShapeDataset(TensorShape(5U, 5U),
111 TensorShape(640U, 480U))
112 {
113 }
114};
115
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100116/** Data set containing small tensor shapes. */
117class SmallShapes final : public ShapeDataset<3>
118{
119public:
120 SmallShapes()
Georgios Pinitasce093142017-06-19 16:11:53 +0100121 : ShapeDataset(TensorShape(7U, 7U),
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100122 TensorShape(27U, 13U, 2U),
123 TensorShape(128U, 64U, 1U, 3U))
124 {
125 }
126};
127
128/** Data set containing large tensor shapes. */
129class LargeShapes final : public ShapeDataset<3>
130{
131public:
132 LargeShapes()
133 : ShapeDataset(TensorShape(1920U, 1080U),
134 TensorShape(1245U, 652U, 1U, 3U),
135 TensorShape(4160U, 3120U))
136 {
137 }
138};
Giorgio Arenaf7959862017-06-13 15:19:51 +0100139
140/** Data set containing two 2D large tensor shapes. */
141class Large2DShapes final : public ShapeDataset<2>
142{
143public:
144 Large2DShapes()
145 : ShapeDataset(TensorShape(1920U, 1080U),
146 TensorShape(4160U, 3120U))
147 {
148 }
149};
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100150} // namespace test
151} // namespace arm_compute
Anthony Barbierac69aa12017-07-03 17:39:37 +0100152#endif /* __ARM_COMPUTE_TEST_SHAPE_DATASETS_H__ */