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
17
#include "
nncc/core/ADT/kernel/IndexEnumerator.h
"
18
19
#include <cassert>
20
#include <algorithm>
21
22
namespace
nncc
23
{
24
namespace
core
25
{
26
namespace
ADT
27
{
28
namespace
kernel
29
{
30
31
IndexEnumerator::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
44
bool
IndexEnumerator::valid
(
void
)
const
{
return
_cursor < 4; }
45
46
uint32_t
IndexEnumerator::count
(
void
)
const
{
return
_cur[3]; }
47
uint32_t
IndexEnumerator::depth
(
void
)
const
{
return
_cur[2]; }
48
uint32_t
IndexEnumerator::height
(
void
)
const
{
return
_cur[1]; }
49
uint32_t
IndexEnumerator::width
(
void
)
const
{
return
_cur[0]; }
50
51
void
IndexEnumerator::advance
(
void
)
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
nncc::core::ADT::kernel::IndexEnumerator::count
uint32_t count(void) const
Definition
IndexEnumerator.cpp:46
nncc::core::ADT::kernel::IndexEnumerator::height
uint32_t height(void) const
Definition
IndexEnumerator.cpp:48
nncc::core::ADT::kernel::IndexEnumerator::valid
bool valid(void) const
Definition
IndexEnumerator.cpp:44
nncc::core::ADT::kernel::IndexEnumerator::IndexEnumerator
IndexEnumerator(const Shape &shape)
Definition
IndexEnumerator.cpp:31
nncc::core::ADT::kernel::IndexEnumerator::advance
void advance(void)
Definition
IndexEnumerator.cpp:51
nncc::core::ADT::kernel::IndexEnumerator::width
uint32_t width(void) const
Definition
IndexEnumerator.cpp:49
nncc::core::ADT::kernel::IndexEnumerator::depth
uint32_t depth(void) const
Definition
IndexEnumerator.cpp:47
nncc::core::ADT::kernel::Shape
Definition
Shape.h:35
nncc::core::ADT::kernel::Shape::width
uint32_t width(void) const
Definition
Shape.h:47
nncc::core::ADT::kernel::Shape::height
uint32_t height(void) const
Definition
Shape.h:46
nncc::core::ADT::kernel::Shape::count
uint32_t count(void) const
Definition
Shape.h:44
nncc::core::ADT::kernel::Shape::depth
uint32_t depth(void) const
Definition
Shape.h:45
IndexEnumerator.h
head
void head(int indent)
nncc
Definition
Accessor.h:23
compiler
angkor
src
ADT
kernel
IndexEnumerator.cpp
Generated by
1.9.8