ONE - On-device Neural Engine
Loading...
Searching...
No Matches
IndexEnumerator.cpp
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
18
19#include <cassert>
20#include <algorithm>
21
22namespace nncc
23{
24namespace core
25{
26namespace ADT
27{
28namespace kernel
29{
30
31IndexEnumerator::IndexEnumerator(const Shape &shape) : _cursor(0)
32{
33 _max[0] = shape.width();
34 _max[1] = shape.height();
35 _max[2] = shape.depth();
36 _max[3] = shape.count();
37
38 std::fill(_cur, _cur + 4, 0);
39
40 // NOTE Null dimension should NOT exist
41 assert(std::find(_max, _max + 4, 0) == (_max + 4));
42}
43
44bool IndexEnumerator::valid(void) const { return _cursor < 4; }
45
46uint32_t IndexEnumerator::count(void) const { return _cur[3]; }
47uint32_t IndexEnumerator::depth(void) const { return _cur[2]; }
48uint32_t IndexEnumerator::height(void) const { return _cur[1]; }
49uint32_t IndexEnumerator::width(void) const { return _cur[0]; }
50
52{
53 while (_cursor < 4)
54 {
55 if (_cur[_cursor] + 1 < _max[_cursor])
56 {
57 break;
58 }
59
60 ++_cursor;
61 }
62
63 if (_cursor == 4)
64 {
65 return;
66 }
67
68 // Increment index
69 _cur[_cursor] += 1;
70
71 // Reset indices for lower dimensions
72 for (uint32_t head = 0; head < _cursor; ++head)
73 {
74 _cur[head] = 0;
75 }
76
77 // Reset cursor
78 _cursor = 0;
79}
80
81} // namespace kernel
82} // namespace ADT
83} // namespace core
84} // namespace nncc
uint32_t width(void) const
Definition Shape.h:47
uint32_t height(void) const
Definition Shape.h:46
uint32_t count(void) const
Definition Shape.h:44
uint32_t depth(void) const
Definition Shape.h:45
void head(int indent)