blob: 34fc782b10bafc9222f57a81269f56a0276afc85 [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_DATA_TYPE_DATASET_H__
25#define __ARM_COMPUTE_TEST_DATA_TYPE_DATASET_H__
26
27#include "arm_compute/core/Types.h"
28
29#ifdef BOOST
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010030#include "tests/validation_old/boost_wrapper.h"
Anthony Barbierac69aa12017-07-03 17:39:37 +010031#endif /* BOOST */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010032
33namespace arm_compute
34{
35namespace test
36{
37/** Abstract data set containing data types.
38 *
39 * Can be used as input for Boost data test cases to automatically run a test
40 * case on different data types.
41 */
42template <unsigned int Size>
43class DataTypes
44{
45public:
46 /** Type of the samples in the data set. */
47 using sample = DataType;
48
49 /** Dimensionality of the data set. */
50 enum
51 {
52 arity = 1
53 };
54
55 /** Number of samples in the data set. */
56#ifdef BOOST
57 boost::unit_test::data::size_t size() const
Anthony Barbierac69aa12017-07-03 17:39:37 +010058#else /* BOOST */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010059 unsigned int size() const
Anthony Barbierac69aa12017-07-03 17:39:37 +010060#endif /* BOOST */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010061 {
62 return _types.size();
63 }
64
65 /** Type of the iterator used to step through all samples in the data set.
66 * Needs to support operator*() and operator++() which a pointer does.
67 */
68 using iterator = const DataType *;
69
70 /** Iterator to the first sample in the data set. */
71 iterator begin() const
72 {
73 return _types.data();
74 }
75
76protected:
77 /** Protected constructor to make the class abstract. */
78 template <typename... Ts>
79 DataTypes(Ts &&... types)
80 : _types{ { types... } }
81 {
82 }
83
84 /** Protected destructor to prevent deletion of derived classes through a
85 * pointer to the base class.
86 */
87 ~DataTypes() = default;
88
89private:
90 std::array<DataType, Size> _types;
91};
92
93/** Data set containing all data types. */
94class AllDataTypes final : public DataTypes<14>
95{
96public:
97 AllDataTypes()
98 : DataTypes{ DataType::U8, DataType::S8, DataType::U16, DataType::S16,
99 DataType::U32, DataType::S32, DataType::U64, DataType::S64,
100 DataType::F16, DataType::F32, DataType::F64, DataType::SIZET,
101 DataType::QS8, DataType::QS16 }
102 {
103 }
104
105 ~AllDataTypes() = default;
106};
107
108/** Data set containing all unsigned data types. */
109class UnsignedDataTypes final : public DataTypes<4>
110{
111public:
112 UnsignedDataTypes()
113 : DataTypes{ DataType::U8, DataType::U16, DataType::U32, DataType::U64 }
114 {
115 }
116
117 ~UnsignedDataTypes() = default;
118};
119
120/** Data set containing all signed data types. */
121class SignedDataTypes final : public DataTypes<4>
122{
123public:
124 SignedDataTypes()
125 : DataTypes{ DataType::S8, DataType::S16, DataType::S32, DataType::S64 }
126 {
127 }
128
129 ~SignedDataTypes() = default;
130};
131
132/** Data set containing all floating point data types. */
133class FloatDataTypes final : public DataTypes<3>
134{
135public:
136 FloatDataTypes()
137 : DataTypes{ DataType::F16, DataType::F32, DataType::F64 }
138 {
139 }
140
141 ~FloatDataTypes() = default;
142};
143
144/** Data set containing all fixed point data types. */
145class FixedPointDataTypes final : public DataTypes<2>
146{
147public:
148 FixedPointDataTypes()
149 : DataTypes{ DataType::QS8, DataType::QS16 }
150 {
151 }
152
153 ~FixedPointDataTypes() = default;
154};
155
156/** Supported CNN float types. */
157class CNNFloatDataTypes final : public DataTypes<1>
158{
159public:
160 CNNFloatDataTypes()
161 : DataTypes{ DataType::F32 }
162 {
163 }
164
165 ~CNNFloatDataTypes() = default;
166};
167
168/** Supported CNN fixed point types. */
Georgios Pinitasac4e8732017-07-05 17:02:25 +0100169class CNNFixedPointDataTypes final : public DataTypes<2>
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100170{
171public:
172 CNNFixedPointDataTypes()
Georgios Pinitasac4e8732017-07-05 17:02:25 +0100173 : DataTypes{ DataType::QS8, DataType::QS16 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100174 {
175 }
176
177 ~CNNFixedPointDataTypes() = default;
178};
179
180/** Supported CNN types. */
181class CNNDataTypes final : public DataTypes<2>
182{
183public:
184 CNNDataTypes()
185 : DataTypes{ DataType::F32, DataType::QS8 }
186 {
187 }
188
189 ~CNNDataTypes() = default;
190};
191} // namespace test
192} // namespace arm_compute
Anthony Barbierac69aa12017-07-03 17:39:37 +0100193#endif /* __ARM_COMPUTE_TEST_DATA_TYPE_DATASET_H__ */