ONE - On-device Neural Engine
Loading...
Searching...
No Matches
nnfw::ruy::Shape Class Reference

#include <Shape.h>

Collaboration diagram for nnfw::ruy::Shape:

Public Member Functions

Shapeoperator= (Shape const &)=delete
 
 Shape ()
 
 Shape (int dimensions_count)
 
 Shape (int shape_size, int32_t value)
 
 Shape (int dimensions_count, const int32_t *dims_data)
 
 Shape (const std::initializer_list< int > init_list)
 
 Shape (Shape const &other)
 
bool operator== (const Shape &comp) const
 
 ~Shape ()
 
int32_t DimensionsCount () const
 
int32_t Dims (int i) const
 
void SetDim (int i, int32_t val)
 
int32_t * DimsData ()
 
const int32_t * DimsData () const
 
const int32_t * DimsDataUpTo4D () const
 
void Resize (int dimensions_count)
 
void ReplaceWith (int dimensions_count, const int32_t *dims_data)
 
void ReplaceWith (const Shape &other)
 
void ReplaceWith (Shape &&other)
 
template<typename T >
void BuildFrom (const T &src_iterable)
 
void BuildFrom (const std::initializer_list< int > init_list)
 
int FlatSize () const
 
bool operator!= (const Shape &comp) const
 

Static Public Member Functions

static Shape ExtendedShape (int new_shape_size, const Shape &shape)
 

Static Public Attributes

static constexpr int kMaxSmallSize = 5
 

Detailed Description

Definition at line 31 of file Shape.h.

Constructor & Destructor Documentation

◆ Shape() [1/6]

nnfw::ruy::Shape::Shape ( )
inline

Definition at line 40 of file Shape.h.

40: _size(0) {}

Referenced by ExtendedShape().

◆ Shape() [2/6]

nnfw::ruy::Shape::Shape ( int  dimensions_count)
inlineexplicit

Definition at line 42 of file Shape.h.

42 : _size(dimensions_count)
43 {
44 if (dimensions_count > kMaxSmallSize)
45 {
46 _dims_pointer = new int32_t[dimensions_count];
47 }
48 }
int32_t * _dims_pointer
Definition Shape.h:217
static constexpr int kMaxSmallSize
Definition Shape.h:36

References _dims_pointer, and kMaxSmallSize.

◆ Shape() [3/6]

nnfw::ruy::Shape::Shape ( int  shape_size,
int32_t  value 
)
inline

Definition at line 50 of file Shape.h.

50 : _size(0)
51 {
52 Resize(shape_size);
53 for (int i = 0; i < shape_size; ++i)
54 {
55 SetDim(i, value);
56 }
57 }
void Resize(int dimensions_count)
Definition Shape.h:117
void SetDim(int i, int32_t val)
Definition Shape.h:98

References Resize(), and SetDim().

◆ Shape() [4/6]

nnfw::ruy::Shape::Shape ( int  dimensions_count,
const int32_t *  dims_data 
)
inline

Definition at line 59 of file Shape.h.

59 : _size(0)
60 {
61 ReplaceWith(dimensions_count, dims_data);
62 }
void ReplaceWith(int dimensions_count, const int32_t *dims_data)
Definition Shape.h:130

References ReplaceWith().

◆ Shape() [5/6]

nnfw::ruy::Shape::Shape ( const std::initializer_list< int >  init_list)
inline

Definition at line 64 of file Shape.h.

64: _size(0) { BuildFrom(init_list); }
void BuildFrom(const T &src_iterable)
Definition Shape.h:152

References BuildFrom().

◆ Shape() [6/6]

nnfw::ruy::Shape::Shape ( Shape const &  other)
inline

Definition at line 68 of file Shape.h.

68 : _size(other.DimensionsCount())
69 {
70 if (_size > kMaxSmallSize)
71 {
72 _dims_pointer = new int32_t[_size];
73 }
74 std::memcpy(DimsData(), other.DimsData(), sizeof(int32_t) * _size);
75 }
int32_t * DimsData()
Definition Shape.h:112

References _dims_pointer, DimsData(), and kMaxSmallSize.

◆ ~Shape()

nnfw::ruy::Shape::~Shape ( )
inline

Definition at line 83 of file Shape.h.

84 {
85 if (_size > kMaxSmallSize)
86 {
87 delete[] _dims_pointer;
88 }
89 }

References _dims_pointer, and kMaxSmallSize.

Member Function Documentation

◆ BuildFrom() [1/2]

void nnfw::ruy::Shape::BuildFrom ( const std::initializer_list< int >  init_list)
inline

Definition at line 174 of file Shape.h.

175 {
176 BuildFrom<const std::initializer_list<int>>(init_list);
177 }

◆ BuildFrom() [2/2]

template<typename T >
void nnfw::ruy::Shape::BuildFrom ( const T &  src_iterable)
inline

Definition at line 152 of file Shape.h.

153 {
154 const int dimensions_count = std::distance(src_iterable.begin(), src_iterable.end());
155 Resize(dimensions_count);
156 int32_t *data = DimsData();
157 for (auto &&it : src_iterable)
158 {
159 *data = it;
160 ++data;
161 }
162 }

References DimsData(), and Resize().

Referenced by Shape().

◆ DimensionsCount()

◆ Dims()

int32_t nnfw::ruy::Shape::Dims ( int  i) const
inline

◆ DimsData() [1/2]

int32_t * nnfw::ruy::Shape::DimsData ( )
inline

◆ DimsData() [2/2]

const int32_t * nnfw::ruy::Shape::DimsData ( ) const
inline

Definition at line 113 of file Shape.h.

113{ return _size > kMaxSmallSize ? _dims_pointer : _dims; }

References _dims, _dims_pointer, and kMaxSmallSize.

◆ DimsDataUpTo4D()

const int32_t * nnfw::ruy::Shape::DimsDataUpTo4D ( ) const
inline

Definition at line 115 of file Shape.h.

115{ return _dims; }

References _dims.

Referenced by nnfw::ruy::Offset().

◆ ExtendedShape()

static Shape nnfw::ruy::Shape::ExtendedShape ( int  new_shape_size,
const Shape shape 
)
inlinestatic

Definition at line 169 of file Shape.h.

170 {
171 return Shape(new_shape_size, shape, 1);
172 }

References Shape().

◆ FlatSize()

int nnfw::ruy::Shape::FlatSize ( ) const
inline

Definition at line 181 of file Shape.h.

182 {
183 int buffer_size = 1;
184 const int *dims_data = DimsData();
185 for (int i = 0; i < _size; i++)
186 {
187 const int dim = dims_data[i];
188 assert(dim >= 1);
189 buffer_size *= dim;
190 }
191 return buffer_size;
192 }

References DimsData().

Referenced by nnfw::ruy::checkMatching(), nnfw::ruy::FullyConnected(), nnfw::ruy::MatchingElementsSize(), nnfw::ruy::MatchingFlatSize(), nnfw::ruy::Conv::operator()(), and onert::backend::ruy::ops::FullyConnectedLayer::prepare().

◆ operator!=()

bool nnfw::ruy::Shape::operator!= ( const Shape comp) const
inline

Definition at line 194 of file Shape.h.

194{ return !((*this) == comp); }

◆ operator=()

Shape & nnfw::ruy::Shape::operator= ( Shape const &  )
delete

◆ operator==()

bool nnfw::ruy::Shape::operator== ( const Shape comp) const
inline

Definition at line 77 of file Shape.h.

78 {
79 return this->_size == comp._size &&
80 std::memcmp(DimsData(), comp.DimsData(), _size * sizeof(int32_t)) == 0;
81 }

References DimsData().

◆ ReplaceWith() [1/3]

void nnfw::ruy::Shape::ReplaceWith ( const Shape other)
inline

Definition at line 137 of file Shape.h.

138 {
139 ReplaceWith(other.DimensionsCount(), other.DimsData());
140 }

References DimensionsCount(), DimsData(), and ReplaceWith().

◆ ReplaceWith() [2/3]

void nnfw::ruy::Shape::ReplaceWith ( int  dimensions_count,
const int32_t *  dims_data 
)
inline

Definition at line 130 of file Shape.h.

131 {
132 Resize(dimensions_count);
133 int32_t *dst_dims = DimsData();
134 std::memcpy(dst_dims, dims_data, dimensions_count * sizeof(int32_t));
135 }

References DimsData(), and Resize().

Referenced by ReplaceWith(), and Shape().

◆ ReplaceWith() [3/3]

void nnfw::ruy::Shape::ReplaceWith ( Shape &&  other)
inline

Definition at line 142 of file Shape.h.

143 {
144 Resize(0);
145 std::swap(_size, other._size);
146 if (_size <= kMaxSmallSize)
147 std::copy(other._dims, other._dims + kMaxSmallSize, _dims);
148 else
149 _dims_pointer = other._dims_pointer;
150 }

References _dims, _dims_pointer, kMaxSmallSize, and Resize().

◆ Resize()

void nnfw::ruy::Shape::Resize ( int  dimensions_count)
inline

Definition at line 117 of file Shape.h.

118 {
119 if (_size > kMaxSmallSize)
120 {
121 delete[] _dims_pointer;
122 }
123 _size = dimensions_count;
124 if (dimensions_count > kMaxSmallSize)
125 {
126 _dims_pointer = new int32_t[dimensions_count];
127 }
128 }

References _dims_pointer, and kMaxSmallSize.

Referenced by BuildFrom(), ReplaceWith(), ReplaceWith(), and Shape().

◆ SetDim()

void nnfw::ruy::Shape::SetDim ( int  i,
int32_t  val 
)
inline

Definition at line 98 of file Shape.h.

99 {
100 assert(i >= 0);
101 assert(i < _size);
102 if (_size > kMaxSmallSize)
103 {
104 _dims_pointer[i] = val;
105 }
106 else
107 {
108 _dims[i] = val;
109 }
110 }

References _dims, _dims_pointer, and kMaxSmallSize.

Referenced by Shape().

Field Documentation

◆ _dims

int32_t nnfw::ruy::Shape::_dims[kMaxSmallSize]

Definition at line 216 of file Shape.h.

Referenced by Dims(), DimsData(), DimsData(), DimsDataUpTo4D(), ReplaceWith(), and SetDim().

◆ _dims_pointer

int32_t* nnfw::ruy::Shape::_dims_pointer {nullptr}

Definition at line 217 of file Shape.h.

217{nullptr};

Referenced by Dims(), DimsData(), DimsData(), ReplaceWith(), Resize(), SetDim(), Shape(), Shape(), and ~Shape().

◆ kMaxSmallSize

constexpr int nnfw::ruy::Shape::kMaxSmallSize = 5
staticconstexpr

Definition at line 36 of file Shape.h.

Referenced by Dims(), DimsData(), DimsData(), ReplaceWith(), Resize(), SetDim(), Shape(), Shape(), and ~Shape().


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