Gian Marco Iodice | 477531c | 2018-08-21 17:53:38 +0100 | [diff] [blame] | 1 | /* |
| 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_REORGLAYER_DATASET |
| 25 | #define ARM_COMPUTE_TEST_REORGLAYER_DATASET |
| 26 | |
| 27 | #include "utils/TypePrinter.h" |
| 28 | |
| 29 | #include "arm_compute/core/TensorShape.h" |
| 30 | #include "arm_compute/core/Types.h" |
| 31 | |
| 32 | namespace arm_compute |
| 33 | { |
| 34 | namespace test |
| 35 | { |
| 36 | namespace datasets |
| 37 | { |
| 38 | class ReorgLayerDataset |
| 39 | { |
| 40 | public: |
| 41 | using type = std::tuple<TensorShape, unsigned int>; |
| 42 | |
| 43 | struct iterator |
| 44 | { |
| 45 | iterator(std::vector<TensorShape>::const_iterator src_it, |
| 46 | std::vector<unsigned int>::const_iterator stride_it) |
| 47 | : _src_it{ std::move(src_it) }, |
| 48 | _stride_it{ std::move(stride_it) } |
| 49 | { |
| 50 | } |
| 51 | |
| 52 | std::string description() const |
| 53 | { |
| 54 | std::stringstream description; |
| 55 | description << "In=" << *_src_it << ":"; |
| 56 | description << "Stride=" << *_stride_it; |
| 57 | return description.str(); |
| 58 | } |
| 59 | |
| 60 | ReorgLayerDataset::type operator*() const |
| 61 | { |
| 62 | return std::make_tuple(*_src_it, *_stride_it); |
| 63 | } |
| 64 | |
| 65 | iterator &operator++() |
| 66 | { |
| 67 | ++_src_it; |
| 68 | ++_stride_it; |
| 69 | |
| 70 | return *this; |
| 71 | } |
| 72 | |
| 73 | private: |
| 74 | std::vector<TensorShape>::const_iterator _src_it; |
| 75 | std::vector<unsigned int>::const_iterator _stride_it; |
| 76 | }; |
| 77 | |
| 78 | iterator begin() const |
| 79 | { |
| 80 | return iterator(_src_shapes.begin(), _stride.begin()); |
| 81 | } |
| 82 | |
| 83 | int size() const |
| 84 | { |
| 85 | return std::min(_src_shapes.size(), _stride.size()); |
| 86 | } |
| 87 | |
| 88 | void add_config(TensorShape src, unsigned int stride) |
| 89 | { |
| 90 | _src_shapes.emplace_back(std::move(src)); |
| 91 | _stride.emplace_back(std::move(stride)); |
| 92 | } |
| 93 | |
| 94 | protected: |
| 95 | ReorgLayerDataset() = default; |
| 96 | ReorgLayerDataset(ReorgLayerDataset &&) = default; |
| 97 | |
| 98 | private: |
| 99 | std::vector<TensorShape> _src_shapes{}; |
| 100 | std::vector<unsigned int> _stride{}; |
| 101 | }; |
| 102 | |
| 103 | /** Dataset containing small reorg layer shapes. */ |
| 104 | class SmallReorgLayerDataset final : public ReorgLayerDataset |
| 105 | { |
| 106 | public: |
| 107 | SmallReorgLayerDataset() |
| 108 | { |
| 109 | add_config(TensorShape(26U, 26U, 64U, 1U), 2U); |
| 110 | add_config(TensorShape(28U, 28U, 13U, 1U), 4U); |
| 111 | add_config(TensorShape(12U, 14U, 4U, 1U), 2U); |
| 112 | add_config(TensorShape(9U, 12U, 2U, 4U), 3U); |
| 113 | add_config(TensorShape(25U, 15U, 4U, 2U), 5U); |
| 114 | } |
| 115 | }; |
| 116 | |
| 117 | /** Dataset containing large reorg layer shapes. */ |
| 118 | class LargeReorgLayerDataset final : public ReorgLayerDataset |
| 119 | { |
| 120 | public: |
| 121 | LargeReorgLayerDataset() |
| 122 | { |
| 123 | add_config(TensorShape(49U, 28U, 64U, 1U), 7U); |
| 124 | add_config(TensorShape(63U, 21U, 13U, 1U), 3U); |
| 125 | add_config(TensorShape(48U, 54U, 4U, 1U), 2U); |
| 126 | add_config(TensorShape(114U, 117U, 2U, 4U), 3U); |
| 127 | add_config(TensorShape(100U, 95U, 4U, 2U), 5U); |
| 128 | } |
| 129 | }; |
| 130 | } // namespace datasets |
| 131 | } // namespace test |
| 132 | } // namespace arm_compute |
| 133 | #endif /* ARM_COMPUTE_TEST_REORGLAYER_DATASET */ |