Compute Library
 21.05
RawTensor Class Reference

Subclass of SimpleTensor using uint8_t as value type. More...

#include <RawTensor.h>

Collaboration diagram for RawTensor:
[legend]

Public Member Functions

 RawTensor (TensorShape shape, Format format)
 Create an uninitialised tensor of the given shape and format. More...
 
 RawTensor (TensorShape shape, DataType data_type, int num_channels=1)
 Create an uninitialised tensor of the given shape and data type. More...
 
template<typename T >
 RawTensor (SimpleTensor< T > &&tensor)
 Conversion constructor from SimpleTensor. More...
 
template<typename T >
 operator SimpleTensor< T > ()
 Conversion operator to SimpleTensor. More...
 
 RawTensor (const RawTensor &tensor)
 Create a deep copy of the given tensor. More...
 
RawTensoroperator= (RawTensor tensor)
 Copy the given tensor. More...
 
 RawTensor (RawTensor &&)=default
 Allow instances of this class to be move constructed. More...
 
 ~RawTensor ()=default
 Default destructor. More...
 
const void * operator() (const Coordinates &coord) const override
 Read only access to the specified element. More...
 
void * operator() (const Coordinates &coord) override
 Access to the specified element. More...
 
- Public Member Functions inherited from SimpleTensor< uint8_t >
 SimpleTensor ()=default
 Create an uninitialised tensor. More...
 
 SimpleTensor (TensorShape shape, Format format)
 Create an uninitialised tensor of the given shape and format. More...
 
 SimpleTensor (TensorShape shape, DataType data_type, int num_channels=1, QuantizationInfo quantization_info=QuantizationInfo(), DataLayout data_layout=DataLayout::NCHW)
 Create an uninitialised tensor of the given shape and data type. More...
 
 SimpleTensor (const SimpleTensor &tensor)
 Create a deep copy of the given tensor. More...
 
 SimpleTensor (SimpleTensor &&)=default
 Allow instances of this class to be move constructed. More...
 
SimpleTensoroperator= (SimpleTensor tensor)
 Create a deep copy of the given tensor. More...
 
 ~SimpleTensor ()=default
 Default destructor. More...
 
uint8_t & operator[] (size_t offset)
 Return value at offset in the buffer. More...
 
const uint8_t & operator[] (size_t offset) const
 Return constant value at offset in the buffer. More...
 
TensorShape shape () const override
 Shape of the tensor. More...
 
size_t element_size () const override
 Size of each element in the tensor in bytes. More...
 
size_t size () const override
 Total size of the tensor in bytes. More...
 
Format format () const override
 Image format of the tensor. More...
 
DataLayout data_layout () const override
 Data layout of the tensor. More...
 
DataType data_type () const override
 Data type of the tensor. More...
 
int num_channels () const override
 Number of channels of the tensor. More...
 
int num_elements () const override
 Number of elements of the tensor. More...
 
PaddingSize padding () const override
 Available padding around the tensor. More...
 
QuantizationInfo quantization_info () const override
 Quantization info in case of asymmetric quantized type. More...
 
const uint8_t * data () const
 Constant pointer to the underlying buffer. More...
 
uint8_t * data ()
 Pointer to the underlying buffer. More...
 
const void * operator() (const Coordinates &coord) const override
 Read only access to the specified element. More...
 
void * operator() (const Coordinates &coord) override
 Access to the specified element. More...
 
- Public Member Functions inherited from IAccessor
virtual ~IAccessor ()=default
 Virtual destructor. More...
 

Additional Inherited Members

- Public Types inherited from SimpleTensor< uint8_t >
using value_type = uint8_t
 Tensor value type. More...
 
using Buffer = std::unique_ptr< value_type[]>
 Tensor buffer pointer type. More...
 

Detailed Description

Subclass of SimpleTensor using uint8_t as value type.

Access operations (except for operator[]) will be based on the data type to copy the right number of elements.

Definition at line 38 of file RawTensor.h.

Constructor & Destructor Documentation

◆ RawTensor() [1/5]

RawTensor ( TensorShape  shape,
Format  format 
)

Create an uninitialised tensor of the given shape and format.

Parameters
[in]shapeShape of the new raw tensor.
[in]formatFormat of the new raw tensor.

Definition at line 30 of file RawTensor.cpp.

32 {
33  _buffer = std::make_unique<uint8_t[]>(SimpleTensor::num_elements() * SimpleTensor::num_channels() * SimpleTensor::element_size());
34 }
size_t element_size() const override
Size of each element in the tensor in bytes.
Definition: SimpleTensor.h:326
Format format() const override
Image format of the tensor.
Definition: SimpleTensor.h:345
TensorShape shape() const override
Shape of the tensor.
Definition: SimpleTensor.h:320
SimpleTensor()=default
Create an uninitialised tensor.
int num_channels() const override
Number of channels of the tensor.
Definition: SimpleTensor.h:370
int num_elements() const override
Number of elements of the tensor.
Definition: SimpleTensor.h:406

References SimpleTensor< T >::element_size(), SimpleTensor< T >::num_channels(), and SimpleTensor< T >::num_elements().

◆ RawTensor() [2/5]

RawTensor ( TensorShape  shape,
DataType  data_type,
int  num_channels = 1 
)

Create an uninitialised tensor of the given shape and data type.

Parameters
[in]shapeShape of the new raw tensor.
[in]data_typeData type of the new raw tensor.
[in]num_channels(Optional) Number of channels (default = 1).

Definition at line 36 of file RawTensor.cpp.

38 {
39  _buffer = std::make_unique<uint8_t[]>(SimpleTensor::num_elements() * SimpleTensor::num_channels() * SimpleTensor::element_size());
40 }
size_t element_size() const override
Size of each element in the tensor in bytes.
Definition: SimpleTensor.h:326
DataType data_type() const override
Data type of the tensor.
Definition: SimpleTensor.h:357
TensorShape shape() const override
Shape of the tensor.
Definition: SimpleTensor.h:320
SimpleTensor()=default
Create an uninitialised tensor.
int num_channels() const override
Number of channels of the tensor.
Definition: SimpleTensor.h:370
int num_elements() const override
Number of elements of the tensor.
Definition: SimpleTensor.h:406

References SimpleTensor< T >::element_size(), SimpleTensor< T >::num_channels(), and SimpleTensor< T >::num_elements().

◆ RawTensor() [3/5]

RawTensor ( SimpleTensor< T > &&  tensor)
inline

Conversion constructor from SimpleTensor.

The passed SimpleTensor will be destroyed after it has been converted to a RawTensor.

Parameters
[in,out]tensorSimpleTensor to be converted to a RawTensor.

Definition at line 64 of file RawTensor.h.

65  {
66  _buffer = std::unique_ptr<uint8_t[]>(reinterpret_cast<uint8_t *>(tensor._buffer.release()));
67  _shape = std::move(tensor._shape);
68  _format = tensor._format;
69  _data_type = tensor._data_type;
70  _num_channels = tensor._num_channels;
71  _data_layout = tensor._data_layout;
72  }

◆ RawTensor() [4/5]

RawTensor ( const RawTensor tensor)

Create a deep copy of the given tensor.

Parameters
[in]tensorTo be copied tensor.

Definition at line 42 of file RawTensor.cpp.

43  : SimpleTensor(tensor.shape(), tensor.data_type(), tensor.num_channels())
44 {
45  _format = tensor.format();
46  _buffer = std::make_unique<uint8_t[]>(num_elements() * num_channels() * element_size());
47  std::copy_n(tensor.data(), num_elements() * num_channels() * element_size(), _buffer.get());
48 }
size_t element_size() const override
Size of each element in the tensor in bytes.
Definition: SimpleTensor.h:326
SimpleTensor()=default
Create an uninitialised tensor.
int num_channels() const override
Number of channels of the tensor.
Definition: SimpleTensor.h:370
int num_elements() const override
Number of elements of the tensor.
Definition: SimpleTensor.h:406

References SimpleTensor< T >::data(), SimpleTensor< uint8_t >::element_size(), SimpleTensor< T >::format(), SimpleTensor< uint8_t >::num_channels(), and SimpleTensor< uint8_t >::num_elements().

◆ RawTensor() [5/5]

RawTensor ( RawTensor &&  )
default

Allow instances of this class to be move constructed.

◆ ~RawTensor()

~RawTensor ( )
default

Default destructor.

Member Function Documentation

◆ operator SimpleTensor< T >()

operator SimpleTensor< T > ( )
inline

Conversion operator to SimpleTensor.

The current RawTensor must not be used after the conversion.

Returns
SimpleTensor of the given type.

Definition at line 81 of file RawTensor.h.

82  {
83  SimpleTensor<T> cast;
84  cast._buffer = std::unique_ptr<T[]>(reinterpret_cast<T *>(_buffer.release()));
85  cast._shape = std::move(_shape);
86  cast._format = _format;
87  cast._data_type = _data_type;
88  cast._num_channels = _num_channels;
89  cast._data_layout = _data_layout;
90 
91  return cast;
92  }

◆ operator()() [1/2]

const void * operator() ( const Coordinates coord) const
overridevirtual

Read only access to the specified element.

Parameters
[in]coordCoordinates of the desired element.
Returns
A pointer to the desired element.

Implements IAccessor.

Definition at line 57 of file RawTensor.cpp.

58 {
59  return _buffer.get() + coord2index(_shape, coord) * element_size();
60 }
size_t element_size() const override
Size of each element in the tensor in bytes.
Definition: SimpleTensor.h:326
int coord2index(const TensorShape &shape, const Coordinates &coord)
Linearise the given coordinate.
Definition: Utils.h:387

References arm_compute::test::coord2index(), and SimpleTensor< uint8_t >::element_size().

◆ operator()() [2/2]

void * operator() ( const Coordinates coord)
overridevirtual

Access to the specified element.

Parameters
[in]coordCoordinates of the desired element.
Returns
A pointer to the desired element.

Implements IAccessor.

Definition at line 62 of file RawTensor.cpp.

63 {
64  return _buffer.get() + coord2index(_shape, coord) * element_size();
65 }
size_t element_size() const override
Size of each element in the tensor in bytes.
Definition: SimpleTensor.h:326
int coord2index(const TensorShape &shape, const Coordinates &coord)
Linearise the given coordinate.
Definition: Utils.h:387

References arm_compute::test::coord2index(), and SimpleTensor< uint8_t >::element_size().

◆ operator=()

RawTensor & operator= ( RawTensor  tensor)

Copy the given tensor.

Parameters
[in]tensorTo be copied tensor.
Returns
a copy of the given tensor.

Definition at line 50 of file RawTensor.cpp.

51 {
52  swap(*this, tensor);
53 
54  return *this;
55 }
friend void swap(SimpleTensor< U > &tensor1, SimpleTensor< U > &tensor2)
Swaps the content of the provided tensors.
Definition: SimpleTensor.h:442

References SimpleTensor< uint8_t >::swap.


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