aboutsummaryrefslogtreecommitdiff
path: root/tests/datasets/ChannelShuffleLayerDataset.h
blob: afab893234b3135edd90f20d509cd81e1456556d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * Copyright (c) 2018 Arm Limited.
 *
 * SPDX-License-Identifier: MIT
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
#ifndef ARM_COMPUTE_TEST_CHANNEL_SHUFFLE_LAYER_DATASET
#define ARM_COMPUTE_TEST_CHANNEL_SHUFFLE_LAYER_DATASET

#include "utils/TypePrinter.h"

#include "arm_compute/core/TensorShape.h"
#include "arm_compute/core/Types.h"

namespace arm_compute
{
namespace test
{
namespace datasets
{
class ChannelShuffleLayerDataset
{
public:
    using type = std::tuple<TensorShape, int>;

    struct iterator
    {
        iterator(std::vector<TensorShape>::const_iterator tensor_it,
                 std::vector<int>::const_iterator         num_groups_it)
            : _tensor_it{ std::move(tensor_it) },
              _num_groups_it{ std::move(num_groups_it) }
        {
        }

        std::string description() const
        {
            std::stringstream description;
            description << "In=" << *_tensor_it << ":";
            description << "NumGroups=" << *_num_groups_it;
            return description.str();
        }

        ChannelShuffleLayerDataset::type operator*() const
        {
            return std::make_tuple(*_tensor_it, *_num_groups_it);
        }

        iterator &operator++()
        {
            ++_tensor_it;
            ++_num_groups_it;

            return *this;
        }

    private:
        std::vector<TensorShape>::const_iterator _tensor_it;
        std::vector<int>::const_iterator         _num_groups_it;
    };

    iterator begin() const
    {
        return iterator(_tensor_shapes.begin(), _num_groups.begin());
    }

    int size() const
    {
        return std::min(_tensor_shapes.size(), _num_groups.size());
    }

    void add_config(TensorShape tensor, int num_groups)
    {
        _tensor_shapes.emplace_back(std::move(tensor));
        _num_groups.emplace_back(std::move(num_groups));
    }

protected:
    ChannelShuffleLayerDataset()                              = default;
    ChannelShuffleLayerDataset(ChannelShuffleLayerDataset &&) = default;

private:
    std::vector<TensorShape> _tensor_shapes{};
    std::vector<int>         _num_groups{};
};

class SmallRandomChannelShuffleLayerDataset final : public ChannelShuffleLayerDataset
{
public:
    SmallRandomChannelShuffleLayerDataset()
    {
        add_config(TensorShape(15U, 16U, 4U, 12U), 2);
        add_config(TensorShape(21U, 11U, 12U, 7U), 4);
        add_config(TensorShape(21U, 11U, 12U, 7U), 6);
        add_config(TensorShape(7U, 3U, 6U, 11U), 3);
    }
};

class LargeRandomChannelShuffleLayerDataset final : public ChannelShuffleLayerDataset
{
public:
    LargeRandomChannelShuffleLayerDataset()
    {
        add_config(TensorShape(210U, 43U, 20U, 3U), 5);
        add_config(TensorShape(283U, 213U, 15U, 3U), 3);
        add_config(TensorShape(500U, 115U, 16U, 2U), 4);
    }
};
} // namespace datasets
} // namespace test
} // namespace arm_compute
#endif /* ARM_COMPUTE_TEST_CHANNEL_SHUFFLE_LAYER_DATASET */