Compute Library
 21.02
TensorAccessor< T > Class Template Reference

Tensor accessors to make it easier to interface with arm_gemm. More...

#include <WindowIterator.h>

Public Member Functions

 TensorAccessor (const ITensor &tensor)
 Constructor: More...
 
size_t stride (size_t dim) const
 Get the stride of the dimension dim expressed in number of Ts. More...
 
void set_stride (size_t dim, size_t size)
 Manually set the stride of a dimension. More...
 
void set_strides (const Strides &strides)
 Manually set the strides. More...
 
T * get_ptr (unsigned int x, unsigned int y=0, unsigned int z=0, unsigned int w=0)
 Returns a pointer to the element at coordinates (x,y,z,w) More...
 
T * operator() (unsigned int x, unsigned int y=0, unsigned int z=0, unsigned int w=0)
 Returns a pointer to the element at coordinates (x,y,z,w) More...
 
T * first_element ()
 Returns a pointer to the first element of the tensor. More...
 
T * operator() ()
 Returns a pointer to the first element of the tensor. More...
 

Detailed Description

template<typename T>
class arm_compute::TensorAccessor< T >

Tensor accessors to make it easier to interface with arm_gemm.

Definition at line 56 of file WindowIterator.h.

Constructor & Destructor Documentation

◆ TensorAccessor()

TensorAccessor ( const ITensor tensor)
inline

Constructor:

Parameters
[in]tensorSource tensor, must be allocated.

Definition at line 63 of file WindowIterator.h.

64  : _first(tensor.ptr_to_element(Coordinates())), _strides(tensor.info()->strides_in_bytes())
65  {
66  }

Member Function Documentation

◆ first_element()

T* first_element ( )
inline

Returns a pointer to the first element of the tensor.

Returns
Pointer to the first element.

Definition at line 126 of file WindowIterator.h.

Referenced by TensorAccessor< T >::operator()().

127  {
128  return reinterpret_cast<T *>(_first);
129  }

◆ get_ptr()

T* get_ptr ( unsigned int  x,
unsigned int  y = 0,
unsigned int  z = 0,
unsigned int  w = 0 
)
inline

Returns a pointer to the element at coordinates (x,y,z,w)

Parameters
[in]xX coordinates
[in]y(optional) Y coordinates
[in]z(optional) Z coordinates
[in]w(optional) W coordinates

Definition at line 105 of file WindowIterator.h.

References arm_compute::test::validation::w.

Referenced by TensorAccessor< T >::operator()().

106  {
107  return reinterpret_cast<T *>(_first + x * _strides[0] + y * _strides[1] + z * _strides[2] + w * _strides[3]);
108  }
SimpleTensor< float > w
Definition: DFT.cpp:156

◆ operator()() [1/2]

T* operator() ( unsigned int  x,
unsigned int  y = 0,
unsigned int  z = 0,
unsigned int  w = 0 
)
inline

Returns a pointer to the element at coordinates (x,y,z,w)

Parameters
[in]xX coordinates
[in]y(optional) Y coordinates
[in]z(optional) Z coordinates
[in]w(optional) W coordinates

Definition at line 117 of file WindowIterator.h.

References TensorAccessor< T >::get_ptr(), and arm_compute::test::validation::w.

118  {
119  return get_ptr(x, y, z, w);
120  }
SimpleTensor< float > w
Definition: DFT.cpp:156
T * get_ptr(unsigned int x, unsigned int y=0, unsigned int z=0, unsigned int w=0)
Returns a pointer to the element at coordinates (x,y,z,w)

◆ operator()() [2/2]

T* operator() ( )
inline

Returns a pointer to the first element of the tensor.

Returns
Pointer to the first element.

Definition at line 135 of file WindowIterator.h.

References TensorAccessor< T >::first_element().

136  {
137  return first_element();
138  }
T * first_element()
Returns a pointer to the first element of the tensor.

◆ set_stride()

void set_stride ( size_t  dim,
size_t  size 
)
inline

Manually set the stride of a dimension.

Parameters
[in]dimDimension of the stride to set.
[in]sizeValue to set the stride to (in bytes).

Definition at line 84 of file WindowIterator.h.

85  {
86  _strides[dim] = size;
87  }

◆ set_strides()

void set_strides ( const Strides strides)
inline

Manually set the strides.

Parameters
[in]stridesStrides to set

Definition at line 93 of file WindowIterator.h.

94  {
95  _strides = strides;
96  }

◆ stride()

size_t stride ( size_t  dim) const
inline

Get the stride of the dimension dim expressed in number of Ts.

Parameters
[in]dimDimension of the wanted stride.
Returns
Stride in number of Ts.

Definition at line 73 of file WindowIterator.h.

References ARM_COMPUTE_ERROR_ON.

74  {
75  ARM_COMPUTE_ERROR_ON(_strides[dim] % sizeof(T) != 0);
76  return _strides[dim] / sizeof(T);
77  }
#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

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