ArmNN
 25.11
Loading...
Searching...
No Matches
TensorShape Class Reference

#include <Tensor.hpp>

Public Member Functions

 TensorShape ()
 Empty (invalid) constructor.
 TensorShape (unsigned int numDimensions, bool initDimensionsSpecificity=true)
 Constructor for TensorShape.
 TensorShape (unsigned int numDimensions, const unsigned int *dimensionSizes)
 Constructor for TensorShape.
 TensorShape (std::initializer_list< unsigned int > dimensionSizeList)
 Constructor for TensorShape.
 TensorShape (const TensorShape &other)
 Copy Constructor for TensorShape.
 TensorShape (unsigned int numDimensions, const unsigned int *dimensionSizes, const bool *dimensionsSpecificity)
 Constructor for TensorShape.
 TensorShape (std::initializer_list< unsigned int > dimensionSizeList, std::initializer_list< bool > dimensionsSpecificityList)
 Constructor for TensorShape.
 TensorShape (Dimensionality dimensionality)
 Constructor for TensorShape.
TensorShapeoperator= (const TensorShape &other)
 Assignation function.
unsigned int operator[] (unsigned int i) const
 Read only operator.
unsigned int & operator[] (unsigned int i)
 Read and write operator.
bool operator== (const TensorShape &other) const
 Equality comparison operator.
bool operator!= (const TensorShape &other) const
 Inequality comparison operator.
unsigned int GetNumDimensions () const
 Function that returns the tensor rank.
unsigned int GetNumElements () const
 Function that calculates the tensor elements by multiplying all dimension size which are Specified.
Dimensionality GetDimensionality () const
 Function that returns the tensor type.
bool GetDimensionSpecificity (unsigned int i) const
 Gets information about if the dimension size has been specified or not.
void SetNumDimensions (unsigned int numDimensions, bool initDimensionsSpecificity=false)
 Sets the tensor rank and therefore the Dimensionality is set to Specified if it was not.
void SetDimensionSize (unsigned int i, unsigned int dimensionSize)
 Sets the size of the indicated dimension and Specificity for that dimension is set to true.
bool AreAllDimensionsSpecified () const
 Checks if there is at least one dimension not specified.
bool IsAtLeastOneDimensionSpecified () const
 Checks if there is at least one dimension specified.

Detailed Description

Constructor & Destructor Documentation

◆ TensorShape() [1/8]

Empty (invalid) constructor.

Definition at line 25 of file Tensor.cpp.

26 : m_NumDimensions(0), m_Dimensionality(Dimensionality::Specified)
27{
28}

References armnn::Specified.

Referenced by operator!=(), operator=(), operator==(), TensorShape(), TensorShape(), and TensorShape().

◆ TensorShape() [2/8]

TensorShape ( unsigned int numDimensions,
bool initDimensionsSpecificity = true )
explicit

Constructor for TensorShape.

Parameters
numDimensions- Tensor rank.
initDimensionsSpecificity(optional) - value to initialize the specificity of each dimension size.

Definition at line 30 of file Tensor.cpp.

31 : m_NumDimensions(numDimensions), m_Dimensionality(Dimensionality::Specified)
32{
33 CheckValidNumDimensions(numDimensions);
34
35 std::fill(m_Dimensions.begin(), m_Dimensions.begin() + m_NumDimensions, 0);
36 std::fill(m_DimensionsSpecificity.begin(), m_DimensionsSpecificity.begin() + m_NumDimensions,
37 initDimensionsSpecificity);
38}

References armnn::Specified.

◆ TensorShape() [3/8]

TensorShape ( unsigned int numDimensions,
const unsigned int * dimensionSizes )

Constructor for TensorShape.

Parameters
numDimensions- Tensor rank.
dimensionSizes- Size of each of dimension.

Definition at line 40 of file Tensor.cpp.

41 : m_NumDimensions(numDimensions), m_Dimensionality(Dimensionality::Specified)
42{
43 CheckValidNumDimensions(numDimensions);
44
45 if (dimensionSizes == nullptr)
46 {
47 throw InvalidArgumentException("Tensor dimensionSizes must not be NULL");
48 }
49
50 std::copy(dimensionSizes, dimensionSizes + numDimensions, m_Dimensions.begin());
51 std::fill(m_DimensionsSpecificity.begin(), m_DimensionsSpecificity.begin() + m_NumDimensions, true);
52}

References armnn::Specified.

◆ TensorShape() [4/8]

TensorShape ( std::initializer_list< unsigned int > dimensionSizeList)

Constructor for TensorShape.

Parameters
dimensionSizeList- Size of each of dimension.

Definition at line 54 of file Tensor.cpp.

55 : TensorShape(armnn::numeric_cast<unsigned int>(dimensionSizeList.size()), dimensionSizeList.begin())
56{
57}
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)

References armnn::numeric_cast(), and TensorShape().

◆ TensorShape() [5/8]

TensorShape ( const TensorShape & other)

Copy Constructor for TensorShape.

Parameters
other- TensorShape to copy from.

Definition at line 116 of file Tensor.cpp.

117 : m_NumDimensions(other.m_NumDimensions), m_Dimensionality(other.m_Dimensionality)
118{
119 std::copy(other.m_Dimensions.cbegin(), other.m_Dimensions.cbegin() + other.m_NumDimensions, m_Dimensions.begin());
120 std::copy(other.m_DimensionsSpecificity.cbegin(), other.m_DimensionsSpecificity.cbegin() + other.m_NumDimensions,
121 m_DimensionsSpecificity.begin());
122}

References TensorShape().

◆ TensorShape() [6/8]

TensorShape ( unsigned int numDimensions,
const unsigned int * dimensionSizes,
const bool * dimensionsSpecificity )

Constructor for TensorShape.

Parameters
numDimensions- Tensor rank.
dimensionSizes- Size of each of dimension.
dimensionsSpecificity- Flags to indicate which dimension has its size specified.

Definition at line 59 of file Tensor.cpp.

62 : m_NumDimensions(numDimensions), m_Dimensionality(Dimensionality::Specified)
63{
64 CheckValidNumDimensions(numDimensions);
65
66 if (dimensionSizes == nullptr)
67 {
68 throw InvalidArgumentException("Tensor dimensionSizes must not be NULL");
69 }
70
71 if (dimensionsSpecificity == nullptr)
72 {
73 throw InvalidArgumentException("Tensor dimensionsSpecificity must not be NULL");
74 }
75
76 std::copy(dimensionSizes, dimensionSizes + numDimensions, m_Dimensions.begin());
77 std::copy(dimensionsSpecificity, dimensionsSpecificity + numDimensions, m_DimensionsSpecificity.begin());
78}

References armnn::Specified.

◆ TensorShape() [7/8]

TensorShape ( std::initializer_list< unsigned int > dimensionSizeList,
std::initializer_list< bool > dimensionsSpecificityList )

Constructor for TensorShape.

Parameters
dimensionSizeList- Size of each of dimension.
dimensionsSpecificityList- Flags to indicate which dimension size is specified.

Definition at line 80 of file Tensor.cpp.

82{
83 auto numDimensions = static_cast<unsigned int>(dimensionSizeList.size());
84 if (dimensionsSpecificityList.size() != numDimensions)
85 {
86 throw InvalidArgumentException("Tensors dimensionSizeList and dimensionsSpecificityList must be same size");
87 }
88
89 *this = TensorShape(numDimensions, dimensionSizeList.begin(), dimensionsSpecificityList.begin());
90}

References TensorShape().

◆ TensorShape() [8/8]

TensorShape ( Dimensionality dimensionality)
explicit

Constructor for TensorShape.

Parameters
dimensionality- Parameter to indicate if the Tensor is a Scalar, a Tensor of known dimensionality or a Tensor of unknown dimensionality.

Definition at line 92 of file Tensor.cpp.

93: m_Dimensionality(dimensionality)
94{
95 switch (dimensionality)
96 {
97 case Dimensionality::Specified:
98 throw InvalidArgumentException("Use other constructor to specify the rest of the values, this one is only "
99 "for tensors that have an unknown number of dimensions or that are scalar");
100 break;
101 case Dimensionality::NotSpecified:
102 m_NumDimensions = 0;
103 m_Dimensions = {0};
104 m_DimensionsSpecificity = {false};
105 break;
106 case Dimensionality::Scalar:
107 m_NumDimensions = 1;
108 m_Dimensions = {1};
109 m_DimensionsSpecificity = {true};
110 break;
111 default:
112 throw InvalidArgumentException("Invalid Dimensionality value");
113 }
114}

References armnn::NotSpecified, armnn::Scalar, and armnn::Specified.

Member Function Documentation

◆ AreAllDimensionsSpecified()

bool AreAllDimensionsSpecified ( ) const

Checks if there is at least one dimension not specified.

AND of all array elements.

Returns
- True when all dimension sizes are specified. False when at least one dimension size is not specified.

Definition at line 241 of file Tensor.cpp.

242{
243 CheckUnspecifiedNumDimensions();
244
245 bool areAllDimensionsSpecified = true;
246 for (unsigned int i = 0; i < m_NumDimensions; ++i)
247 {
248 if (!m_DimensionsSpecificity[i])
249 {
250 areAllDimensionsSpecified = false;
251 break;
252 }
253 }
254 return areAllDimensionsSpecified;
255}

Referenced by ConstantLayer::ValidateTensorShapesFromInputs(), and Layer::VerifyShapeInferenceType().

◆ GetDimensionality()

Dimensionality GetDimensionality ( ) const
inline

Function that returns the tensor type.

Returns
- Parameter to indicate if the Tensor is a scalar, a Tensor of known dimensionality or a Tensor of unknown dimensionality

Definition at line 92 of file Tensor.hpp.

92{ return m_Dimensionality; }

Referenced by GatherLayer::InferOutputShapes(), GatherNdLayer::InferOutputShapes(), armnn::operator<<(), Layer::ValidateAndCopyShape(), ConstantLayer::ValidateTensorShapesFromInputs(), and Layer::VerifyShapeInferenceType().

◆ GetDimensionSpecificity()

bool GetDimensionSpecificity ( unsigned int i) const

Gets information about if the dimension size has been specified or not.

Parameters
i- Dimension index.
Returns
- Flag to indicate if the dimension "i" has a specified size.

Definition at line 211 of file Tensor.cpp.

212{
213 CheckUnspecifiedNumDimensions();
214 CheckDimensionIndex(i);
215
216 return m_DimensionsSpecificity[i];
217}

Referenced by armnn::operator<<(), and Layer::ValidateAndCopyShape().

◆ GetNumDimensions()

unsigned int GetNumDimensions ( ) const

Function that returns the tensor rank.

Returns
- Tensor rank.

Definition at line 174 of file Tensor.cpp.

175{
176 CheckUnspecifiedNumDimensions();
177
178 return m_NumDimensions;
179}

Referenced by BroadcastLoop::BroadcastLoop(), ShapesAreBroadcastCompatible::CalcInputSize(), armnnDeserializer::CheckShape(), ClStackWorkload::ClStackWorkload(), armnn::ClStackWorkloadValidate(), armnn::ClUnidirectionalSequenceLstmFloatWorkloadValidate(), armnnUtils::ConvertTensorShapeToString(), armnn::CoordinatesToIndex(), armnn::CopyTensorContentsGeneric(), ClImportTensorHandleFactory::CreateSubTensorHandle(), ClTensorHandleFactory::CreateSubTensorHandle(), ClWorkloadFactory::CreateSubTensorHandle(), NeonTensorHandleFactory::CreateSubTensorHandle(), NeonWorkloadFactory::CreateSubTensorHandle(), armnnUtils::ExpandDims(), armnnUtils::ExpandDimsToRank(), BatchMatMulDescriptor::GetAxesNotMul(), BatchMatMulDescriptor::GetAxesToMul(), armnnUtils::GetNumElementsAfter(), armnnUtils::GetNumElementsBetween(), armnn::GetOffset(), BatchMatMulDescriptor::GetPermuteVec(), GetTosaTensorShape(), armnn::GetUnpaddedTensorStrides(), ArgMinMaxLayer::InferOutputShapes(), BatchMatMulLayer::InferOutputShapes(), ComparisonLayer::InferOutputShapes(), Convolution2dLayer::InferOutputShapes(), Convolution3dLayer::InferOutputShapes(), DepthwiseConvolution2dLayer::InferOutputShapes(), ElementwiseBaseLayer::InferOutputShapes(), ElementwiseBinaryLayer::InferOutputShapes(), GatherLayer::InferOutputShapes(), GatherNdLayer::InferOutputShapes(), LogicalBinaryLayer::InferOutputShapes(), MeanLayer::InferOutputShapes(), PadLayer::InferOutputShapes(), Pooling2dLayer::InferOutputShapes(), Pooling3dLayer::InferOutputShapes(), PreluLayer::InferOutputShapes(), ReduceLayer::InferOutputShapes(), StackLayer::InferOutputShapes(), StridedSliceLayer::InferOutputShapes(), TileLayer::InferOutputShapes(), TransposeConvolution2dLayer::InferOutputShapes(), armnn::LogSoftmax(), armnn::MirrorPad(), NeonStackWorkload::NeonStackWorkload(), armnn::NeonStackWorkloadValidate(), armnn::NeonUnidirectionalSequenceLstmFloatWorkloadValidate(), armnn::NeonUnidirectionalSequenceLstmWorkloadValidate(), armnn::Offset(), armnn::operator<<(), armnn::Pad(), armnnUtils::Permuted(), armnnUtils::ReduceDims(), ShapesAreBroadcastCompatible::ShapesAreBroadcastCompatible(), ShapesAreSameRank::ShapesAreSameRank(), armnn::Slice(), armnn::Softmax(), armnnUtils::SqueezeDims(), armnnUtils::TransposeTensorShape(), ArgMinMaxQueueDescriptor::Validate(), StackQueueDescriptor::Validate(), Layer::ValidateAndCopyShape(), and armnnNumpy::WriteToNumpyFile().

◆ GetNumElements()

unsigned int GetNumElements ( ) const

Function that calculates the tensor elements by multiplying all dimension size which are Specified.

Returns
- Total number of elements in the tensor.

Definition at line 181 of file Tensor.cpp.

182{
183 CheckUnspecifiedNumDimensions();
184
185 if (m_NumDimensions == 0)
186 {
187 return 0;
188 }
189
190 unsigned int count = 1;
191 bool atLeastOneDimensionSpecified = false;
192 for (unsigned int i = 0; i < m_NumDimensions; ++i)
193 {
194 if (m_DimensionsSpecificity[i])
195 {
196 atLeastOneDimensionSpecified = true;
197 count *= m_Dimensions[i];
198 }
199 }
200
201 if (atLeastOneDimensionSpecified)
202 {
203 return count;
204 }
205 else
206 {
207 return 0;
208 }
209}

Referenced by BooleanDecoder::DecodeTensor(), BooleanDecoderBool::DecodeTensor(), Float16Decoder::DecodeTensor(), Float32Decoder::DecodeTensor(), Int32Decoder::DecodeTensor(), Int32ToInt32tDecoder::DecodeTensor(), Int64Decoder::DecodeTensor(), QASymm8Decoder::DecodeTensor(), QASymmS8Decoder::DecodeTensor(), QSymm16Decoder::DecodeTensor(), QSymm8PerAxisDecoder::DecodeTensor(), QSymmS8Decoder::DecodeTensor(), ScaledInt32Decoder::DecodeTensor(), ScaledInt32PerAxisDecoder::DecodeTensor(), armnn::DepthToSpace(), armnn::Fill(), armnnUtils::FindMinMax(), armnn::TransposeConvolution2dImpl(), and ScatterNdLayer::ValidateTensorShapesFromInputs().

◆ IsAtLeastOneDimensionSpecified()

bool IsAtLeastOneDimensionSpecified ( ) const

Checks if there is at least one dimension specified.

OR of all array elements.

Returns
- True at least one dimension sizes is specified. False when all dimension sizes are not specified.

Definition at line 257 of file Tensor.cpp.

258{
259 CheckUnspecifiedNumDimensions();
260
261 bool isAtLeastOneDimensionSpecified = false;
262 for (unsigned int i = 0; i < m_NumDimensions; ++i)
263 {
264 if (m_DimensionsSpecificity[i])
265 {
266 isAtLeastOneDimensionSpecified = true;
267 break;
268 }
269 }
270 return isAtLeastOneDimensionSpecified;
271}

◆ operator!=()

bool operator!= ( const TensorShape & other) const

Inequality comparison operator.

Parameters
other- TensorShape to compare with.

Definition at line 169 of file Tensor.cpp.

170{
171 return !(*this == other);
172}

References TensorShape().

◆ operator=()

TensorShape & operator= ( const TensorShape & other)

Assignation function.

Parameters
other- TensorShape to copy from.

Definition at line 124 of file Tensor.cpp.

125{
126 m_NumDimensions = other.m_NumDimensions;
127 m_Dimensionality = other.m_Dimensionality;
128 std::copy(other.m_Dimensions.cbegin(), other.m_Dimensions.cbegin() + other.m_NumDimensions, m_Dimensions.begin());
129 std::copy(other.m_DimensionsSpecificity.cbegin(), other.m_DimensionsSpecificity.cbegin() + other.m_NumDimensions,
130 m_DimensionsSpecificity.begin());
131 return *this;
132}

References TensorShape().

◆ operator==()

bool operator== ( const TensorShape & other) const

Equality comparison operator.

Parameters
other- TensorShape to compare with.

Definition at line 160 of file Tensor.cpp.

161{
162 return ((m_NumDimensions == other.m_NumDimensions) &&
163 (m_Dimensionality == other.m_Dimensionality) &&
164 std::equal(m_Dimensions.cbegin(), m_Dimensions.cbegin() + m_NumDimensions, other.m_Dimensions.cbegin()) &&
165 std::equal(m_DimensionsSpecificity.cbegin(), m_DimensionsSpecificity.cbegin() + m_NumDimensions,
166 other.m_DimensionsSpecificity.cbegin()));
167}

References TensorShape().

◆ operator[]() [1/2]

unsigned int & operator[] ( unsigned int i)

Read and write operator.

Parameters
i- Dimension index.

Definition at line 145 of file Tensor.cpp.

146{
147 if (Dimensionality::Scalar == m_Dimensionality)
148 {
149 std::stringstream errorMessage;
150 errorMessage << "TensorShape with Dimensionality::Scalar must be const to use operator[]";
151 throw InvalidArgumentException(errorMessage.str(), CHECK_LOCATION());
152 }
153 CheckUnspecifiedNumDimensions();
154 CheckDimensionIndex(i);
155 CheckDimensionSpecified(i);
156
157 return m_Dimensions.at(i);
158}
#define CHECK_LOCATION()

References CHECK_LOCATION, and armnn::Scalar.

◆ operator[]() [2/2]

unsigned int operator[] ( unsigned int i) const

Read only operator.

Parameters
i- Dimension index.

Definition at line 135 of file Tensor.cpp.

136{
137 CheckUnspecifiedNumDimensions();
138 CheckDimensionIndex(i);
139 CheckDimensionSpecified(i);
140
141 return m_Dimensions.at(i);
142}

◆ SetDimensionSize()

void SetDimensionSize ( unsigned int i,
unsigned int dimensionSize )

Sets the size of the indicated dimension and Specificity for that dimension is set to true.

Parameters
i- Dimension index.
dimensionSize- size of one dimension.

Definition at line 232 of file Tensor.cpp.

233{
234 CheckScalar();
235 CheckDimensionIndex(i);
236
237 m_Dimensions[i] = dimensionSize;
238 m_DimensionsSpecificity[i] = true;
239}

◆ SetNumDimensions()

void SetNumDimensions ( unsigned int numDimensions,
bool initDimensionsSpecificity = false )

Sets the tensor rank and therefore the Dimensionality is set to Specified if it was not.

Parameters
numDimensions- Tensor rank.
initDimensionsSpecificity(optional) - value to initialize the specificity of each dimension size.

Definition at line 219 of file Tensor.cpp.

220{
221 CheckScalar();
222 CheckSpecifiedNumDimensions();
223 CheckValidNumDimensions(numDimensions);
224
225 m_NumDimensions = numDimensions;
226 m_Dimensionality = Dimensionality::Specified;
227 std::fill(m_Dimensions.begin(), m_Dimensions.begin() + m_NumDimensions, 0);
228 std::fill(m_DimensionsSpecificity.begin(), m_DimensionsSpecificity.begin() + m_NumDimensions,
229 initDimensionsSpecificity);
230}

References armnn::Specified.


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