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

#include <Shape.h>

Collaboration diagram for nnfw::cker::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::cker::Shape::Shape ( )
inline

Definition at line 40 of file Shape.h.

40: _size(0) {}

Referenced by ExtendedShape().

◆ Shape() [2/6]

nnfw::cker::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 }
static constexpr int kMaxSmallSize
Definition Shape.h:36
int32_t * _dims_pointer
Definition Shape.h:216

References _dims_pointer, and kMaxSmallSize.

◆ Shape() [3/6]

nnfw::cker::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::cker::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::cker::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::cker::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::cker::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::cker::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::cker::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()

int32_t nnfw::cker::Shape::DimensionsCount ( ) const
inline

Definition at line 91 of file Shape.h.

91{ return _size; }

Referenced by nnfw::cker::train::Adam(), nnfw::cker::ArgMinMax(), nnfw::cker::AveragePool16(), nnfw::cker::train::AveragePool2DGrad(), nnfw::cker::AveragePool32(), nnfw::cker::AveragePool< float >(), nnfw::cker::AveragePool< int8_t >(), nnfw::cker::BatchToSpaceND(), nnfw::cker::bias_op::biasHelper(), nnfw::cker::functor::biasReductionHelper(), nnfw::cker::BroadcastComparison4DSlowImpl(), nnfw::cker::BroadcastComparison4DSlowWithScaling(), nnfw::cker::BroadcastSelect4DSlow(), nnfw::cker::BroadcastTo(), nnfw::cker::train::CategoricalCrossEntropyWithLogits(), nnfw::cker::checkMatching(), nnfw::cker::reference::Conv(), nnfw::cker::multithreaded::Conv(), nnfw::cker::reference::Conv(), nnfw::cker::reference::Conv(), nnfw::cker::optimized::Conv(), nnfw::cker::Tensor::copyFrom(), nnfw::cker::train::Depad(), nnfw::cker::DepthToSpace(), nnfw::cker::DepthwiseConv(), nnfw::cker::reference_integer_ops::DepthwiseConvHybridPerChannel(), nnfw::cker::optimized::DepthwiseConvImpl(), nnfw::cker::optimized_integer_ops::DepthwiseConvPerChannel(), nnfw::cker::reference_integer_ops::DepthwiseConvPerChannel(), nnfw::cker::optimized_integer_ops::DepthwiseConvWithRounding(), nnfw::cker::optimized::DepthwiseConvWithRounding(), nnfw::cker::optimized::DilatedIm2col(), nnfw::cker::optimized::ExtractPatchIntoBufferColumn(), nnfw::cker::FlatSizeSkipDim(), nnfw::cker::FloorDivBroadcast(), nnfw::cker::FloorModBroadcast(), nnfw::cker::BCast::FromShape(), nnfw::cker::FullyConnected(), nnfw::cker::train::FullyConnectedBiasGrad(), nnfw::cker::FullyConnectedSparseWeight16x1(), nnfw::cker::FullyConnectedSparseWeightRandom(), nnfw::cker::Gather(), nnfw::cker::train::GradientDescent(), nnfw::cker::reference::HybridConvPerChannel(), nnfw::cker::optimized::Im2col(), nnfw::cker::InitTensorDataForReduce(), nnfw::cker::L2NormalizeFloat32(), nnfw::cker::L2NormalizeQuant8(), nnfw::cker::LogicalAndBroadcast(), nnfw::cker::LogicalOrBroadcast(), nnfw::cker::LogSoftmax(), nnfw::cker::LogSoftmax(), nnfw::cker::MapAsMatrixWithLastDimAsRows(), nnfw::cker::MatchingFlatSizeSkipDim(), nnfw::cker::MatchingFlatSizeSkipDim(), nnfw::cker::MatMulBCast::MatMulBCast(), nnfw::cker::MatrixBandPart(), nnfw::cker::MaximumMinimumBroadcast4DSlow(), nnfw::cker::train::MaxPool2D(), nnfw::cker::train::MaxPool2DGrad(), nnfw::cker::MaxPool< float >(), nnfw::cker::MaxPool< uint8_t >(), nnfw::cker::Mean(), nnfw::cker::MeanAxis1And2(), nnfw::cker::MeanQ8Asymm(), nnfw::cker::Offset(), nnfw::cker::OneHot(), nnfw::cker::Einsum::operator()(), nnfw::cker::Pad(), nnfw::cker::FCTempArena::prepare(), nnfw::cker::BatchMatMul::prepare(), nnfw::cker::ReduceMean::PrepareforReduce(), nnfw::cker::ProcessBroadcastShapes(), nnfw::cker::Reduce::QuantizedMeanOrSum(), nnfw::cker::Reduce::ReduceGeneric(), nnfw::cker::ReduceImpl(), nnfw::cker::ReduceMeanImpl(), nnfw::cker::ReduceSumQuantImpl(), ReplaceWith(), nnfw::cker::ResizeBilinear(), nnfw::cker::Reverse(), nnfw::cker::RmsNorm(), nnfw::cker::reference::Softmax(), nnfw::cker::Softmax(), nnfw::cker::train::SoftMaxGrad(), nnfw::cker::SpaceToBatchND(), nnfw::cker::SpaceToDepth(), nnfw::cker::Split(), nnfw::cker::SplitV(), nnfw::cker::SqDiff(), nnfw::cker::StatelessRandomUniform(), nnfw::cker::StridedSlice(), nnfw::cker::TileOneDimension(), nnfw::cker::Transpose(), nnfw::cker::Transpose2D(), nnfw::cker::TransposeConv(), nnfw::cker::TransposeImpl(), nnfw::cker::reference::TransposeImpl(), and nnfw::cker::Unpack().

◆ Dims()

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

Definition at line 92 of file Shape.h.

93 {
94 assert(i >= 0);
95 assert(i < _size);
96 return _size > kMaxSmallSize ? _dims_pointer[i] : _dims[i];
97 }
int32_t _dims[kMaxSmallSize]
Definition Shape.h:215

References _dims, _dims_pointer, and kMaxSmallSize.

Referenced by nnfw::cker::ArgMinMax(), nnfw::cker::AveragePool16(), nnfw::cker::train::AveragePool2DGrad(), nnfw::cker::AveragePool32(), nnfw::cker::AveragePool< float >(), nnfw::cker::AveragePool< int8_t >(), nnfw::cker::train::backpropFilter(), nnfw::cker::train::backpropInput(), nnfw::cker::BatchMatMulParams::BatchMatMulParams(), nnfw::cker::BatchToSpaceND(), nnfw::cker::bias_op::biasHelper(), nnfw::cker::functor::biasReductionHelper(), nnfw::cker::reference::BroadcastBinaryArithmeticOpSlow(), nnfw::cker::reference::BroadcastBinaryArithmeticOpSlow(), nnfw::cker::reference::BroadcastBinaryArithmeticOpSlow(), nnfw::cker::reference::BroadcastBinaryArithmeticOpSlow(), nnfw::cker::reference::BroadcastBinaryArithmeticOpSlow(), nnfw::cker::BroadcastSelect4DSlow(), nnfw::cker::train::CategoricalCrossEntropy(), nnfw::cker::train::CategoricalCrossEntropyGrad(), nnfw::cker::train::CategoricalCrossEntropyWithLogits(), nnfw::cker::checkMatching(), nnfw::cker::Concatenation(), nnfw::cker::ConcatenationWithScaling(), nnfw::cker::reference::Conv(), nnfw::cker::multithreaded::Conv(), nnfw::cker::reference::Conv(), nnfw::cker::reference::Conv(), nnfw::cker::optimized::Conv(), nnfw::cker::train::ConvFilterGrad(), nnfw::cker::train::ConvInputGrad(), nnfw::cker::CopyDimsToDesc(), nnfw::cker::train::Depad(), nnfw::cker::DepthToSpace(), nnfw::cker::optimized_integer_ops::depthwise_conv::DepthwiseConvGeneral(), nnfw::cker::optimized::depthwise_conv::DepthwiseConvGeneral(), nnfw::cker::reference_integer_ops::DepthwiseConvHybridPerChannel(), nnfw::cker::optimized::DepthwiseConvImpl(), nnfw::cker::DepthwiseConvOp(), nnfw::cker::reference_integer_ops::DepthwiseConvPerChannel(), nnfw::cker::optimized_integer_ops::DepthwiseConvWithRounding(), nnfw::cker::optimized::DepthwiseConvWithRounding(), nnfw::cker::optimized::DilatedIm2col(), nnfw::cker::BCast::FromShape(), nnfw::cker::FullyConnected(), nnfw::cker::FullyConnected(), nnfw::cker::train::FullyConnectedBiasGrad(), nnfw::cker::FullyConnectedHybrid(), nnfw::cker::FullyConnectedSparseWeight16x1(), nnfw::cker::FullyConnectedSparseWeightRandom(), nnfw::cker::Gather(), nnfw::cker::HowManyConvThreads(), nnfw::cker::optimized_integer_ops::HowManyConvThreads(), nnfw::cker::reference::HybridConvPerChannel(), nnfw::cker::optimized::Im2col(), nnfw::cker::LogSoftmax(), nnfw::cker::LogSoftmax(), nnfw::cker::MapAsMatrixWithLastDimAsRows(), nnfw::cker::MatchingDim(), nnfw::cker::MatchingDim(), nnfw::cker::MatchingFlatSizeSkipDim(), nnfw::cker::MatchingFlatSizeSkipDim(), nnfw::cker::MatMulBCast::MatMulBCast(), nnfw::cker::MatrixBandPart(), nnfw::cker::train::MaxPool2D(), nnfw::cker::MaxPool< float >(), nnfw::cker::MaxPool< uint8_t >(), nnfw::cker::MeanAxis1And2(), nnfw::cker::train::MSE(), nnfw::cker::train::MSEGrad(), nnfw::cker::OneHot(), nnfw::cker::Einsum::operator()(), nnfw::cker::ShapeIterator::operator*(), nnfw::cker::Pad(), onert::backend::cpu::ops::ConvolutionLayer::prepare(), onert::backend::cpu::ops::FullyConnectedLayer::prepare(), nnfw::cker::FCTempArena::prepare(), nnfw::cker::BatchMatMul::prepare(), nnfw::cker::ProcessBroadcastShapes(), nnfw::cker::Reduce::QuantizedMeanOrSum(), nnfw::cker::ResizeBilinear(), nnfw::cker::ResizeBilinear(), nnfw::cker::ResizeBilinear(), nnfw::cker::ResizeBilinearKernel2x2(), nnfw::cker::Reverse(), nnfw::cker::RmsNorm(), nnfw::cker::RoPE(), nnfw::cker::Tensor::shaped(), nnfw::cker::Slice(), nnfw::cker::train::SoftMaxGrad(), nnfw::cker::SpaceToBatchND(), nnfw::cker::SpaceToDepth(), nnfw::cker::Split(), nnfw::cker::SplitV(), nnfw::cker::StartForAxis(), nnfw::cker::StopForAxis(), nnfw::cker::StridedSlice(), nnfw::cker::TileOneDimension(), nnfw::cker::Transpose3D(), nnfw::cker::TransposeConv(), and nnfw::cker::Unpack().

◆ DimsData() [1/2]

◆ DimsData() [2/2]

const int32_t * nnfw::cker::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::cker::Shape::DimsDataUpTo4D ( ) const
inline

Definition at line 115 of file Shape.h.

115{ return _dims; }

References _dims.

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

◆ ExtendedShape()

static Shape nnfw::cker::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::cker::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 buffer_size *= dim;
189 }
190 return buffer_size;
191 }

References DimsData().

Referenced by nnfw::cker::optimized::AddBiasAndEvalActivationFunction(), nnfw::cker::AddN(), nnfw::cker::train::AveragePool2DGrad(), nnfw::cker::BroadcastTo(), nnfw::cker::checkMatching(), nnfw::cker::Tensor::copyFrom(), nnfw::cker::reference_integer_ops::DepthwiseConvHybridPerChannel(), nnfw::cker::optimized_integer_ops::DepthwiseConvWithRounding(), nnfw::cker::optimized::DepthwiseConvWithRounding(), nnfw::cker::Tensor::flat(), nnfw::cker::Tensor::flat(), nnfw::cker::FloorDivElementwise(), nnfw::cker::FloorModElementwise(), nnfw::cker::FullyConnected(), nnfw::cker::train::FullyConnectedBiasGrad(), onert::backend::cpu::ops::FullyConnectedLayer::fullyConnectedHybrid(), nnfw::cker::FullyConnectedHybrid(), nnfw::cker::Gather(), nnfw::cker::LogicalAndElementwise(), nnfw::cker::LogicalOrElementwise(), nnfw::cker::MapAsVector(), nnfw::cker::MatchingElementsSize(), nnfw::cker::MatchingFlatSize(), nnfw::cker::MatMulBCast::MatMulBCast(), nnfw::cker::train::MaxPool2DGrad(), nnfw::cker::OneHot(), nnfw::cker::Conv::operator()(), onert::backend::cpu::ops::FullyConnectedLayer::prepare(), nnfw::cker::FCTempArena::prepare(), nnfw::cker::BatchMatMul::prepare(), nnfw::cker::RankOneSelect(), nnfw::cker::functor::BroadcastTo< Device, T >::ReshapeAndBCast(), and nnfw::cker::Transpose().

◆ operator!=()

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

Definition at line 193 of file Shape.h.

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

◆ operator=()

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

◆ operator==()

bool nnfw::cker::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::cker::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::cker::Shape::ReplaceWith ( int  dimensions_count,
const int32_t *  dims_data 
)
inline

◆ ReplaceWith() [3/3]

void nnfw::cker::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::cker::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(), nnfw::cker::BatchMatMul::prepare(), ReplaceWith(), ReplaceWith(), and Shape().

◆ SetDim()

void nnfw::cker::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 onert::backend::train::ops::MeanLayer::backward(), nnfw::cker::BatchToSpaceND(), nnfw::cker::BatchMatMul::prepare(), Shape(), and nnfw::cker::BCast::ToShape().

Field Documentation

◆ _dims

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

Definition at line 215 of file Shape.h.

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

◆ _dims_pointer

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

Definition at line 216 of file Shape.h.

216{nullptr};

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

◆ kMaxSmallSize

constexpr int nnfw::cker::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: