ONE - On-device Neural Engine
Loading...
Searching...
No Matches
nnfw::misc::tensor::IndexEnumerator Class Reference

Class to enumerate index of a tensor. More...

#include <IndexEnumerator.h>

Collaboration diagram for nnfw::misc::tensor::IndexEnumerator:

Public Member Functions

 IndexEnumerator (const Shape &shape)
 Construct a new IndexEnumerator object.
 
 IndexEnumerator (IndexEnumerator &&)=delete
 Prevent constructing IndexEnumerator object by using R-value reference.
 
 IndexEnumerator (const IndexEnumerator &)=delete
 Prevent copy constructor.
 
bool valid (void) const
 Check if more enumeration is available.
 
const Indexcurr (void) const
 Get the current index to enumerate.
 
void advance (void)
 Advance index by +1.
 

Data Fields

const Shape _shape
 Shape to enumerate.
 

Detailed Description

Class to enumerate index of a tensor.

Definition at line 39 of file IndexEnumerator.h.

Constructor & Destructor Documentation

◆ IndexEnumerator() [1/3]

nnfw::misc::tensor::IndexEnumerator::IndexEnumerator ( const Shape shape)
inlineexplicit

Construct a new IndexEnumerator object.

Parameters
[in]shapeShape of tensor of which index will be enumerate

Definition at line 46 of file IndexEnumerator.h.

46 : _shape(shape), _cursor(0), _index(shape.rank())
47 {
48 const uint32_t rank = _shape.rank();
49
50 for (uint32_t axis = 0; axis < rank; ++axis)
51 {
52 _index.at(axis) = 0;
53 }
54
55 for (_cursor = 0; _cursor < rank; ++_cursor)
56 {
57 if (_index.at(_cursor) < _shape.dim(_cursor))
58 {
59 break;
60 }
61 }
62 }
const Shape _shape
Shape to enumerate.
int32_t dim(uint32_t n) const
Get specific dimension.
Definition Shape.h:100
uint32_t rank(void) const
Get the rank of this shape.
Definition Shape.h:92
int32_t at(uint32_t n) const
Get the index n'th dimension.
Definition Index.h:75

References _shape, nnfw::misc::tensor::Index::at(), nnfw::misc::tensor::Shape::dim(), and nnfw::misc::tensor::Shape::rank().

◆ IndexEnumerator() [2/3]

nnfw::misc::tensor::IndexEnumerator::IndexEnumerator ( IndexEnumerator &&  )
delete

Prevent constructing IndexEnumerator object by using R-value reference.

◆ IndexEnumerator() [3/3]

nnfw::misc::tensor::IndexEnumerator::IndexEnumerator ( const IndexEnumerator )
delete

Prevent copy constructor.

Member Function Documentation

◆ advance()

void nnfw::misc::tensor::IndexEnumerator::advance ( void  )
inline

Advance index by +1.

Definition at line 92 of file IndexEnumerator.h.

93 {
94 const uint32_t rank = _shape.rank();
95
96 // Find axis to be updated
97 while ((_cursor < rank) && !(_index.at(_cursor) + 1 < _shape.dim(_cursor)))
98 {
99 ++_cursor;
100 }
101
102 if (_cursor == rank)
103 {
104 return;
105 }
106
107 // Update index
108 _index.at(_cursor) += 1;
109
110 for (uint32_t axis = 0; axis < _cursor; ++axis)
111 {
112 _index.at(axis) = 0;
113 }
114
115 // Update cursor
116 _cursor = 0;
117 }

References _shape, nnfw::misc::tensor::Index::at(), nnfw::misc::tensor::Shape::dim(), and nnfw::misc::tensor::Shape::rank().

◆ curr()

const Index & nnfw::misc::tensor::IndexEnumerator::curr ( void  ) const
inline

Get the current index to enumerate.

Returns
Current index

Definition at line 86 of file IndexEnumerator.h.

86{ return _index; }

◆ valid()

bool nnfw::misc::tensor::IndexEnumerator::valid ( void  ) const
inline

Check if more enumeration is available.

Returns
true if more advance() is available, otherwise false

Definition at line 79 of file IndexEnumerator.h.

79{ return _cursor < _shape.rank(); }

References _shape, and nnfw::misc::tensor::Shape::rank().

Field Documentation

◆ _shape

const Shape nnfw::misc::tensor::IndexEnumerator::_shape

Shape to enumerate.

Definition at line 120 of file IndexEnumerator.h.

Referenced by advance(), IndexEnumerator(), and valid().


The documentation for this class was generated from the following file: