diff options
Diffstat (limited to 'libs/util/include/util/feature/IndexIterator.h')
-rw-r--r-- | libs/util/include/util/feature/IndexIterator.h | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/libs/util/include/util/feature/IndexIterator.h b/libs/util/include/util/feature/IndexIterator.h new file mode 100644 index 000000000..dd029f4b6 --- /dev/null +++ b/libs/util/include/util/feature/IndexIterator.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __NNFW_UTIL_FEATURE_INDEX_ITERATOR_H__ +#define __NNFW_UTIL_FEATURE_INDEX_ITERATOR_H__ + +#include "util/feature/Shape.h" + +namespace nnfw +{ +namespace util +{ +namespace feature +{ + +class IndexIterator +{ +public: + IndexIterator(const Shape &shape) : _shape{shape} + { + // DO NOTHING + } + +public: + template <typename Callable> IndexIterator &iter(Callable cb) + { + for (uint32_t ch = 0; ch < _shape.C; ++ch) + { + for (uint32_t row = 0; row < _shape.H; ++row) + { + for (uint32_t col = 0; col < _shape.W; ++col) + { + cb(ch, row, col); + } + } + } + + return (*this); + } + +private: + const Shape _shape; +}; + +IndexIterator iterate(const Shape &shape) { return IndexIterator{shape}; } + +template <typename Callable> IndexIterator &operator<<(IndexIterator &&it, Callable cb) +{ + return it.iter(cb); +} + +} // namespace feature +} // namespace util +} // namespace nnfw + +#endif // __NNFW_UTIL_FEATURE_INDEX_ITERATOR_H__ |