blob: 36818010a54512accd98a37fb3d535408e4a6a64 [file] [log] [blame]
Moritz Pflanzeree493ae2017-07-05 10:52:21 +01001/*
Georgios Pinitas15997872018-02-19 13:58:22 +00002 * Copyright (c) 2017-2018 ARM Limited.
Moritz Pflanzeree493ae2017-07-05 10:52:21 +01003 *
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_LAYER_DATASET
25#define ARM_COMPUTE_TEST_POOLING_LAYER_DATASET
26
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010027#include "arm_compute/core/TensorShape.h"
28#include "arm_compute/core/Types.h"
Anthony Barbier2a07e182017-08-04 18:20:27 +010029#include "utils/TypePrinter.h"
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010030
31namespace arm_compute
32{
33namespace test
34{
35namespace datasets
36{
37class PoolingLayerDataset
38{
39public:
40 using type = std::tuple<TensorShape, TensorShape, PoolingLayerInfo>;
41
42 struct iterator
43 {
44 iterator(std::vector<TensorShape>::const_iterator src_it,
45 std::vector<TensorShape>::const_iterator dst_it,
46 std::vector<PoolingLayerInfo>::const_iterator infos_it)
47 : _src_it{ std::move(src_it) },
48 _dst_it{ std::move(dst_it) },
49 _infos_it{ std::move(infos_it) }
50 {
51 }
52
53 std::string description() const
54 {
55 std::stringstream description;
56 description << "In=" << *_src_it << ":";
57 description << "Out=" << *_dst_it << ":";
Michalis Spyrou57dac842018-03-01 16:03:50 +000058 description << "Info=" << *_infos_it << ":";
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010059 return description.str();
60 }
61
62 PoolingLayerDataset::type operator*() const
63 {
64 return std::make_tuple(*_src_it, *_dst_it, *_infos_it);
65 }
66
67 iterator &operator++()
68 {
69 ++_src_it;
70 ++_dst_it;
71 ++_infos_it;
72
73 return *this;
74 }
75
76 private:
77 std::vector<TensorShape>::const_iterator _src_it;
78 std::vector<TensorShape>::const_iterator _dst_it;
79 std::vector<PoolingLayerInfo>::const_iterator _infos_it;
80 };
81
82 iterator begin() const
83 {
84 return iterator(_src_shapes.begin(), _dst_shapes.begin(), _infos.begin());
85 }
86
87 int size() const
88 {
89 return std::min(_src_shapes.size(), std::min(_dst_shapes.size(), _infos.size()));
90 }
91
92 void add_config(TensorShape src, TensorShape dst, PoolingLayerInfo info)
93 {
94 _src_shapes.emplace_back(std::move(src));
95 _dst_shapes.emplace_back(std::move(dst));
96 _infos.emplace_back(std::move(info));
97 }
98
99protected:
100 PoolingLayerDataset() = default;
101 PoolingLayerDataset(PoolingLayerDataset &&) = default;
102
103private:
104 std::vector<TensorShape> _src_shapes{};
105 std::vector<TensorShape> _dst_shapes{};
106 std::vector<PoolingLayerInfo> _infos{};
107};
Georgios Pinitas15997872018-02-19 13:58:22 +0000108
109// Special pooling dataset
110class PoolingLayerDatasetSpecial final : public PoolingLayerDataset
111{
112public:
113 PoolingLayerDatasetSpecial()
114 {
115 // Special cases
116 add_config(TensorShape(60U, 52U, 3U, 2U), TensorShape(13U, 11U, 32U), PoolingLayerInfo(PoolingType::AVG, Size2D(100, 100), PadStrideInfo(5, 5, 50, 50), true));
117 // Asymmetric padding
118 add_config(TensorShape(112U, 112U, 32U), TensorShape(56U, 56U, 32U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 1, 0, 1, DimensionRoundingType::FLOOR)));
Michalis Spyrou57dac842018-03-01 16:03:50 +0000119 add_config(TensorShape(14U, 14U, 832U), TensorShape(7U, 7U, 832U), PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(1, 1, 0, 0, DimensionRoundingType::CEIL)));
Georgios Pinitas15997872018-02-19 13:58:22 +0000120 }
121};
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100122} // namespace datasets
123} // namespace test
124} // namespace arm_compute
125#endif /* ARM_COMPUTE_TEST_POOLING_LAYER_DATASET */