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

#include <Shape.h>

Collaboration diagram for mir::Shape:

Public Member Functions

 Shape ()=default
 
 Shape (int32_t rank)
 
 Shape (std::initializer_list< int32_t > &&dims)
 
 Shape (const std::vector< int32_t > &dims)
 
int32_t rank () const
 
void resize (int32_t size)
 
int32_t & dim (int32_t axis) noexcept
 
int32_t dim (int32_t axis) const noexcept
 
int32_t numElements () const
 
bool operator== (const Shape &rhs) const
 
bool operator!= (const Shape &rhs) const
 

Static Public Attributes

static constexpr int32_t autoDim = -1
 

Detailed Description

Definition at line 30 of file Shape.h.

Constructor & Destructor Documentation

◆ Shape() [1/4]

mir::Shape::Shape ( )
default

◆ Shape() [2/4]

mir::Shape::Shape ( int32_t  rank)
inlineexplicit

Definition at line 37 of file Shape.h.

37: _dims(rank) {}
int32_t rank() const
Definition Shape.h:43

◆ Shape() [3/4]

mir::Shape::Shape ( std::initializer_list< int32_t > &&  dims)
inline

Definition at line 39 of file Shape.h.

39: _dims(std::move(dims)) {}

◆ Shape() [4/4]

mir::Shape::Shape ( const std::vector< int32_t > &  dims)
inlineexplicit

Definition at line 41 of file Shape.h.

41: _dims(std::begin(dims), std::end(dims)) {}

Member Function Documentation

◆ dim() [1/2]

int32_t mir::Shape::dim ( int32_t  axis) const
inlinenoexcept

Definition at line 53 of file Shape.h.

54 {
55 auto dim = wrap_index(axis, _dims.size());
56 return _dims[dim];
57 }
size_t size() const noexcept
Definition SmallVector.h:67
int32_t & dim(int32_t axis) noexcept
Definition Shape.h:47
constexpr std::size_t wrap_index(std::int32_t index, std::size_t limit) noexcept
Definition Common.h:30

References dim(), adt::small_vector< T, Capacity >::size(), and mir::wrap_index().

◆ dim() [2/2]

int32_t & mir::Shape::dim ( int32_t  axis)
inlinenoexcept

Definition at line 47 of file Shape.h.

48 {
49 auto dim = wrap_index(axis, _dims.size());
50 return _dims[dim];
51 };

References dim(), adt::small_vector< T, Capacity >::size(), and mir::wrap_index().

Referenced by mir::broadcastShapes(), mir_caffe::CaffeOpCreator::checkReshape(), mir::ShapeRange::contains(), mir_onnx::convertBatchNormalizationV9(), mir_caffe2::Caffe2OpCreator::convertFC(), mir_tflite::TFLiteOpCreator::convertFullyConnected(), mir_tflite::TFLiteOpCreator::convertReshape(), mir_onnx::convertReshapeV1(), mir_tflite::TFLiteOpCreator::convertResizeNearestNeighbor(), mir_tflite::TFLiteOpCreator::convertShape(), mir_tflite::TFLiteOpCreator::convertStridedSlice(), mir_onnx::convertUnsqueezeV1(), mir_onnx::createTensor(), dim(), dim(), mir_onnx::fixPads(), nnc::AclCppOpGenerator::genPadStrideInfo(), mir::Tensor< T >::getRegion(), mir_onnx::inferAutoPadding(), numElements(), mir::ShapeIter::operator++(), mir_interpreter::DepthwiseConv2DImpl< T >::run(), mir_interpreter::DepthwiseConv2DImpl< uint8_t >::run(), mir_interpreter::SoftmaxImpl< T >::run(), mir_interpreter::PadImpl< T >::run(), mir_interpreter::FullyConnectedImpl< T >::run(), mir_interpreter::FullyConnectedImpl< uint8_t >::run(), mir_interpreter::Conv2DImpl< T >::run(), mir_interpreter::Conv2DImpl< uint8_t >::run(), mir_interpreter::DeConv2DImpl< T >::run(), mir_interpreter::shift(), mir::TensorVariant::TensorVariant(), mir::TensorVariant::TensorVariant(), TEST(), mir::toString(), mir::transposeShape(), mir::transposeTensor(), mir2loco::Transformer::visit(), nnc::ModelAnalyzer::visit(), nnc::ModelAnalyzer::visit(), nnc::AclCppOpGenerator::visit(), and nnc::AclCppOpGenerator::visit().

◆ numElements()

int32_t Shape::numElements ( ) const

Definition at line 30 of file Shape.cpp.

31{
32 int32_t res = 1;
33
34 for (int32_t axis = 0; axis < rank(); ++axis)
35 {
36 assert(dim(axis) != Shape::autoDim);
37 res *= dim(axis);
38 }
39
40 return res;
41}

References dim(), and rank().

Referenced by mir_tflite::TFLiteOpCreator::convertFullyConnected(), mir_onnx::convertReshapeV5(), mir::ShapeRange::end(), mir_interpreter::erase(), mir::TensorVariant::TensorVariant(), and mir::TensorVariant::TensorVariant().

◆ operator!=()

bool mir::Shape::operator!= ( const Shape rhs) const
inline

Definition at line 63 of file Shape.h.

63{ return !(*this == rhs); }

◆ operator==()

bool mir::Shape::operator== ( const Shape rhs) const
inline

Definition at line 61 of file Shape.h.

61{ return _dims == rhs._dims; }

◆ rank()

◆ resize()

void Shape::resize ( int32_t  size)

Definition at line 28 of file Shape.cpp.

28{ _dims.resize(size); }
void resize(size_t new_size) noexcept
resize to given new size
Definition SmallVector.h:78
int32_t size[5]
Definition Slice.cpp:35

References adt::small_vector< T, Capacity >::resize(), and size.

Field Documentation

◆ autoDim

constexpr int32_t Shape::autoDim = -1
staticconstexpr

Definition at line 33 of file Shape.h.


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