ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2022 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_POOLING_3D_LAYER_DATASET |
| 25 | #define ARM_COMPUTE_TEST_POOLING_3D_LAYER_DATASET |
| 26 | |
| 27 | #include "arm_compute/core/TensorShape.h" |
| 28 | #include "arm_compute/core/Types.h" |
| 29 | #include "utils/TypePrinter.h" |
| 30 | |
| 31 | namespace arm_compute |
| 32 | { |
| 33 | namespace test |
| 34 | { |
| 35 | namespace datasets |
| 36 | { |
| 37 | class Pooling3dLayerDataset |
| 38 | { |
| 39 | public: |
| 40 | using type = std::tuple<TensorShape, Pooling3dLayerInfo>; |
| 41 | |
| 42 | struct iterator |
| 43 | { |
| 44 | iterator(std::vector<TensorShape>::const_iterator src_it, |
| 45 | std::vector<Pooling3dLayerInfo>::const_iterator infos_it) |
| 46 | : _src_it{ std::move(src_it) }, |
| 47 | _infos_it{ std::move(infos_it) } |
| 48 | { |
| 49 | } |
| 50 | |
| 51 | std::string description() const |
| 52 | { |
| 53 | std::stringstream description; |
| 54 | description << "In=" << *_src_it << ":"; |
| 55 | description << "Info=" << *_infos_it << ":"; |
| 56 | return description.str(); |
| 57 | } |
| 58 | |
| 59 | Pooling3dLayerDataset::type operator*() const |
| 60 | { |
| 61 | return std::make_tuple(*_src_it, *_infos_it); |
| 62 | } |
| 63 | |
| 64 | iterator &operator++() |
| 65 | { |
| 66 | ++_src_it; |
| 67 | ++_infos_it; |
| 68 | |
| 69 | return *this; |
| 70 | } |
| 71 | |
| 72 | private: |
| 73 | std::vector<TensorShape>::const_iterator _src_it; |
| 74 | std::vector<Pooling3dLayerInfo>::const_iterator _infos_it; |
| 75 | }; |
| 76 | |
| 77 | iterator begin() const |
| 78 | { |
| 79 | return iterator(_src_shapes.begin(), _infos.begin()); |
| 80 | } |
| 81 | |
| 82 | int size() const |
| 83 | { |
| 84 | return std::min(_src_shapes.size(), _infos.size()); |
| 85 | } |
| 86 | |
| 87 | void add_config(TensorShape src, Pooling3dLayerInfo info) |
| 88 | { |
| 89 | _src_shapes.emplace_back(std::move(src)); |
| 90 | _infos.emplace_back(std::move(info)); |
| 91 | } |
| 92 | |
| 93 | protected: |
| 94 | Pooling3dLayerDataset() = default; |
| 95 | Pooling3dLayerDataset(Pooling3dLayerDataset &&) = default; |
| 96 | |
| 97 | private: |
| 98 | std::vector<TensorShape> _src_shapes{}; |
| 99 | std::vector<Pooling3dLayerInfo> _infos{}; |
| 100 | }; |
| 101 | |
| 102 | // Special pooling dataset |
| 103 | class Pooling3dLayerDatasetSpecial final : public Pooling3dLayerDataset |
| 104 | { |
| 105 | public: |
| 106 | Pooling3dLayerDatasetSpecial() |
| 107 | { |
| 108 | // Special cases |
| 109 | add_config(TensorShape(2U, 3U, 4U, 2U, 4U), Pooling3dLayerInfo(PoolingType::AVG, /*pool size*/ Size3D(2, 2, 1), /*pool strides*/ Size3D(3, 3, 1), /*pool padding*/ Padding3D(0, 0, 0), true)); |
| 110 | add_config(TensorShape(20U, 22U, 10U, 2U), Pooling3dLayerInfo(PoolingType::AVG, Size3D(100, 100, 100), Size3D(5, 5, 5), Padding3D(50, 50, 50), true)); |
| 111 | add_config(TensorShape(10U, 20U, 32U, 3U, 2U), Pooling3dLayerInfo(PoolingType::MAX, /*pool size*/ 3, /*pool strides*/ Size3D(2, 2, 2), Padding3D(1, 1, 1, 1, 1, 1), false, false, |
| 112 | DimensionRoundingType::FLOOR)); |
| 113 | add_config(TensorShape(14U, 10U, 10U, 3U, 5U), Pooling3dLayerInfo(PoolingType::AVG, Size3D(3, 3, 3), /*pool strides*/ Size3D(3, 3, 3), Padding3D(2, 1, 2), true, false, DimensionRoundingType::CEIL)); |
| 114 | add_config(TensorShape(14U, 10U, 10U, 2U, 4U), Pooling3dLayerInfo(PoolingType::AVG, Size3D(3, 3, 3), /*pool strides*/ Size3D(3, 3, 3), Padding3D(2, 1, 2), false, false, DimensionRoundingType::CEIL)); |
| 115 | add_config(TensorShape(15U, 13U, 13U, 3U, 5U), Pooling3dLayerInfo(PoolingType::AVG, Size3D(4, 4, 4), /*pool strides*/ Size3D(2, 2, 2), Padding3D(2, 2, 2), true, false, DimensionRoundingType::CEIL)); |
| 116 | } |
| 117 | }; |
| 118 | } // namespace datasets |
| 119 | } // namespace test |
| 120 | } // namespace arm_compute |
| 121 | #endif /* ARM_COMPUTE_TEST_POOLING_3D_LAYER_DATASET */ |