Compute Library
 21.02
SubTensorInfo Class Referencefinal

Store the sub tensor's metadata. More...

#include <SubTensorInfo.h>

Collaboration diagram for SubTensorInfo:
[legend]

Public Member Functions

 SubTensorInfo ()
 Default constructor. More...
 
 SubTensorInfo (ITensorInfo *parent, TensorShape tensor_shape, Coordinates coords, bool extend_parent=false)
 Default constructor. More...
 
 ~SubTensorInfo ()=default
 Default destructor. More...
 
 SubTensorInfo (const SubTensorInfo &)=default
 Allow instances of this class to be copy constructed. More...
 
SubTensorInfooperator= (const SubTensorInfo &)=default
 Allow instances of this class to be copied. More...
 
 SubTensorInfo (SubTensorInfo &&)=default
 Allow instances of this class to be move constructed. More...
 
SubTensorInfooperator= (SubTensorInfo &&)=default
 Allow instances of this class to be moved. More...
 
Coordinates coords () const
 Returns the coordinates of the sub-tensor inside the parent tensor. More...
 
std::unique_ptr< ITensorInfoclone () const override
 Provide a clone of the current object of class T. More...
 
ITensorInfoset_data_type (DataType data_type) override
 Set the data type to the specified value. More...
 
ITensorInfoset_data_layout (const DataLayout &data_layout) override
 Set the data layout of the tensor. More...
 
ITensorInfoset_num_channels (int num_channels) override
 Set the number of channels to the specified value. More...
 
ITensorInfoset_format (Format format) override
 Set the format of an already initialized tensor. More...
 
ITensorInfoset_tensor_shape (const TensorShape &shape) override
 Set the shape of an already initialized tensor. More...
 
ITensorInfoset_tensor_dims_state (const TensorDimsState &state) override
 
ITensorInfoset_quantization_info (const QuantizationInfo &quantization_info) override
 Set the quantization settings (scale and offset) of the tensor. More...
 
ITensorInforeset_padding () override
 Resets the padding settings of the tensor. More...
 
bool auto_padding () override
 Update the offset to the first element and the strides to automatically computed values. More...
 
bool extend_padding (const PaddingSize &padding) override
 Update the offset to the first element, the strides and the total size. More...
 
size_t dimension (size_t index) const override
 Return the size of the requested dimension. More...
 
size_t dimension (DataLayoutDimension dimension) const override
 Return the size of the requested data layout dimension. More...
 
const Stridesstrides_in_bytes () const override
 The strides in bytes for accessing each dimension of the tensor. More...
 
size_t offset_first_element_in_bytes () const override
 The offset from the beginning of the memory allocation to the first element of the tensor. More...
 
int32_t offset_element_in_bytes (const Coordinates &pos) const override
 The offset in bytes from the beginning of the memory allocation to access the element at position (x, y, z ...) More...
 
size_t element_size () const override
 Element size in bytes calculated as data_size() * num_channels() More...
 
size_t num_dimensions () const override
 The number of dimensions of the tensor (rank) More...
 
size_t num_channels () const override
 The number of channels for each tensor element. More...
 
const TensorShapetensor_shape () const override
 Size for each dimension of the tensor. More...
 
const TensorDimsStatetensor_dims_state () const override
 State of each dimension of the tensor shape. More...
 
DataType data_type () const override
 Data type used for each element of the tensor. More...
 
Format format () const override
 Colour format of the image. More...
 
size_t total_size () const override
 Returns the total size of the tensor in bytes. More...
 
PaddingSize padding () const override
 Padding of tensor. More...
 
bool has_padding () const override
 Checks if the tensor has been allocated with padding or not. More...
 
bool is_resizable () const override
 Flag indicating whether the size of the tensor can be changed. More...
 
bool is_dynamic () const override
 Flag indicating whether the shape of the tensor is dynamic, meaning that it can change on kernel/function execution. More...
 
ITensorInfoset_is_resizable (bool is_resizable) override
 Set the flag whether the tensor size can be changed. More...
 
ValidRegion valid_region () const override
 Valid region of the tensor. More...
 
void set_valid_region (const ValidRegion &valid_region) override
 Set the valid region of the tensor. More...
 
QuantizationInfo quantization_info () const override
 Get the quantization settings (scale and offset) of the tensor. More...
 
DataLayout data_layout () const override
 Get the data layout of the tensor. More...
 
- Public Member Functions inherited from ITensorInfo
virtual ~ITensorInfo ()=default
 Default virtual destructor. More...
 
virtual ITensorInfoset_tensor_dims_state (const TensorDimsState &state)=0
 Set the state for each dimension of the tensor. More...
 
- Public Member Functions inherited from ICloneable< ITensorInfo >
virtual ~ICloneable ()=default
 Default virtual desctructor. More...
 

Additional Inherited Members

- Public Types inherited from ITensorInfo
using TensorDimsState = Coordinates
 
- Static Public Member Functions inherited from ITensorInfo
template<typename... Infos>
static std::pair< TensorShape, ValidRegionbroadcast_shape_and_valid_region (const Infos &... infos)
 If infos are broadcast compatible tensor info's, return the broadcasted shape and the intersection of the broadcasted valid regions of the tensors. More...
 

Detailed Description

Store the sub tensor's metadata.

Definition at line 41 of file SubTensorInfo.h.

Constructor & Destructor Documentation

◆ SubTensorInfo() [1/4]

Default constructor.

Definition at line 58 of file SubTensorInfo.cpp.

59  : _parent(nullptr), _tensor_shape(), _dims_state(), _coords(), _valid_region{ Coordinates(), _tensor_shape }, _extend_parent(false)
60 {
61 }

◆ SubTensorInfo() [2/4]

SubTensorInfo ( ITensorInfo parent,
TensorShape  tensor_shape,
Coordinates  coords,
bool  extend_parent = false 
)

Default constructor.

Parameters
[in]parentMetadata of parent tensor.
[in]tensor_shapeTensor shape. Shape must fit inside parent's shape. X and Y dimensions must match the parent's ones.
[in]coordsCoordinates of starting element inside parent tensor.
[in]extend_parent(Optional) Extend parent with subtensor shape if subtensor indexes out of bounds

Definition at line 63 of file SubTensorInfo.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBTENSOR, SubTensorInfo::coords(), and SubTensorInfo::tensor_shape().

64  : _parent(parent), _tensor_shape(tensor_shape), _dims_state(), _coords(coords), _valid_region{ Coordinates(), _tensor_shape }, _extend_parent(extend_parent)
65 {
66  ARM_COMPUTE_ERROR_ON(parent == nullptr);
67 
68  // Check if subtensor is valid if parent is configured
69  if(parent->tensor_shape().total_size() != 0 && !_extend_parent)
70  {
72  }
73 
74  // Initialize valid region
75  _valid_region = ValidRegion{ Coordinates(), _tensor_shape };
76 }
Coordinates coords() const
Returns the coordinates of the sub-tensor inside the parent tensor.
Definition: SubTensorInfo.h:69
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
const TensorShape & tensor_shape() const override
Size for each dimension of the tensor.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBTENSOR(p, c, s)
Definition: Validate.h:959

◆ ~SubTensorInfo()

~SubTensorInfo ( )
default

Default destructor.

◆ SubTensorInfo() [3/4]

SubTensorInfo ( const SubTensorInfo )
default

Allow instances of this class to be copy constructed.

◆ SubTensorInfo() [4/4]

SubTensorInfo ( SubTensorInfo &&  )
default

Allow instances of this class to be move constructed.

Member Function Documentation

◆ auto_padding()

bool auto_padding ( )
inlineoverridevirtual

Update the offset to the first element and the strides to automatically computed values.

Note
The padding used by this method is really conservative so that the tensor can be used for most functions.
Returns
True if the strides or the offset to the first element have changed.

Implements ITensorInfo.

Definition at line 114 of file SubTensorInfo.h.

References ARM_COMPUTE_ERROR_ON, ITensorInfo::auto_padding(), SubTensorInfo::extend_padding(), and SubTensorInfo::padding().

115  {
116  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
117  return _parent->auto_padding();
118  };
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
virtual bool auto_padding()=0
Update the offset to the first element and the strides to automatically computed values.

◆ clone()

std::unique_ptr< ITensorInfo > clone ( ) const
overridevirtual

Provide a clone of the current object of class T.

Returns
Clone object of class T

Implements ICloneable< ITensorInfo >.

Definition at line 78 of file SubTensorInfo.cpp.

References ARM_COMPUTE_ERROR_ON, and ICloneable< T >::clone().

Referenced by SubTensorInfo::coords().

79 {
80  // Clone creates a TensorInfo object from SubTensorInfo's parent which will conclude to a TensorInfo
81  // For now it does not make sense to copy a SubTensorInfo explicitly
82  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
83  auto clone_obj = _parent->clone();
84  clone_obj->set_tensor_shape(_tensor_shape);
85  clone_obj->set_valid_region(_valid_region);
86  return clone_obj;
87 }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.

◆ coords()

Coordinates coords ( ) const
inline

Returns the coordinates of the sub-tensor inside the parent tensor.

Returns
Sub-tensor coordinates

Definition at line 69 of file SubTensorInfo.h.

References SubTensorInfo::clone().

Referenced by SubTensorInfo::SubTensorInfo().

70  {
71  return _coords;
72  }

◆ data_layout()

DataLayout data_layout ( ) const
inlineoverridevirtual

Get the data layout of the tensor.

Returns
A DataLayout containing the layout data information.

Implements ITensorInfo.

Definition at line 224 of file SubTensorInfo.h.

References ARM_COMPUTE_ERROR_ON, and ITensorInfo::data_layout().

225  {
226  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
227  return _parent->data_layout();
228  }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.

◆ data_type()

DataType data_type ( ) const
inlineoverridevirtual

Data type used for each element of the tensor.

Returns
Tensor data type

Implements ITensorInfo.

Definition at line 164 of file SubTensorInfo.h.

References ARM_COMPUTE_ERROR_ON, and ITensorInfo::data_type().

165  {
166  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
167  return _parent->data_type();
168  }
virtual DataType data_type() const =0
Data type used for each element of the tensor.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466

◆ dimension() [1/2]

size_t dimension ( size_t  index) const
inlineoverridevirtual

Return the size of the requested dimension.

Parameters
[in]indexIndex of the dimension
Returns
Dimension of the requested dimension

Implements ITensorInfo.

Definition at line 120 of file SubTensorInfo.h.

Referenced by SubTensorInfo::dimension().

121  {
122  return _tensor_shape[index];
123  }

◆ dimension() [2/2]

size_t dimension ( DataLayoutDimension  dimension) const
inlineoverridevirtual

Return the size of the requested data layout dimension.

Parameters
[in]dimensionDataLayoutDimension of the dimension
Returns
Dimension of the requested dimension

Implements ITensorInfo.

Definition at line 124 of file SubTensorInfo.h.

References ARM_COMPUTE_ERROR_ON, ITensorInfo::data_layout(), SubTensorInfo::dimension(), and arm_compute::get_data_layout_dimension_index().

125  {
126  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
128  }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:193
size_t dimension(size_t index) const override
Return the size of the requested dimension.
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.

◆ element_size()

size_t element_size ( ) const
inlineoverridevirtual

Element size in bytes calculated as data_size() * num_channels()

Returns
The size of one element in bytes

Implements ITensorInfo.

Definition at line 140 of file SubTensorInfo.h.

References ARM_COMPUTE_ERROR_ON, and ITensorInfo::element_size().

141  {
142  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
143  return _parent->element_size();
144  }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
virtual size_t element_size() const =0
Element size in bytes calculated as data_size() * num_channels()

◆ extend_padding()

bool extend_padding ( const PaddingSize padding)
overridevirtual

Update the offset to the first element, the strides and the total size.

Note
This function can only increase the offset, strides and total size.
Parameters
[in]paddingPadding around the XY plane in number of elements.
Returns
True if the strides, offset and total size have changed.

Implements ITensorInfo.

Definition at line 117 of file SubTensorInfo.cpp.

References ARM_COMPUTE_ERROR_ON, BorderSize::bottom, ITensorInfo::extend_padding(), ITensorInfo::is_resizable(), BorderSize::left, BorderSize::right, SubTensorInfo::tensor_shape(), ITensorInfo::tensor_shape(), BorderSize::top, ITensorInfo::total_size(), Dimensions< T >::x(), and Dimensions< T >::y().

Referenced by SubTensorInfo::auto_padding(), and arm_compute::test::validation::TEST_CASE().

118 {
119  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
120  ARM_COMPUTE_ERROR_ON(!_parent->is_resizable());
121  ARM_COMPUTE_ERROR_ON(_parent->total_size() == 0);
122 
123  // Check that you do not extend padding on sub-tensors unless XY shape matches parent tensor
124  // TODO(COMPMID-3558): Remove _extend_parent check
125  if(!_extend_parent && (padding.left || padding.right))
126  {
127  ARM_COMPUTE_ERROR_ON(_parent->tensor_shape().x() != tensor_shape().x());
128  }
129  if(!_extend_parent && (padding.top || padding.bottom))
130  {
131  ARM_COMPUTE_ERROR_ON(_parent->tensor_shape().y() != tensor_shape().y());
132  }
133 
134  // Extend parent padding if required
135  return _parent->extend_padding(padding);
136 }
unsigned int top
top of the border
Definition: Types.h:375
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
unsigned int bottom
bottom of the border
Definition: Types.h:377
T x() const
Alias to access the size of the first dimension.
Definition: Dimensions.h:87
virtual bool is_resizable() const =0
Flag indicating whether the size of the tensor can be changed.
PaddingSize padding() const override
Padding of tensor.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
const TensorShape & tensor_shape() const override
Size for each dimension of the tensor.
unsigned int left
left of the border
Definition: Types.h:378
unsigned int right
right of the border
Definition: Types.h:376
virtual size_t total_size() const =0
Returns the total size of the tensor in bytes.
T y() const
Alias to access the size of the second dimension.
Definition: Dimensions.h:92
virtual bool extend_padding(const PaddingSize &padding)=0
Update the offset to the first element, the strides and the total size.

◆ format()

Format format ( ) const
inlineoverridevirtual

Colour format of the image.

Returns
Colour format of the image

Implements ITensorInfo.

Definition at line 169 of file SubTensorInfo.h.

References ARM_COMPUTE_ERROR_ON, and ITensorInfo::format().

170  {
171  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
172  return _parent->format();
173  }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
virtual Format format() const =0
Colour format of the image.

◆ has_padding()

bool has_padding ( ) const
inlineoverridevirtual

Checks if the tensor has been allocated with padding or not.

Returns
True if padding is allocated in the tensor, otherwise false.

Implements ITensorInfo.

Definition at line 184 of file SubTensorInfo.h.

References ARM_COMPUTE_ERROR_ON, and ITensorInfo::has_padding().

185  {
186  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
187  return _parent->has_padding();
188  }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
virtual bool has_padding() const =0
Checks if the tensor has been allocated with padding or not.

◆ is_dynamic()

bool is_dynamic ( ) const
inlineoverridevirtual

Flag indicating whether the shape of the tensor is dynamic, meaning that it can change on kernel/function execution.

Returns
True if its dynamic else false

Implements ITensorInfo.

Definition at line 194 of file SubTensorInfo.h.

References ARM_COMPUTE_ERROR_ON, and ITensorInfo::is_dynamic().

195  {
196  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
197  return _parent->is_dynamic();
198  }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
virtual bool is_dynamic() const =0
Flag indicating whether the shape of the tensor is dynamic, meaning that it can change on kernel/func...

◆ is_resizable()

bool is_resizable ( ) const
inlineoverridevirtual

Flag indicating whether the size of the tensor can be changed.

Returns
True if the tensor size can be changed.

Implements ITensorInfo.

Definition at line 189 of file SubTensorInfo.h.

References ARM_COMPUTE_ERROR_ON, and ITensorInfo::is_resizable().

190  {
191  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
192  return _parent->is_resizable();
193  }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
virtual bool is_resizable() const =0
Flag indicating whether the size of the tensor can be changed.

◆ num_channels()

size_t num_channels ( ) const
inlineoverridevirtual

The number of channels for each tensor element.

Returns
The number of channels for each tensor element

Implements ITensorInfo.

Definition at line 149 of file SubTensorInfo.h.

References ARM_COMPUTE_ERROR_ON, and ITensorInfo::num_channels().

150  {
151  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
152  return _parent->num_channels();
153  }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
virtual size_t num_channels() const =0
The number of channels for each tensor element.

◆ num_dimensions()

size_t num_dimensions ( ) const
inlineoverridevirtual

The number of dimensions of the tensor (rank)

Returns
The number of dimensions of the tensor (rank)

Implements ITensorInfo.

Definition at line 145 of file SubTensorInfo.h.

References Dimensions< T >::num_dimensions().

146  {
147  return _tensor_shape.num_dimensions();
148  }
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
Definition: Dimensions.h:143

◆ offset_element_in_bytes()

int32_t offset_element_in_bytes ( const Coordinates pos) const
overridevirtual

The offset in bytes from the beginning of the memory allocation to access the element at position (x, y, z ...)

Parameters
[in]posVector with the coordinates of the element to access. The size of this vector must be equal to the number of dimensions of the tensor
Returns
Offset in bytes from the beginning of the memory allocation to access the element (x, y, z, ...)

Implements ITensorInfo.

Definition at line 138 of file SubTensorInfo.cpp.

References ARM_COMPUTE_ERROR_ON_COORDINATES_DIMENSIONS_GTE, Dimensions< T >::num_dimensions(), offset(), SubTensorInfo::offset_first_element_in_bytes(), and SubTensorInfo::strides_in_bytes().

Referenced by SubTensorInfo::offset_first_element_in_bytes().

139 {
141 
143  const Strides &strides = strides_in_bytes();
144 
145  for(size_t i = 0; i < _tensor_shape.num_dimensions(); ++i)
146  {
147  offset += pos[i] * strides[i];
148  }
149 
150  return offset;
151 }
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
Definition: helpers.h:846
const Strides & strides_in_bytes() const override
The strides in bytes for accessing each dimension of the tensor.
size_t offset_first_element_in_bytes() const override
The offset from the beginning of the memory allocation to the first element of the tensor...
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
Definition: Dimensions.h:143
#define ARM_COMPUTE_ERROR_ON_COORDINATES_DIMENSIONS_GTE(p, md)
Definition: Validate.h:244

◆ offset_first_element_in_bytes()

size_t offset_first_element_in_bytes ( ) const
inlineoverridevirtual

The offset from the beginning of the memory allocation to the first element of the tensor.

This can be used to access efficiently elements in a 2D tensor

Returns
The offset in bytes to access the first element of the tensor.

Implements ITensorInfo.

Definition at line 134 of file SubTensorInfo.h.

References ARM_COMPUTE_ERROR_ON, SubTensorInfo::offset_element_in_bytes(), and ITensorInfo::offset_element_in_bytes().

Referenced by SubTensorInfo::offset_element_in_bytes().

135  {
136  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
137  return _parent->offset_element_in_bytes(_coords);
138  }
virtual int32_t offset_element_in_bytes(const Coordinates &pos) const =0
The offset in bytes from the beginning of the memory allocation to access the element at position (x...
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466

◆ operator=() [1/2]

SubTensorInfo& operator= ( const SubTensorInfo )
default

Allow instances of this class to be copied.

◆ operator=() [2/2]

SubTensorInfo& operator= ( SubTensorInfo &&  )
default

Allow instances of this class to be moved.

◆ padding()

PaddingSize padding ( ) const
inlineoverridevirtual

Padding of tensor.

Returns
Padding.

Implements ITensorInfo.

Definition at line 179 of file SubTensorInfo.h.

References ARM_COMPUTE_ERROR_ON, and ITensorInfo::padding().

Referenced by SubTensorInfo::auto_padding().

180  {
181  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
182  return _parent->padding();
183  }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
virtual PaddingSize padding() const =0
Padding of tensor.

◆ quantization_info()

QuantizationInfo quantization_info ( ) const
inlineoverridevirtual

Get the quantization settings (scale and offset) of the tensor.

Returns
A QuantizationInfo containing the scale and offset.

Implements ITensorInfo.

Definition at line 219 of file SubTensorInfo.h.

References ARM_COMPUTE_ERROR_ON, and ITensorInfo::quantization_info().

220  {
221  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
222  return _parent->quantization_info();
223  }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
virtual QuantizationInfo quantization_info() const =0
Get the quantization settings (scale and offset) of the tensor.

◆ reset_padding()

ITensorInfo& reset_padding ( )
inlineoverridevirtual

Resets the padding settings of the tensor.

Returns
Reference to this ITensorInfo object

Implements ITensorInfo.

Definition at line 108 of file SubTensorInfo.h.

References ARM_COMPUTE_ERROR_ON, and ITensorInfo::reset_padding().

109  {
110  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
111  _parent->reset_padding();
112  return *this;
113  }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
virtual ITensorInfo & reset_padding()=0
Resets the padding settings of the tensor.

◆ set_data_layout()

ITensorInfo& set_data_layout ( const DataLayout data_layout)
inlineoverridevirtual

Set the data layout of the tensor.

Parameters
[in]data_layoutDataLayout containing the layout data information.
Returns
Reference to this ITensorInfo object

Implements ITensorInfo.

Definition at line 82 of file SubTensorInfo.h.

References ARM_COMPUTE_ERROR_ON, and ITensorInfo::set_data_layout().

83  {
84  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
85  _parent->set_data_layout(data_layout);
86  return *this;
87  };
DataLayout data_layout() const override
Get the data layout of the tensor.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
virtual ITensorInfo & set_data_layout(const DataLayout &data_layout)=0
Set the data layout of the tensor.

◆ set_data_type()

ITensorInfo& set_data_type ( DataType  data_type)
inlineoverridevirtual

Set the data type to the specified value.

Warning
This resets the format to UNKNOWN.
Parameters
[in]data_typeThe new data type.
Returns
Reference to this ITensorInfo object

Implements ITensorInfo.

Definition at line 76 of file SubTensorInfo.h.

References ARM_COMPUTE_ERROR_ON, and ITensorInfo::set_data_type().

77  {
78  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
79  _parent->set_data_type(data_type);
80  return *this;
81  };
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
virtual ITensorInfo & set_data_type(DataType data_type)=0
Set the data type to the specified value.
DataType data_type() const override
Data type used for each element of the tensor.

◆ set_format()

ITensorInfo& set_format ( Format  format)
inlineoverridevirtual

Set the format of an already initialized tensor.

Note
If the data type has already been configured (i.e. not UNKNOWN) it must match the new format. If data type hasn't been configured it will be based on the format.
Parameters
[in]formatSingle-plane format of the tensor.
Returns
Reference to this ITensorInfo object

Implements ITensorInfo.

Definition at line 94 of file SubTensorInfo.h.

References ARM_COMPUTE_ERROR_ON, ITensorInfo::set_format(), SubTensorInfo::set_tensor_dims_state(), SubTensorInfo::set_tensor_shape(), and arm_compute::test::validation::shape.

95  {
96  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
97  _parent->set_format(format);
98  return *this;
99  };
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
Format format() const override
Colour format of the image.
virtual ITensorInfo & set_format(Format format)=0
Set the format of an already initialized tensor.

◆ set_is_resizable()

ITensorInfo& set_is_resizable ( bool  is_resizable)
inlineoverridevirtual

Set the flag whether the tensor size can be changed.

Parameters
[in]is_resizableFlag that marks the tensor if it can be changed or not.
Returns
Reference to this ITensorInfo object

Implements ITensorInfo.

Definition at line 199 of file SubTensorInfo.h.

References ARM_COMPUTE_ERROR_ON, and ITensorInfo::set_is_resizable().

200  {
201  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
202  _parent->set_is_resizable(is_resizable);
203  return *this;
204  }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
bool is_resizable() const override
Flag indicating whether the size of the tensor can be changed.
virtual ITensorInfo & set_is_resizable(bool is_resizable)=0
Set the flag whether the tensor size can be changed.

◆ set_num_channels()

ITensorInfo& set_num_channels ( int  num_channels)
inlineoverridevirtual

Set the number of channels to the specified value.

Warning
This resets the format to UNKNOWN.
Parameters
[in]num_channelsNew number of channels.
Returns
Reference to this ITensorInfo object

Implements ITensorInfo.

Definition at line 88 of file SubTensorInfo.h.

References ARM_COMPUTE_ERROR_ON, and ITensorInfo::set_num_channels().

89  {
90  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
92  return *this;
93  };
virtual ITensorInfo & set_num_channels(int num_channels)=0
Set the number of channels to the specified value.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
size_t num_channels() const override
The number of channels for each tensor element.

◆ set_quantization_info()

ITensorInfo& set_quantization_info ( const QuantizationInfo quantization_info)
inlineoverridevirtual

Set the quantization settings (scale and offset) of the tensor.

Parameters
[in]quantization_infoQuantizationInfo containing the scale and offset
Returns
Reference to this ITensorInfo object

Implements ITensorInfo.

Definition at line 102 of file SubTensorInfo.h.

References ARM_COMPUTE_ERROR_ON, and ITensorInfo::set_quantization_info().

103  {
104  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
106  return *this;
107  }
QuantizationInfo quantization_info() const override
Get the quantization settings (scale and offset) of the tensor.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
virtual ITensorInfo & set_quantization_info(const QuantizationInfo &quantization_info)=0
Set the quantization settings (scale and offset) of the tensor.

◆ set_tensor_dims_state()

ITensorInfo & set_tensor_dims_state ( const TensorDimsState state)
override

Definition at line 110 of file SubTensorInfo.cpp.

References ARM_COMPUTE_ERROR_ON.

Referenced by SubTensorInfo::set_format().

111 {
112  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
113  _dims_state = state;
114  return *this;
115 }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466

◆ set_tensor_shape()

ITensorInfo & set_tensor_shape ( const TensorShape shape)
overridevirtual

Set the shape of an already initialized tensor.

Warning
Changing the shape requires to recompute the strides and is therefore only possible if the tensor hasn't been allocated yet.
Parameters
[in]shapeNew tensor shape.
Returns
Reference to this ITensorInfo object

Implements ITensorInfo.

Definition at line 89 of file SubTensorInfo.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBTENSOR, ITensorInfo::data_type(), ITensorInfo::format(), ITensorInfo::set_tensor_shape(), ITensorInfo::set_valid_region(), arm_compute::test::validation::shape, ITensorInfo::tensor_shape(), TensorShape::total_size(), and arm_compute::UNKNOWN.

Referenced by SubTensorInfo::set_format().

90 {
91  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
92 
93  // Check if subtensor is valid if parent is configured
94  if(_parent->tensor_shape().total_size() != 0 && !_extend_parent)
95  {
97  _valid_region = ValidRegion{ _coords, shape };
98  }
99  else if(_extend_parent) // Extend parent shape, configure if specified
100  {
101  ARM_COMPUTE_ERROR_ON((_parent->data_type() == DataType::UNKNOWN) && (_parent->format() == Format::UNKNOWN));
102  TensorShape parent_extended_shape = extend_parent_shape(_parent->tensor_shape(), shape, _coords);
103  _parent->set_tensor_shape(parent_extended_shape);
104  _parent->set_valid_region(ValidRegion{ Coordinates(), parent_extended_shape });
105  }
106  _tensor_shape = shape;
107  return *this;
108 }
virtual ITensorInfo & set_tensor_shape(const TensorShape &shape)=0
Set the shape of an already initialized tensor.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
virtual void set_valid_region(const ValidRegion &valid_region)=0
Set the valid region of the tensor.
virtual Format format() const =0
Colour format of the image.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
size_t total_size() const
Collapses all dimensions to a single linear total size.
Definition: TensorShape.h:172
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBTENSOR(p, c, s)
Definition: Validate.h:959

◆ set_valid_region()

void set_valid_region ( const ValidRegion valid_region)
inlineoverridevirtual

Set the valid region of the tensor.

Parameters
[in]valid_regionValid region to set.

Implements ITensorInfo.

Definition at line 209 of file SubTensorInfo.h.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBTENSOR_VALID_REGION, ITensorInfo::tensor_shape(), TensorShape::total_size(), SubTensorInfo::valid_region(), and ITensorInfo::valid_region().

210  {
211  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
212  // Check if subtensor is valid if parent is configured
213  if(_parent->tensor_shape().total_size() != 0)
214  {
216  }
217  _valid_region = valid_region;
218  }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
virtual ValidRegion valid_region() const =0
Valid region of the tensor.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
ValidRegion valid_region() const override
Valid region of the tensor.
size_t total_size() const
Collapses all dimensions to a single linear total size.
Definition: TensorShape.h:172
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBTENSOR_VALID_REGION(pv, sv)
Definition: Validate.h:976

◆ strides_in_bytes()

const Strides& strides_in_bytes ( ) const
inlineoverridevirtual

The strides in bytes for accessing each dimension of the tensor.

Returns
Strides in bytes for each tensor dimension

Implements ITensorInfo.

Definition at line 129 of file SubTensorInfo.h.

References ARM_COMPUTE_ERROR_ON, and ITensorInfo::strides_in_bytes().

Referenced by SubTensorInfo::offset_element_in_bytes().

130  {
131  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
132  return _parent->strides_in_bytes();
133  }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
virtual const Strides & strides_in_bytes() const =0
The strides in bytes for accessing each dimension of the tensor.

◆ tensor_dims_state()

const TensorDimsState& tensor_dims_state ( ) const
inlineoverridevirtual

State of each dimension of the tensor shape.

Returns
A vector with the state for each dimension of the tensor, where -1 specifies dynamic dimension

Implements ITensorInfo.

Definition at line 159 of file SubTensorInfo.h.

References ARM_COMPUTE_ERROR_ON.

160  {
161  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
162  return _dims_state;
163  }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466

◆ tensor_shape()

const TensorShape& tensor_shape ( ) const
inlineoverridevirtual

Size for each dimension of the tensor.

Returns
A vector with the size for each dimension of the tensor

Implements ITensorInfo.

Definition at line 154 of file SubTensorInfo.h.

References ARM_COMPUTE_ERROR_ON.

Referenced by SubTensorInfo::extend_padding(), and SubTensorInfo::SubTensorInfo().

155  {
156  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
157  return _tensor_shape;
158  }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466

◆ total_size()

size_t total_size ( ) const
inlineoverridevirtual

Returns the total size of the tensor in bytes.

Returns
Total size of the tensor in bytes.

Implements ITensorInfo.

Definition at line 174 of file SubTensorInfo.h.

References ARM_COMPUTE_ERROR_ON, and ITensorInfo::total_size().

175  {
176  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
177  return _parent->total_size();
178  }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
virtual size_t total_size() const =0
Returns the total size of the tensor in bytes.

◆ valid_region()

ValidRegion valid_region ( ) const
inlineoverridevirtual

Valid region of the tensor.

All elements in the valid region have defined values, i.e. are not undefined.

Returns
The valid region.

Implements ITensorInfo.

Definition at line 205 of file SubTensorInfo.h.

Referenced by SubTensorInfo::set_valid_region().

206  {
207  return _valid_region;
208  }

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