ONE - On-device Neural Engine
Loading...
Searching...
No Matches
IndexIterator.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
23#ifndef __NNFW_MISC_FEATURE_INDEX_ITERATOR_H__
24#define __NNFW_MISC_FEATURE_INDEX_ITERATOR_H__
25
26#include "misc/feature/Shape.h"
27
28namespace nnfw
29{
30namespace misc
31{
32namespace feature
33{
34
39{
40public:
45 IndexIterator(const Shape &shape) : _shape{shape}
46 {
47 // DO NOTHING
48 }
49
50public:
56 template <typename Callable> IndexIterator &iter(Callable cb)
57 {
58 for (int32_t batch = 0; batch < _shape.N; ++batch)
59 {
60 for (int32_t ch = 0; ch < _shape.C; ++ch)
61 {
62 for (int32_t row = 0; row < _shape.H; ++row)
63 {
64 for (int32_t col = 0; col < _shape.W; ++col)
65 {
66 cb(batch, ch, row, col);
67 }
68 }
69 }
70 }
71
72 return (*this);
73 }
74
75private:
79 const Shape _shape;
80};
81
87static inline IndexIterator iterate(const Shape &shape) { return IndexIterator{shape}; }
88
96template <typename Callable> IndexIterator &operator<<(IndexIterator &&it, Callable cb)
97{
98 return it.iter(cb);
99}
100
101} // namespace feature
102} // namespace misc
103} // namespace nnfw
104
105#endif // __NNFW_MISC_FEATURE_INDEX_ITERATOR_H__
Class to iterate Callable with Index of feature.
IndexIterator(const Shape &shape)
Construct IndexIterator object with Shape of feature.
IndexIterator & iter(Callable cb)
Call a function iterated.
IndexIterator & operator<<(IndexIterator &&it, Callable cb)
Call a function iterated using IndexIterator of feature Overloaded operator<<.
Definition topk_v2.h:30
This file contains Shape class for feature.
Definition Shape.h:28
Structure to have values of dimensions for feature.
Definition Shape.h:39