blob: a082ab319635ffeda02e8c392dca06bf650cabff [file] [log] [blame]
John Richardson18300972017-09-13 16:57:46 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017 Arm Limited.
John Richardson18300972017-09-13 16:57:46 +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_THRESHOLD_DATASET
25#define ARM_COMPUTE_TEST_THRESHOLD_DATASET
26
27#include "utils/TypePrinter.h"
28
29#include "arm_compute/core/Types.h"
30
31namespace arm_compute
32{
33namespace test
34{
35namespace datasets
36{
37class ThresholdDataset
38{
39public:
40 using type = std::tuple<uint8_t, uint8_t, uint8_t, ThresholdType, uint8_t>;
41
42 struct iterator
43 {
44 iterator(std::vector<uint8_t>::const_iterator threshold_it,
45 std::vector<uint8_t>::const_iterator false_value_it,
46 std::vector<uint8_t>::const_iterator true_value_it,
47 std::vector<ThresholdType>::const_iterator type_it,
48 std::vector<uint8_t>::const_iterator upper_it)
49 : _threshold_it{ std::move(threshold_it) },
50 _false_value_it{ std::move(false_value_it) },
51 _true_value_it{ std::move(true_value_it) },
52 _type_it{ std::move(type_it) },
53 _upper_it{ std::move(upper_it) }
54 {
55 }
56
57 std::string description() const
58 {
59 std::stringstream description;
60 description << "Threshold=" << static_cast<unsigned>(*_threshold_it) << ":";
61 description << "FalseValue_=" << std::boolalpha << static_cast<unsigned>(*_false_value_it) << ":";
62 description << "TrueValue=" << std::boolalpha << static_cast<unsigned>(*_true_value_it) << ":";
63 description << "Type=" << ((*_type_it == ThresholdType::BINARY) ? "binary" : "range") << ":";
64 description << "Upper=" << static_cast<unsigned>(*_upper_it);
65
66 return description.str();
67 }
68
69 ThresholdDataset::type operator*() const
70 {
71 return std::make_tuple(*_threshold_it, *_false_value_it, *_true_value_it, *_type_it, *_upper_it);
72 }
73
74 iterator &operator++()
75 {
76 ++_threshold_it;
77 ++_false_value_it;
78 ++_true_value_it;
79 ++_type_it;
80 ++_upper_it;
81
82 return *this;
83 }
84
85 private:
86 std::vector<uint8_t>::const_iterator _threshold_it;
87 std::vector<uint8_t>::const_iterator _false_value_it;
88 std::vector<uint8_t>::const_iterator _true_value_it;
89 std::vector<ThresholdType>::const_iterator _type_it;
90 std::vector<uint8_t>::const_iterator _upper_it;
91 };
92
93 iterator begin() const
94 {
95 return iterator(_thresholds.begin(), _false_values.begin(), _true_values.begin(), _types.begin(), _uppers.begin());
96 }
97
98 int size() const
99 {
100 return std::min(_thresholds.size(), std::min(_false_values.size(), std::min(_true_values.size(), std::min(_types.size(), _uppers.size()))));
101 }
102
103 void add_config(uint8_t threshold, uint8_t false_value, uint8_t true_value, ThresholdType threshold_type, uint8_t upper)
104 {
105 _thresholds.emplace_back(std::move(threshold));
106 _false_values.emplace_back(std::move(false_value));
107 _true_values.emplace_back(std::move(true_value));
108 _types.emplace_back(std::move(threshold_type));
109 _uppers.emplace_back(std::move(upper));
110 }
111
112protected:
113 ThresholdDataset() = default;
114 ThresholdDataset(ThresholdDataset &&) = default;
115
116private:
117 std::vector<uint8_t> _thresholds{};
118 std::vector<uint8_t> _false_values{};
119 std::vector<uint8_t> _true_values{};
120 std::vector<ThresholdType> _types{};
121 std::vector<uint8_t> _uppers{};
122};
123
124class MixedThresholdDataset final : public ThresholdDataset
125{
126public:
127 MixedThresholdDataset()
128 {
129 add_config(10U, 25U, 3U, ThresholdType::BINARY, 0U);
130 add_config(20U, 1U, 0U, ThresholdType::BINARY, 0U);
131 add_config(30U, 1U, 0U, ThresholdType::RANGE, 100U);
132 add_config(100U, 1U, 0U, ThresholdType::RANGE, 200U);
133 }
134};
135} // namespace datasets
136} // namespace test
137} // namespace arm_compute
138#endif /* ARM_COMPUTE_TEST_THRESHOLD_DATASET */