Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
| 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 Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 33 | #endif /* BOOST */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 34 | |
| 35 | namespace arm_compute |
| 36 | { |
| 37 | namespace 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 | */ |
| 44 | template <unsigned int Size> |
| 45 | class ShapeDataset |
| 46 | { |
| 47 | public: |
| 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 Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 60 | #else /* BOOST */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 61 | unsigned int size() const |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 62 | #endif /* BOOST */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 63 | { |
| 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 | |
| 78 | protected: |
| 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 | |
| 91 | private: |
| 92 | std::array<TensorShape, Size> _shapes; |
| 93 | }; |
| 94 | |
| 95 | /** Data set containing one 1D tensor shape. */ |
| 96 | class Small1DShape final : public ShapeDataset<1> |
| 97 | { |
| 98 | public: |
| 99 | Small1DShape() |
Michalis Spyrou | d7e8281 | 2017-06-20 15:00:14 +0100 | [diff] [blame] | 100 | : ShapeDataset(TensorShape(256U)) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 101 | { |
| 102 | } |
| 103 | }; |
| 104 | |
Giorgio Arena | f795986 | 2017-06-13 15:19:51 +0100 | [diff] [blame] | 105 | /** Data set containing two small 2D tensor shapes. */ |
| 106 | class Small2DShapes final : public ShapeDataset<2> |
| 107 | { |
| 108 | public: |
| 109 | Small2DShapes() |
| 110 | : ShapeDataset(TensorShape(5U, 5U), |
| 111 | TensorShape(640U, 480U)) |
| 112 | { |
| 113 | } |
| 114 | }; |
| 115 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 116 | /** Data set containing small tensor shapes. */ |
| 117 | class SmallShapes final : public ShapeDataset<3> |
| 118 | { |
| 119 | public: |
| 120 | SmallShapes() |
Georgios Pinitas | ce09314 | 2017-06-19 16:11:53 +0100 | [diff] [blame] | 121 | : ShapeDataset(TensorShape(7U, 7U), |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 122 | TensorShape(27U, 13U, 2U), |
| 123 | TensorShape(128U, 64U, 1U, 3U)) |
| 124 | { |
| 125 | } |
| 126 | }; |
| 127 | |
| 128 | /** Data set containing large tensor shapes. */ |
| 129 | class LargeShapes final : public ShapeDataset<3> |
| 130 | { |
| 131 | public: |
| 132 | LargeShapes() |
| 133 | : ShapeDataset(TensorShape(1920U, 1080U), |
| 134 | TensorShape(1245U, 652U, 1U, 3U), |
| 135 | TensorShape(4160U, 3120U)) |
| 136 | { |
| 137 | } |
| 138 | }; |
Giorgio Arena | f795986 | 2017-06-13 15:19:51 +0100 | [diff] [blame] | 139 | |
| 140 | /** Data set containing two 2D large tensor shapes. */ |
| 141 | class Large2DShapes final : public ShapeDataset<2> |
| 142 | { |
| 143 | public: |
| 144 | Large2DShapes() |
| 145 | : ShapeDataset(TensorShape(1920U, 1080U), |
| 146 | TensorShape(4160U, 3120U)) |
| 147 | { |
| 148 | } |
| 149 | }; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 150 | } // namespace test |
| 151 | } // namespace arm_compute |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 152 | #endif /* __ARM_COMPUTE_TEST_SHAPE_DATASETS_H__ */ |