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_TENSOR_INDEX_ITERATOR_H__
24#define __NNFW_MISC_TENSOR_INDEX_ITERATOR_H__
25
26#include "misc/tensor/Shape.h"
27#include "misc/tensor/Index.h"
29
30namespace nnfw
31{
32namespace misc
33{
34namespace tensor
35{
36
41{
42public:
47 IndexIterator(const Shape &shape) : _shape(shape)
48 {
49 // DO NOTHING
50 }
51
52public:
58
62 IndexIterator(const IndexIterator &) = delete;
63
64public:
70 template <typename Callable> IndexIterator &iter(Callable fn)
71 {
72 for (IndexEnumerator e{_shape}; e.valid(); e.advance())
73 {
74 fn(e.curr());
75 }
76
77 return (*this);
78 }
79
80private:
81 const Shape &_shape;
82};
83
89inline IndexIterator iterate(const Shape &shape) { return IndexIterator{shape}; }
90
98template <typename Callable> IndexIterator &operator<<(IndexIterator &&it, Callable cb)
99{
100 return it.iter(cb);
101}
102
103} // namespace tensor
104} // namespace misc
105} // namespace nnfw
106
107#endif // __NNFW_MISC_TENSOR_INDEX_ITERATOR_H__
Class to enumerate index of a tensor.
Class to iterate indexes available for given shape.
IndexIterator(const Shape &shape)
Construct a new IndexIterator object.
IndexIterator(IndexIterator &&)=default
Construct a new IndexIterator object using reference.
IndexIterator(const IndexIterator &)=delete
Prevent copy constructor.
IndexIterator & iter(Callable fn)
Iterate all available indexes and run a function for each index.
Class to represent shape of a tensor.
Definition Shape.h:45
IndexIterator iterate(const Shape &shape)
Get an IndexItator object.
std::ostream & operator<<(std::ostream &os, const IndexFormatter &fmt)
Send IndexFormatter object to output stream.
Definition topk_v2.h:30
This file contains nnfw::misc::tensor::Index struct.
This file contains nnfw::misc::tensor::IndexEnumerator class.
This file contains nnfw::misc::tensor::Shape class.