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_KERNEL_INDEX_ITERATOR_H__
24#define __NNFW_MISC_KERNEL_INDEX_ITERATOR_H__
25
26#include "misc/kernel/Shape.h"
27
28namespace nnfw
29{
30namespace misc
31{
32namespace kernel
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 nth = 0; nth < _shape.N; ++nth)
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(nth, ch, row, col);
67 }
68 }
69 }
70 }
71
72 return (*this);
73 }
74
75private:
76 const Shape _shape;
77};
78
84inline IndexIterator iterate(const Shape &shape) { return IndexIterator{shape}; }
85
93template <typename Callable> IndexIterator &operator<<(IndexIterator &&it, Callable cb)
94{
95 return it.iter(cb);
96}
97
98} // namespace kernel
99} // namespace misc
100} // namespace nnfw
101
102#endif // __NNFW_MISC_FEATURE_INDEX_ITERATOR_H__
Class to iterate Callable with Index of kernel.
IndexIterator & iter(Callable cb)
Call a function iterated.
IndexIterator(const Shape &shape)
Construct IndexIterator object with Shape of kernel.
IndexIterator iterate(const Shape &shape)
Create an object of IndexIterator for kernel.
IndexIterator & operator<<(IndexIterator &&it, Callable cb)
Call a function iterated using IndexIterator of kernel Overloaded operator<<.
Definition topk_v2.h:30
This file contains Shape structure.
Structure to Shape.
Definition Shape.h:39