ONE - On-device Neural Engine
Loading...
Searching...
No Matches
moco::TensorPackEnumerator Class Reference

#include <TensorPackEnumerator.h>

Public Member Functions

 TensorPackEnumerator ()=default
 
void shape (const loco::TensorShape &si, const loco::TensorShape &so)
 
void axis (uint32_t axis)
 
void start (void)
 
bool valid (void)
 
void advance (void)
 
uint32_t inp_num (void) const
 
uint32_t inp_element (void) const
 
uint32_t out_element (void) const
 

Detailed Description

Definition at line 29 of file TensorPackEnumerator.h.

Constructor & Destructor Documentation

◆ TensorPackEnumerator()

moco::TensorPackEnumerator::TensorPackEnumerator ( )
default

Member Function Documentation

◆ advance()

void moco::TensorPackEnumerator::advance ( void  )

Definition at line 88 of file TensorPackEnumerator.cpp.

89{
90 uint32_t r = _rank_out - 1;
91 increment(r);
92
93 // from _cursor_out, set _cursor_inp and _num
94 for (int32_t r = 0, s = 0; r < _rank_out; ++r)
95 {
96 if (r == _axis)
97 {
98 _num_inp = _cursor_out.at(r);
99 }
100 else
101 {
102 _cursor_inp.at(s) = _cursor_out.at(r);
103 s++;
104 }
105 }
106}

◆ axis()

void moco::TensorPackEnumerator::axis ( uint32_t  axis)
inline

Definition at line 36 of file TensorPackEnumerator.h.

36{ _axis = axis; }

References axis().

Referenced by axis().

◆ inp_element()

uint32_t moco::TensorPackEnumerator::inp_element ( void  ) const

Definition at line 110 of file TensorPackEnumerator.cpp.

111{
112 uint32_t rank = _rank_out - 1;
113 uint32_t element = 0;
114 for (uint32_t r = 0; r < rank; ++r)
115 {
116 uint32_t dim = _boundary_inp.at(r);
117 element = element * dim + _cursor_inp.at(r);
118 }
119 return element;
120}

◆ inp_num()

uint32_t moco::TensorPackEnumerator::inp_num ( void  ) const

Definition at line 108 of file TensorPackEnumerator.cpp.

108{ return _num_inp; }

◆ out_element()

uint32_t moco::TensorPackEnumerator::out_element ( void  ) const

Definition at line 122 of file TensorPackEnumerator.cpp.

123{
124 uint32_t rank = _rank_out;
125 uint32_t element = 0;
126 for (uint32_t r = 0; r < rank; ++r)
127 {
128 uint32_t dim = _boundary_out.at(r);
129 element = element * dim + _cursor_out.at(r);
130 }
131 return element;
132}

◆ shape()

void moco::TensorPackEnumerator::shape ( const loco::TensorShape si,
const loco::TensorShape so 
)

Definition at line 24 of file TensorPackEnumerator.cpp.

25{
26 _shape_inp = si;
27 _shape_out = so;
28
29 assert(_shape_inp.rank() + 1 == _shape_out.rank());
30
31 _rank_out = _shape_out.rank();
32}
uint32_t rank(void) const
Definition TensorShape.h:35

References loco::TensorShape::rank().

Referenced by RandomDataGenerator.RandomDataGenerator::_gen_float32(), RandomDataGenerator.RandomDataGenerator::_gen_int16(), and RandomDataGenerator.RandomDataGenerator::_gen_uint8().

◆ start()

void moco::TensorPackEnumerator::start ( void  )

Definition at line 52 of file TensorPackEnumerator.cpp.

53{
54 uint32_t rank = _rank_out;
55
56 _cursor_out.resize(rank);
57 _boundary_out.resize(rank);
58 for (uint32_t r = 0; r < rank; ++r)
59 {
60 _cursor_out.at(r) = 0;
61 _boundary_out.at(r) = _shape_out.dim(r).value();
62 }
63
64 rank = _rank_out - 1;
65 _cursor_inp.resize(rank);
66 _boundary_inp.resize(rank);
67 for (uint32_t r = 0; r < rank; ++r)
68 {
69 _cursor_inp.at(r) = 0;
70 _boundary_inp.at(r) = _shape_inp.dim(r).value();
71 }
72 _num_inp = 0;
73}
uint32_t value(void) const
Return the value.
Definition Dimension.h:51
const Dimension & dim(uint32_t axis) const
Definition TensorShape.h:38

References loco::TensorShape::dim(), and loco::Dimension::value().

◆ valid()

bool moco::TensorPackEnumerator::valid ( void  )

Definition at line 75 of file TensorPackEnumerator.cpp.

76{
77 uint32_t rank = _rank_out;
78 for (uint32_t r = 0; r < rank; ++r)
79 {
80 if (_cursor_out.at(r) >= _boundary_out.at(r))
81 {
82 return false;
83 }
84 }
85 return true;
86}

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