Compute Library
 20.02.1
Iterator Class Reference

Iterator updated by execute_window_loop for each window element. More...

#include <Helpers.h>

Public Member Functions

constexpr Iterator ()
 Default constructor to create an empty iterator. More...
 
 Iterator (const ITensor *tensor, const Window &window)
 Create a container iterator for the metadata and allocation contained in the ITensor. More...
 
void increment (size_t dimension)
 Increment the iterator along the specified dimension of the step value associated to the dimension. More...
 
constexpr int offset () const
 Return the offset in bytes from the first element to the current position of the iterator. More...
 
constexpr uint8_t * ptr () const
 Return a pointer to the current pixel. More...
 
void reset (size_t dimension)
 Move the iterator back to the beginning of the specified dimension. More...
 

Detailed Description

Iterator updated by execute_window_loop for each window element.

Definition at line 318 of file Helpers.h.

Constructor & Destructor Documentation

◆ Iterator() [1/2]

constexpr Iterator ( )
inline

Default constructor to create an empty iterator.

Definition at line 136 of file Helpers.inl.

137  : _ptr(nullptr), _dims()
138 {
139 }

◆ Iterator() [2/2]

Iterator ( const ITensor tensor,
const Window window 
)
inline

Create a container iterator for the metadata and allocation contained in the ITensor.

Parameters
[in]tensorThe tensor to associate to the iterator.
[in]windowThe window which will be used to iterate over the tensor.

Definition at line 141 of file Helpers.inl.

142  : Iterator()
143 {
144  ARM_COMPUTE_ERROR_ON(tensor == nullptr);
145  ARM_COMPUTE_ERROR_ON(tensor->info() == nullptr);
146 
147  const ITensorInfo *info = tensor->info();
148  const Strides &strides = info->strides_in_bytes();
149 
150  _ptr = tensor->buffer() + info->offset_first_element_in_bytes();
151 
152  //Initialize the stride for each dimension and calculate the position of the first element of the iteration:
153  for(unsigned int n = 0; n < info->num_dimensions(); ++n)
154  {
155  _dims[n]._stride = win[n].step() * strides[n];
156  std::get<0>(_dims)._dim_start += strides[n] * win[n].start();
157  }
158 
159  //Copy the starting point to all the dimensions:
160  for(unsigned int n = 1; n < Coordinates::num_max_dimensions; ++n)
161  {
162  _dims[n]._dim_start = std::get<0>(_dims)._dim_start;
163  }
164 
165  ARM_COMPUTE_ERROR_ON_WINDOW_DIMENSIONS_GTE(win, info->num_dimensions());
166 }
#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
constexpr Iterator()
Default constructor to create an empty iterator.
Definition: Helpers.inl:136
#define ARM_COMPUTE_ERROR_ON_WINDOW_DIMENSIONS_GTE(w, md)
Definition: Validate.h:263
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
Definition: Dimensions.h:45

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_WINDOW_DIMENSIONS_GTE, ITensor::buffer(), ITensor::info(), arm_compute::test::validation::info, and Dimensions< int >::num_max_dimensions.

Member Function Documentation

◆ increment()

void increment ( size_t  dimension)
inline

Increment the iterator along the specified dimension of the step value associated to the dimension.

Warning
It is the caller's responsibility to call increment(dimension+1) when reaching the end of a dimension, the iterator will not check for overflow.
Note
When incrementing a dimension 'n' the coordinates of all the dimensions in the range (0,n-1) are reset. For example if you iterate over a 2D image, everytime you change row (dimension 1), the iterator for the width (dimension 0) is reset to its start.
Parameters
[in]dimensionDimension to increment

Definition at line 168 of file Helpers.inl.

169 {
171 
172  _dims[dimension]._dim_start += _dims[dimension]._stride;
173 
174  for(unsigned int n = 0; n < dimension; ++n)
175  {
176  _dims[n]._dim_start = _dims[dimension]._dim_start;
177  }
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
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
Definition: Dimensions.h:45

References ARM_COMPUTE_ERROR_ON, and Dimensions< int >::num_max_dimensions.

Referenced by NEGaussianPyramidVertKernel::run().

◆ offset()

constexpr int offset ( ) const
inline

Return the offset in bytes from the first element to the current position of the iterator.

Returns
The current position of the iterator in bytes relative to the first element.

Definition at line 180 of file Helpers.inl.

181 {
182  return _dims.at(0)._dim_start;
183 }

Referenced by NEIntegralImageKernel::run(), NEMemsetKernel::run(), NEWidthConcatenateLayerKernel::run(), NEHeightConcatenateLayerKernel::run(), NEGaussianPyramidVertKernel::run(), and NESobel5x5VertKernel::run().

◆ ptr()

constexpr uint8_t * ptr ( ) const
inline

Return a pointer to the current pixel.

Warning
Only works if the iterator was created with an ITensor.
Returns
equivalent to buffer() + offset()

Definition at line 185 of file Helpers.inl.

186 {
187  return _ptr + _dims.at(0)._dim_start;
188 }

Referenced by arm_compute::colorconvert_rgb_to_iyuv(), arm_compute::colorconvert_rgb_to_nv12(), arm_compute::colorconvert_rgb_to_rgbx(), arm_compute::colorconvert_rgb_to_u8(), arm_compute::colorconvert_rgb_to_yuv4(), arm_compute::colorconvert_rgbx_to_rgb(), arm_compute::colorconvert_yuyv_to_iyuv(), arm_compute::colorconvert_yuyv_to_nv12(), arm_compute::colorconvert_yuyv_to_rgb(), arm_compute::utils::compare_tensor(), ITensor::copy_from(), IImageLoader::fill_image(), IImageLoader::fill_planar_tensor(), arm_compute::utils::fill_random_tensor(), CPPFlipWeightsKernel::flip_weights(), arm_compute::utils::load_trained_data(), CLMinMaxLayerKernel::reset(), NEMinMaxLayerKernel::reset(), NEIntegralImageKernel::run(), NEMedian3x3Kernel::run(), NEGaussian3x3Kernel::run(), NEGaussian5x5HorKernel::run(), NEAccumulateKernel::run(), NEFloorKernel::run(), NEGaussianPyramidHorKernel::run(), CPPUpsampleKernel::run(), NEGEMMMatrixAccumulateBiasesKernel::run(), NENonMaximaSuppression3x3Kernel::run(), NESobel5x5HorKernel::run(), NESobel7x7HorKernel::run(), NEGradientKernel::run(), NEConvertQuantizedSignednessKernel::run(), NETileKernel::run(), NECopyKernel::run(), NEDepthToSpaceLayerKernel::run(), NESpaceToDepthLayerKernel::run(), NEFFTScaleKernel::run(), NESobel3x3Kernel::run(), NEScharr3x3Kernel::run(), NEReorgLayerKernel::run(), NEGaussian5x5VertKernel::run(), NEMinMaxLayerKernel::run(), NEFFTRadixStageKernel::run(), NEStackLayerKernel::run(), NEDepthConvertLayerKernel::run(), NEAccumulateWeightedKernel::run(), NEBatchToSpaceLayerKernel::run(), NEGEMMTranspose1xWKernel::run(), NESpaceToBatchLayerKernel::run(), NEGaussianPyramidVertKernel::run(), NEWeightsReshapeKernel::run(), NESobel5x5VertKernel::run(), NESobel7x7VertKernel::run(), NEAccumulateSquaredKernel::run(), arm_compute::run_reverse(), and arm_compute::test::validation::TEST_CASE().

◆ reset()

void reset ( size_t  dimension)
inline

Move the iterator back to the beginning of the specified dimension.

Parameters
[in]dimensionDimension to reset

Definition at line 190 of file Helpers.inl.

191 {
193 
194  _dims[dimension]._dim_start = _dims[dimension + 1]._dim_start;
195 
196  for(unsigned int n = 0; n < dimension; ++n)
197  {
198  _dims[n]._dim_start = _dims[dimension]._dim_start;
199  }
200 }
#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
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
Definition: Dimensions.h:45

References ARM_COMPUTE_ERROR_ON, and Dimensions< int >::num_max_dimensions.


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