From 69e44dc073bae7f7f54923d306a52d809b1334d5 Mon Sep 17 00:00:00 2001 From: Moritz Pflanzer Date: Wed, 5 Jul 2017 11:02:14 +0100 Subject: COMPMID-415: New framework - datasets [2/5] Change-Id: Ice4e5d73f40ba2f105663924393afcc88db07973 Reviewed-on: http://mpd-gerrit.cambridge.arm.com/79756 Tested-by: Kaizen Reviewed-by: Georgios Pinitas Reviewed-by: Anthony Barbier --- framework/datasets/CartesianProductDataset.h | 163 +++++++++++++++++++++++++++ framework/datasets/ContainerDataset.h | 148 ++++++++++++++++++++++++ framework/datasets/Dataset.h | 86 ++++++++++++++ framework/datasets/Datasets.h | 35 ++++++ framework/datasets/InitializerListDataset.h | 135 ++++++++++++++++++++++ framework/datasets/JoinDataset.h | 148 ++++++++++++++++++++++++ framework/datasets/RangeDataset.h | 134 ++++++++++++++++++++++ framework/datasets/SingletonDataset.h | 138 +++++++++++++++++++++++ framework/datasets/ZipDataset.h | 139 +++++++++++++++++++++++ 9 files changed, 1126 insertions(+) create mode 100644 framework/datasets/CartesianProductDataset.h create mode 100644 framework/datasets/ContainerDataset.h create mode 100644 framework/datasets/Dataset.h create mode 100644 framework/datasets/Datasets.h create mode 100644 framework/datasets/InitializerListDataset.h create mode 100644 framework/datasets/JoinDataset.h create mode 100644 framework/datasets/RangeDataset.h create mode 100644 framework/datasets/SingletonDataset.h create mode 100644 framework/datasets/ZipDataset.h (limited to 'framework') diff --git a/framework/datasets/CartesianProductDataset.h b/framework/datasets/CartesianProductDataset.h new file mode 100644 index 0000000000..e03a45da1f --- /dev/null +++ b/framework/datasets/CartesianProductDataset.h @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2017 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_DATASET_CARTESIAN_PRODUCT +#define ARM_COMPUTE_TEST_DATASET_CARTESIAN_PRODUCT + +#include "Dataset.h" + +#include +#include +#include + +namespace arm_compute +{ +namespace test +{ +namespace framework +{ +namespace dataset +{ +/** Implementation of a dataset representing all combinations of values of the input datasets. + * + * For example, for the inputs {1, 2} and {3, 4} this dataset virtually + * represents the values {(1, 3), (1, 4), (2, 3), (2, 4)}. + */ +template +class CartesianProductDataset : public Dataset +{ +private: + using iter1_type = typename T::iterator; + using iter2_type = typename U::iterator; + +public: + /** Construct dataset from the given datasets. + * + * @param[in] dataset1 First dataset. + * @param[in] dataset2 Second dataset. + */ + CartesianProductDataset(T &&dataset1, U &&dataset2) + : _dataset1{ std::forward(dataset1) }, + _dataset2{ std::forward(dataset2) } + { + } + + CartesianProductDataset(CartesianProductDataset &&) = default; + + /** Type of the dataset. */ + using type = decltype(std::tuple_cat(*std::declval(), *std::declval())); + + /** Iterator for the dataset. */ + struct iterator + { + iterator(const T *dataset1, const U *dataset2) + : _iter1{ dataset1->begin() }, + _dataset2{ dataset2 }, + _iter2{ dataset2->begin() } + { + } + + iterator(const iterator &) = default; + iterator &operator=(const iterator &) = default; + iterator(iterator &&) = default; + iterator &operator=(iterator &&) = default; + + ~iterator() = default; + + std::string description() const + { + return _iter1.description() + ":" + _iter2.description(); + } + + CartesianProductDataset::type operator*() const + { + return std::tuple_cat(*_iter1, *_iter2); + } + + iterator &operator++() + { + ++_second_pos; + + if(_second_pos < _dataset2->size()) + { + ++_iter2; + } + else + { + _second_pos = 0; + _iter2 = _dataset2->begin(); + + ++_iter1; + } + + return *this; + } + + private: + iter1_type _iter1; + const U *_dataset2; + iter2_type _iter2; + int _first_pos{ 0 }; + int _second_pos{ 0 }; + }; + + /** Iterator pointing at the begin of the dataset. + * + * @return Iterator for the dataset. + */ + iterator begin() const + { + return iterator(&_dataset1, &_dataset2); + } + + /** Size of the dataset. + * + * @return Number of values in the dataset. + */ + int size() const + { + return _dataset1.size() * _dataset2.size(); + } + +private: + T _dataset1; + U _dataset2; +}; + +/** Helper function to create a @ref CartesianProductDataset. + * + * @param[in] dataset1 First dataset. + * @param[in] dataset2 Second dataset. + * + * @return A grid dataset. + */ +template +CartesianProductDataset combine(T &&dataset1, U &&dataset2) +{ + return CartesianProductDataset(std::forward(dataset1), std::forward(dataset2)); +} +} // namespace dataset +} // namespace framework +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_DATASET_CARTESIAN_PRODUCT */ diff --git a/framework/datasets/ContainerDataset.h b/framework/datasets/ContainerDataset.h new file mode 100644 index 0000000000..af685439b5 --- /dev/null +++ b/framework/datasets/ContainerDataset.h @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2017 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_DATASET_CONTAINER +#define ARM_COMPUTE_TEST_DATASET_CONTAINER + +#include "Dataset.h" +#include "support/ToolchainSupport.h" + +#include +#include +#include +#include +#include + +namespace arm_compute +{ +namespace test +{ +namespace framework +{ +namespace dataset +{ +/** Base case. Nothing is a container. */ +template +struct is_container : public std::false_type +{ +}; + +/** Vector is considered a container. */ +template +struct is_container> : public std::true_type +{ +}; + +/** Implementation of a dataset created from a container. */ +template +class ContainerDataset final : public NamedDataset +{ +private: + using container_value_type = typename T::value_type; + using container_const_iterator = typename T::const_iterator; + +public: + /** Construct dataset with given name and values from the container. + * + * @param[in] name Description of the values. + * @param[in] container Values for the dataset. + */ + ContainerDataset(std::string name, T &&container) + : NamedDataset{ std::move(name) }, _container{ std::forward(container) } + { + } + + ContainerDataset(ContainerDataset &&) = default; + + /** Type of the dataset. */ + using type = std::tuple; + + /** Iterator for the dataset. */ + struct iterator + { + iterator(std::string name, container_const_iterator iterator) + : _name{ name }, _iterator{ iterator } + { + } + + std::string description() const + { + using support::cpp11::to_string; + return _name + "=" + to_string(*_iterator); + } + + ContainerDataset::type operator*() const + { + return std::make_tuple(*_iterator); + } + + iterator &operator++() + { + ++_iterator; + return *this; + } + + private: + std::string _name; + container_const_iterator _iterator; + }; + + /** Iterator pointing at the begin of the dataset. + * + * @return Iterator for the dataset. + */ + iterator begin() const + { + return iterator(name(), _container.cbegin()); + } + + /** Size of the dataset. + * + * @return Number of values in the dataset. + */ + int size() const + { + return _container.size(); + } + +private: + T _container; +}; + +/** Helper function to create a @ref ContainerDataset. + * + * @param[in] name Name of the dataset. + * @param[in] values Container. + * + * @return A container dataset. + */ +template +typename std::enable_if::value, ContainerDataset>::type make(std::string name, T &&values) +{ + return ContainerDataset(std::move(name), std::forward(values)); +} +} // namespace dataset +} // namespace framework +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_DATASET_CONTAINER */ diff --git a/framework/datasets/Dataset.h b/framework/datasets/Dataset.h new file mode 100644 index 0000000000..d91673073a --- /dev/null +++ b/framework/datasets/Dataset.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2017 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_DATASET +#define ARM_COMPUTE_TEST_DATASET + +#include +#include + +namespace arm_compute +{ +namespace test +{ +namespace framework +{ +namespace dataset +{ +/** Abstract dataset base class. */ +class Dataset +{ +protected: + Dataset() = default; + ~Dataset() = default; + +public: + Dataset(Dataset &&) = default; +}; + +/** Abstract implementation of a named dataset. + * + * The name should describe the values of the dataset. + */ +class NamedDataset : public Dataset +{ +protected: + /** Construct the dataset with the given name. + * + * @param[in] name Description of the values. + */ + explicit NamedDataset(std::string name) + : _name{ std::move(name) } + { + } + + ~NamedDataset() = default; + +public: + NamedDataset(NamedDataset &&) = default; + + /** Return name of the dataset. + * + * @return Description of the values. + */ + std::string name() const + { + return _name; + } + +protected: + const std::string _name; +}; +} // namespace dataset +} // namespace framework +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_DATASET */ diff --git a/framework/datasets/Datasets.h b/framework/datasets/Datasets.h new file mode 100644 index 0000000000..c0e5822e17 --- /dev/null +++ b/framework/datasets/Datasets.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2017 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_DATASETS +#define ARM_COMPUTE_TEST_DATASETS + +#include "CartesianProductDataset.h" +#include "ContainerDataset.h" +#include "InitializerListDataset.h" +#include "JoinDataset.h" +#include "RangeDataset.h" +#include "SingletonDataset.h" +#include "ZipDataset.h" + +#endif /* ARM_COMPUTE_TEST_DATASETS */ diff --git a/framework/datasets/InitializerListDataset.h b/framework/datasets/InitializerListDataset.h new file mode 100644 index 0000000000..7d32234fab --- /dev/null +++ b/framework/datasets/InitializerListDataset.h @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2017 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_DATASET_LIST +#define ARM_COMPUTE_TEST_DATASET_LIST + +#include "Dataset.h" +#include "support/ToolchainSupport.h" + +#include +#include +#include +#include +#include + +namespace arm_compute +{ +namespace test +{ +namespace framework +{ +namespace dataset +{ +/** Implementation of a dataset created from an initializer list. */ +template +class InitializerListDataset final : public NamedDataset +{ +private: + using data_const_iterator = typename std::vector::const_iterator; + +public: + /** Construct dataset with given name and values from the container. + * + * @param[in] name Description of the values. + * @param[in] list Values for the dataset. + */ + InitializerListDataset(std::string name, std::initializer_list &&list) + : NamedDataset{ std::move(name) }, _data(std::forward>(list)) + { + } + + InitializerListDataset(InitializerListDataset &&) = default; + + /** Type of the dataset. */ + using type = std::tuple; + + /** Iterator for the dataset. */ + struct iterator + { + iterator(std::string name, data_const_iterator iterator) + : _name{ name }, _iterator{ iterator } + { + } + + std::string description() const + { + using support::cpp11::to_string; + return _name + "=" + to_string(*_iterator); + } + + InitializerListDataset::type operator*() const + { + return std::make_tuple(*_iterator); + } + + iterator &operator++() + { + ++_iterator; + return *this; + } + + private: + std::string _name; + data_const_iterator _iterator; + }; + + /** Iterator pointing at the begin of the dataset. + * + * @return Iterator for the dataset. + */ + iterator begin() const + { + return iterator(name(), _data.cbegin()); + } + + /** Size of the dataset. + * + * @return Number of values in the dataset. + */ + int size() const + { + return _data.size(); + } + +private: + std::vector _data; +}; + +/** Helper function to create an @ref InitializerListDataset. + * + * @param[in] name Name of the dataset. + * @param[in] list Initializer list. + * + * @return An initializer list dataset. + */ +template +InitializerListDataset make(std::string name, std::initializer_list &&list) +{ + return InitializerListDataset(std::move(name), std::forward>(list)); +} +} // namespace dataset +} // namespace framework +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_DATASET_LIST */ diff --git a/framework/datasets/JoinDataset.h b/framework/datasets/JoinDataset.h new file mode 100644 index 0000000000..eded6e0259 --- /dev/null +++ b/framework/datasets/JoinDataset.h @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2017 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_DATASET_JOIN +#define ARM_COMPUTE_TEST_DATASET_JOIN + +#include "Dataset.h" + +#include +#include +#include + +namespace arm_compute +{ +namespace test +{ +namespace framework +{ +namespace dataset +{ +/** Implementation of a dataset representing the concatenation of the input datasets. + * + * For example, for the inputs {1, 2} and {3, 4} this dataset virtually + * represents the values {1, 2, 3, 4}. + */ +template +class JoinDataset : public Dataset +{ +private: + using iter1_type = typename T::iterator; + using iter2_type = typename U::iterator; + +public: + /** Construct dataset from the given datasets. + * + * @param[in] dataset1 First dataset. + * @param[in] dataset2 Second dataset. + */ + JoinDataset(T &&dataset1, U &&dataset2) + : _dataset1{ std::forward(dataset1) }, + _dataset2{ std::forward(dataset2) } + { + } + + JoinDataset(JoinDataset &&) = default; + + /** Type of the dataset. */ + using type = typename T::type; + + /** Iterator for the dataset. */ + struct iterator + { + iterator(const T *dataset1, const U *dataset2) + : _iter1{ dataset1->begin() }, _iter2{ dataset2->begin() }, _first_size{ dataset1->size() } + { + } + + std::string description() const + { + return _first_size > 0 ? _iter1.description() : _iter2.description(); + } + + JoinDataset::type operator*() const + { + return _first_size > 0 ? *_iter1 : *_iter2; + } + + iterator &operator++() + { + if(_first_size > 0) + { + --_first_size; + ++_iter1; + } + else + { + ++_iter2; + } + + return *this; + } + + private: + iter1_type _iter1; + iter2_type _iter2; + int _first_size; + }; + + /** Iterator pointing at the begin of the dataset. + * + * @return Iterator for the dataset. + */ + iterator begin() const + { + return iterator(&_dataset1, &_dataset2); + } + + /** Size of the dataset. + * + * @return Number of values in the dataset. + */ + int size() const + { + return _dataset1.size() + _dataset2.size(); + } + +private: + T _dataset1; + U _dataset2; +}; + +/** Helper function to create a @ref JoinDataset. + * + * @param[in] dataset1 First dataset. + * @param[in] dataset2 Second dataset. + * + * @return A join dataset. + */ +template +JoinDataset concat(T &&dataset1, U &&dataset2) +{ + return JoinDataset(std::forward(dataset1), std::forward(dataset2)); +} +} // namespace dataset +} // namespace framework +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_DATASET_JOIN */ diff --git a/framework/datasets/RangeDataset.h b/framework/datasets/RangeDataset.h new file mode 100644 index 0000000000..2489405ff7 --- /dev/null +++ b/framework/datasets/RangeDataset.h @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2017 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_DATASET_RANGE +#define ARM_COMPUTE_TEST_DATASET_RANGE + +#include "Dataset.h" +#include "support/ToolchainSupport.h" + +#include +#include +#include +#include + +namespace arm_compute +{ +namespace test +{ +namespace framework +{ +namespace dataset +{ +/** Implementation of a dataset created from a range of values. */ +template +class RangeDataset final : public NamedDataset +{ +public: + /** Construct dataset with given name and values in the specified range. + * + * @param[in] name Description of the values. + * @param[in] first Iterator to the first value. + * @param[in] last Iterator behind the last value. + */ + RangeDataset(std::string name, T &&first, T &&last) + : NamedDataset{ std::move(name) }, _first{ std::forward(first) }, _last{ std::forward(last) } + { + } + + RangeDataset(RangeDataset &&) = default; + + /** Type of the dataset. */ + using type = std::tuple::value_type>; + + /** Iterator for the dataset. */ + struct iterator + { + iterator(std::string name, T iterator) + : _name{ name }, _iterator{ iterator } + { + } + + std::string description() const + { + using support::cpp11::to_string; + return _name + "=" + to_string(*_iterator); + } + + RangeDataset::type operator*() const + { + return std::make_tuple(*_iterator); + } + + iterator &operator++() + { + ++_iterator; + return *this; + } + + private: + std::string _name; + T _iterator; + }; + + /** Iterator pointing at the begin of the dataset. + * + * @return Iterator for the dataset. + */ + iterator begin() const + { + return iterator(name(), _first); + } + + /** Size of the dataset. + * + * @return Number of values in the dataset. + */ + int size() const + { + return std::distance(_first, _last); + } + +private: + T _first; + T _last; +}; + +/** Helper function to create a @ref RangeDataset. + * + * @param[in] name Name of the dataset. + * @param[in] first Iterator to the first value. + * @param[in] last Iterator behind the last value. + * + * @return A range dataset. + */ +template +RangeDataset make(std::string name, T &&first, T &&last) +{ + return RangeDataset(std::move(name), std::forward(first), std::forward(last)); +} +} // namespace dataset +} // namespace framework +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_DATASET_RANGE */ diff --git a/framework/datasets/SingletonDataset.h b/framework/datasets/SingletonDataset.h new file mode 100644 index 0000000000..4b71631d92 --- /dev/null +++ b/framework/datasets/SingletonDataset.h @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2017 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_DATASET_SINGLETON +#define ARM_COMPUTE_TEST_DATASET_SINGLETON + +#include "ContainerDataset.h" +#include "Dataset.h" +#include "support/ToolchainSupport.h" + +#include +#include +#include +#include + +namespace arm_compute +{ +namespace test +{ +namespace framework +{ +namespace dataset +{ +/** Implementation of a dataset holding a single value. */ +template +class SingletonDataset final : public NamedDataset +{ +public: + /** Construct dataset with given name and value. + * + * @param[in] name Description of the value. + * @param[in] value Value for the dataset. + */ + SingletonDataset(std::string name, T &&value) + : NamedDataset{ std::move(name) }, _value{ std::forward(value) } + { + } + + SingletonDataset(SingletonDataset &&) = default; + + /** Type of the dataset. */ + using type = std::tuple; + + /** Iterator for the dataset. */ + struct iterator + { + iterator(std::string name, const T *value) + : _name{ name }, _value{ value } + { + } + + ~iterator() = default; + + iterator(const iterator &) = default; + iterator &operator=(const iterator &) = default; + iterator(iterator &&) = default; + iterator &operator=(iterator &&) = default; + + std::string description() const + { + using support::cpp11::to_string; + return _name + "=" + to_string(*_value); + } + + SingletonDataset::type operator*() const + { + return std::make_tuple(*_value); + } + + iterator &operator++() + { + return *this; + } + + private: + std::string _name; + const T *_value; + }; + + /** Iterator pointing at the begin of the dataset. + * + * @return Iterator for the dataset. + */ + iterator begin() const + { + return iterator(name(), &_value); + } + + /** Size of the dataset. + * + * @return Number of values in the dataset. + */ + int size() const + { + return 1; + } + +private: + T _value; +}; + +/** Helper function to create a @ref SingletonDataset. + * + * @param[in] name Name of the dataset. + * @param[in] value Value. + * + * @return A singleton dataset. + */ +template +typename std::enable_if < !is_container::value, SingletonDataset>::type make(std::string name, T &&value) +{ + return SingletonDataset(std::move(name), std::forward(value)); +} +} // namespace dataset +} // namespace framework +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_DATASET_SINGLETON */ diff --git a/framework/datasets/ZipDataset.h b/framework/datasets/ZipDataset.h new file mode 100644 index 0000000000..b95b7209a7 --- /dev/null +++ b/framework/datasets/ZipDataset.h @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2017 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_DATASET_ZIP +#define ARM_COMPUTE_TEST_DATASET_ZIP + +#include "Dataset.h" + +#include +#include +#include + +namespace arm_compute +{ +namespace test +{ +namespace framework +{ +namespace dataset +{ +/** Implementation of a dataset representing pairs of values of the input datasets. + * + * For example, for the inputs {1, 2} and {3, 4} this dataset virtually + * represents the values {(1, 3), (1, 4)}. + */ +template +class ZipDataset : public Dataset +{ +private: + using iter1_type = typename T::iterator; + using iter2_type = typename U::iterator; + +public: + /** Construct dataset from the given datasets. + * + * @param[in] dataset1 First dataset. + * @param[in] dataset2 Second dataset. + */ + ZipDataset(T &&dataset1, U &&dataset2) + : _dataset1{ std::forward(dataset1) }, + _dataset2{ std::forward(dataset2) } + { + } + + ZipDataset(ZipDataset &&) = default; + + /** Type of the dataset. */ + using type = decltype(std::tuple_cat(*std::declval(), *std::declval())); + + /** Iterator for the dataset. */ + struct iterator + { + iterator(iter1_type iter1, iter2_type iter2) + : _iter1{ std::move(iter1) }, _iter2{ std::move(iter2) } + { + } + + std::string description() const + { + return _iter1.description() + ":" + _iter2.description(); + } + + ZipDataset::type operator*() const + { + return std::tuple_cat(*_iter1, *_iter2); + } + + iterator &operator++() + { + ++_iter1; + ++_iter2; + return *this; + } + + private: + iter1_type _iter1; + iter2_type _iter2; + }; + + /** Iterator pointing at the begin of the dataset. + * + * @return Iterator for the dataset. + */ + iterator begin() const + { + return iterator(_dataset1.begin(), _dataset2.begin()); + } + + /** Size of the dataset. + * + * @return Number of values in the dataset. + */ + int size() const + { + return std::min(_dataset1.size(), _dataset2.size()); + } + +private: + T _dataset1; + U _dataset2; +}; + +/** Helper function to create a @ref ZipDataset. + * + * @param[in] dataset1 First dataset. + * @param[in] dataset2 Second dataset. + * + * @return A zip dataset. + */ +template +ZipDataset zip(T &&dataset1, U &&dataset2) +{ + return ZipDataset(std::forward(dataset1), std::forward(dataset2)); +} +} // namespace dataset +} // namespace framework +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_DATASET_ZIP */ -- cgit v1.2.1