Compute Library
 21.08
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 size_t 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 46 of file Helpers.h.

Constructor & Destructor Documentation

◆ Iterator() [1/2]

constexpr Iterator ( )
inline

Default constructor to create an empty iterator.

Definition at line 90 of file Helpers.inl.

91  : _ptr(nullptr), _dims()
92 {
93 }

◆ 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 95 of file Helpers.inl.

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.

96  : Iterator()
97 {
98  ARM_COMPUTE_ERROR_ON(tensor == nullptr);
99  ARM_COMPUTE_ERROR_ON(tensor->info() == nullptr);
100 
101  const ITensorInfo *info = tensor->info();
102  const Strides &strides = info->strides_in_bytes();
103 
104  _ptr = tensor->buffer() + info->offset_first_element_in_bytes();
105 
106  //Initialize the stride for each dimension and calculate the position of the first element of the iteration:
107  for(unsigned int n = 0; n < info->num_dimensions(); ++n)
108  {
109  _dims[n]._stride = win[n].step() * strides[n];
110  std::get<0>(_dims)._dim_start += static_cast<size_t>(strides[n]) * win[n].start();
111  }
112 
113  //Copy the starting point to all the dimensions:
114  for(unsigned int n = 1; n < Coordinates::num_max_dimensions; ++n)
115  {
116  _dims[n]._dim_start = std::get<0>(_dims)._dim_start;
117  }
118 
119  ARM_COMPUTE_ERROR_ON_WINDOW_DIMENSIONS_GTE(win, info->num_dimensions());
120 }
#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
#define ARM_COMPUTE_ERROR_ON_WINDOW_DIMENSIONS_GTE(w, md)
Definition: Validate.h:259
constexpr Iterator()
Default constructor to create an empty iterator.
Definition: Helpers.inl:90
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
Definition: Dimensions.h:46

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 122 of file Helpers.inl.

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

123 {
125 
126  _dims[dimension]._dim_start += _dims[dimension]._stride;
127 
128  for(unsigned int n = 0; n < dimension; ++n)
129  {
130  _dims[n]._dim_start = _dims[dimension]._dim_start;
131  }
132 }
#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:46

◆ offset()

constexpr size_t 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 134 of file Helpers.inl.

Referenced by arm_compute::cpu::poolingMxN_q8_neon_nhwc(), CpuFillKernel::run_op(), CpuConcatenateWidthKernel::run_op(), CpuConcatenateHeightKernel::run_op(), and NEFillBorderKernel::run_op().

135 {
136  return _dims.at(0)._dim_start;
137 }

◆ 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 139 of file Helpers.inl.

Referenced by arm_compute::cpu::add_qasymm8_neon(), arm_compute::cpu::add_qasymm8_signed_neon(), arm_compute::cpu::add_qsymm16_neon(), arm_compute::cpu::add_same_neon(), arm_compute::cpu::bilinear_neon_scale(), 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(), CpuScaleKernel::configure(), NENormalizationLayerKernel::configure(), NEMaxUnpoolingLayerKernel::configure(), NERemapKernel::configure(), ITensor::copy_from(), arm_compute::cpu::elementwise_comp_quantized_signed(), arm_compute::cpu::elementwise_op(), arm_compute::cpu::elementwise_op_quantized(), arm_compute::cpu::elementwise_op_quantized_signed(), arm_compute::utils::fill_random_tensor(), arm_compute::utils::fill_tensor_value(), arm_compute::utils::fill_tensor_vector(), arm_compute::cpu::fp32_neon_activation(), arm_compute::utils::load_trained_data(), arm_compute::cpu::nearest_neon_scale(), NEGatherKernel::NEGatherKernel(), arm_compute::cpu::neon_logits_1d_max(), arm_compute::cpu::neon_softmax_logits_1d_float(), arm_compute::cpu::neon_softmax_logits_1d_quantized(), arm_compute::cpu::poolingMxN_fp32_neon_nhwc(), arm_compute::cpu::poolingMxN_q8_neon_nhwc(), arm_compute::cpu::qasymm8_neon_activation(), arm_compute::cpu::qasymm8_signed_neon_activation(), arm_compute::cpu::qsymm16_neon_activation(), CLMinMaxLayerKernel::reset(), NEMinMaxLayerKernel::reset(), CPPUpsampleKernel::run(), NEBitwiseNotKernel::run(), NEBitwiseOrKernel::run(), NEBitwiseAndKernel::run(), NEBitwiseXorKernel::run(), NETileKernel::run(), NEDepthToSpaceLayerKernel::run(), NESpaceToDepthLayerKernel::run(), NEFFTScaleKernel::run(), NEReorgLayerKernel::run(), NEMinMaxLayerKernel::run(), NEFFTRadixStageKernel::run(), NEStackLayerKernel::run(), NEBatchToSpaceLayerKernel::run(), NESpaceToBatchLayerKernel::run(), CpuConvertQuantizedSignednessKernel::run_op(), CpuCopyKernel::run_op(), CpuConcatenateHeightKernel::run_op(), CpuConcatenateWidthKernel::run_op(), CpuFloorKernel::run_op(), CpuConvertFullyConnectedWeightsKernel::run_op(), CpuCastKernel::run_op(), CpuGemmInterleave4x4Kernel::run_op(), CpuCol2ImKernel::run_op(), NEFillBorderKernel::run_op(), CpuWeightsReshapeKernel::run_op(), CpuGemmTranspose1xWKernel::run_op(), arm_compute::run_reverse(), arm_compute::utils::save_to_npy(), arm_compute::utils::save_to_ppm(), arm_compute::cpu::sub_qasymm8_neon(), arm_compute::cpu::sub_qasymm8_signed_neon(), arm_compute::cpu::sub_qsymm16_neon(), arm_compute::cpu::sub_same_neon(), arm_compute::test::validation::TEST_CASE(), CpuQuantizeKernel::validate(), CpuGemmLowpMatrixAReductionKernel::validate(), NEComputeAllAnchorsKernel::validate(), NEFFTDigitReverseKernel::validate(), NEBoundingBoxTransformKernel::validate(), and CpuGemmLowpMatrixBReductionKernel::validate().

140 {
141  return _ptr + _dims.at(0)._dim_start;
142 }

◆ 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 144 of file Helpers.inl.

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

145 {
147 
148  _dims[dimension]._dim_start = _dims[dimension + 1]._dim_start;
149 
150  for(unsigned int n = 0; n < dimension; ++n)
151  {
152  _dims[n]._dim_start = _dims[dimension]._dim_start;
153  }
154 }
#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:46

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