SiCong Li | 1e5c157 | 2017-07-27 17:58:52 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017 Arm Limited. |
SiCong Li | 1e5c157 | 2017-07-27 17:58:52 +0100 | [diff] [blame] | 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_BATCHNORMALIZATION_LAYER_DATASET |
| 25 | #define ARM_COMPUTE_TEST_BATCHNORMALIZATION_LAYER_DATASET |
| 26 | |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 27 | #include "utils/TypePrinter.h" |
SiCong Li | 1e5c157 | 2017-07-27 17:58:52 +0100 | [diff] [blame] | 28 | |
| 29 | #include "arm_compute/core/TensorShape.h" |
| 30 | #include "arm_compute/core/Types.h" |
| 31 | |
| 32 | namespace arm_compute |
| 33 | { |
| 34 | namespace test |
| 35 | { |
| 36 | namespace datasets |
| 37 | { |
| 38 | class BatchNormalizationLayerDataset |
| 39 | { |
| 40 | public: |
| 41 | using type = std::tuple<TensorShape, TensorShape, float>; |
| 42 | |
| 43 | struct iterator |
| 44 | { |
| 45 | iterator(std::vector<TensorShape>::const_iterator tensor_it, |
| 46 | std::vector<TensorShape>::const_iterator param_it, |
| 47 | std::vector<float>::const_iterator epsilon_it) |
| 48 | : _tensor_it{ std::move(tensor_it) }, |
| 49 | _param_it{ std::move(param_it) }, |
| 50 | _epsilon_it{ std::move(epsilon_it) } |
| 51 | { |
| 52 | } |
| 53 | |
| 54 | std::string description() const |
| 55 | { |
| 56 | std::stringstream description; |
| 57 | description << "In=" << *_tensor_it << ":"; |
| 58 | description << "Out=" << *_tensor_it << ":"; |
| 59 | description << "Mean=" << *_param_it << ":"; |
| 60 | description << "Variance=" << *_param_it << ":"; |
| 61 | description << "Beta=" << *_param_it << ":"; |
| 62 | description << "Gamma=" << *_param_it << ":"; |
| 63 | description << "Epsilon=" << *_epsilon_it; |
| 64 | return description.str(); |
| 65 | } |
| 66 | |
| 67 | BatchNormalizationLayerDataset::type operator*() const |
| 68 | { |
| 69 | return std::make_tuple(*_tensor_it, *_param_it, *_epsilon_it); |
| 70 | } |
| 71 | |
| 72 | iterator &operator++() |
| 73 | { |
| 74 | ++_tensor_it; |
| 75 | ++_param_it; |
| 76 | ++_epsilon_it; |
| 77 | |
| 78 | return *this; |
| 79 | } |
| 80 | |
| 81 | private: |
| 82 | std::vector<TensorShape>::const_iterator _tensor_it; |
| 83 | std::vector<TensorShape>::const_iterator _param_it; |
| 84 | std::vector<float>::const_iterator _epsilon_it; |
| 85 | }; |
| 86 | |
| 87 | iterator begin() const |
| 88 | { |
| 89 | return iterator(_tensor_shapes.begin(), _param_shapes.begin(), _epsilons.begin()); |
| 90 | } |
| 91 | |
| 92 | int size() const |
| 93 | { |
| 94 | return std::min(_tensor_shapes.size(), std::min(_param_shapes.size(), _epsilons.size())); |
| 95 | } |
| 96 | |
| 97 | void add_config(TensorShape tensor, TensorShape param, float epsilon) |
| 98 | { |
| 99 | _tensor_shapes.emplace_back(std::move(tensor)); |
| 100 | _param_shapes.emplace_back(std::move(param)); |
| 101 | _epsilons.emplace_back(std::move(epsilon)); |
| 102 | } |
| 103 | |
| 104 | protected: |
| 105 | BatchNormalizationLayerDataset() = default; |
| 106 | BatchNormalizationLayerDataset(BatchNormalizationLayerDataset &&) = default; |
| 107 | |
| 108 | private: |
| 109 | std::vector<TensorShape> _tensor_shapes{}; |
| 110 | std::vector<TensorShape> _param_shapes{}; |
| 111 | std::vector<float> _epsilons{}; |
| 112 | }; |
| 113 | } // namespace datasets |
| 114 | } // namespace test |
| 115 | } // namespace arm_compute |
| 116 | #endif /* ARM_COMPUTE_TEST_BATCHNORMALIZATION_LAYER_DATASET */ |