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_MATRIX_INDEX_ITERATOR_H__
24#define __NNFW_MISC_MATRIX_INDEX_ITERATOR_H__
25
26#include "misc/matrix/Shape.h"
27
28namespace nnfw
29{
30namespace misc
31{
32namespace matrix
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 (uint32_t row = 0; row < _shape.H; ++row)
59 {
60 for (uint32_t col = 0; col < _shape.W; ++col)
61 {
62 cb(row, col);
63 }
64 }
65
66 return (*this);
67 }
68
69private:
73 const Shape _shape;
74};
75
81inline IndexIterator iterate(const Shape &shape) { return IndexIterator{shape}; }
82
90template <typename Callable> IndexIterator &operator<<(IndexIterator &&it, Callable cb)
91{
92 return it.iter(cb);
93}
94
95} // namespace matrix
96} // namespace misc
97} // namespace nnfw
98
99#endif // __NNFW_MISC_MATRIX_INDEX_ITERATOR_H__
Class to iterate Callable with Index of matrix.
IndexIterator(const Shape &shape)
Construct IndexIterator object with Shape of matrix.
IndexIterator & iter(Callable cb)
Call a function iterated.
IndexIterator & operator<<(IndexIterator &&it, Callable cb)
Call a function iterated using IndexIterator of matrix Overloaded operator<<.
IndexIterator iterate(const Shape &shape)
Create an object of IndexIterator for matrix.
Definition topk_v2.h:30
This file contains Shape class for matrix.
Structure to have values of dimensions for matrix.
Definition Shape.h:39