Compute Library
 23.05
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...
 
 Iterator (size_t num_dims, const Strides &strides, uint8_t *buffer, size_t offset, const Window &window)
 Create a container iterator for the tensor with the specified number of dimensions, stride, buffer pointer and window. 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/3]

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/3]

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, ITensor::buffer(), ITensor::info(), ITensorInfo::num_dimensions(), ITensorInfo::offset_first_element_in_bytes(), and ITensorInfo::strides_in_bytes().

96  : Iterator()
97 {
98  ARM_COMPUTE_ERROR_ON(tensor == nullptr);
99  ARM_COMPUTE_ERROR_ON(tensor->info() == nullptr);
100 
101  initialize(tensor->info()->num_dimensions(), tensor->info()->strides_in_bytes(), tensor->buffer(), tensor->info()->offset_first_element_in_bytes(), win);
102 }
#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:90
CLTensor * tensor
Pointer to the auxiliary tensor.

◆ Iterator() [3/3]

Iterator ( size_t  num_dims,
const Strides strides,
uint8_t *  buffer,
size_t  offset,
const Window window 
)
inline

Create a container iterator for the tensor with the specified number of dimensions, stride, buffer pointer and window.

Parameters
[in]num_dimsThe number of dimensions.
[in]stridesThe strides in bytes.
[in]bufferThe data buffer.
[in]offsetThe offset in bytes from the beginning of the buffer to the first element of the tensor.
[in]windowThe window which will be used to iterate over the tensor.

Definition at line 104 of file Helpers.inl.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_WINDOW_DIMENSIONS_GTE, arm_compute::test::validation::n, Dimensions< int >::num_max_dimensions, and Iterator::offset().

105  : Iterator()
106 {
107  initialize(num_dims, strides, buffer, offset, win);
108 }
constexpr Iterator()
Default constructor to create an empty iterator.
Definition: Helpers.inl:90
constexpr size_t offset() const
Return the offset in bytes from the first element to the current position of the iterator.
Definition: Helpers.inl:144

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

References ARM_COMPUTE_ERROR_ON, arm_compute::test::validation::n, and Dimensions< int >::num_max_dimensions.

133 {
135 
136  _dims[dimension]._dim_start += _dims[dimension]._stride;
137 
138  for(unsigned int n = 0; n < dimension; ++n)
139  {
140  _dims[n]._dim_start = _dims[dimension]._dim_start;
141  }
142 }
#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 144 of file Helpers.inl.

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

145 {
146  return _dims.at(0)._dim_start;
147 }

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

Referenced by arm_compute::cpu::add_qasymm8_signed_sve2(), arm_compute::cpu::add_qasymm8_sve2(), arm_compute::cpu::add_qsymm16_neon(), arm_compute::cpu::add_qsymm16_sve2(), arm_compute::cpu::add_same_neon(), arm_compute::cpu::add_same_sve(), arm_compute::cpu::add_sub_q8_neon_fixedpoint(), arm_compute::cpu::add_sub_qasymm8_neon(), arm_compute::cpu::add_sub_qasymm8_signed_neon(), arm_compute::cpu::avg_poolingMxNxD_q8_neon_ndhwc(), arm_compute::cpu::bilinear_neon_scale(), arm_compute::cpu::bounding_box_transform(), arm_compute::cpu::bounding_box_transform_qsymm16(), 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(), arm_compute::cpu::compute_all_anchors(), arm_compute::cpu::compute_all_anchors_qasymm16(), CpuScaleKernel::configure(), NENormalizationLayerKernel::configure(), arm_compute::cpu::kernels::convolve_nchw(), arm_compute::cpu::kernels::convolve_nhwc(), ITensor::copy_from(), arm_compute::cpu::directconv3d_float_neon_ndhwc(), arm_compute::cpu::directconv3d_quantized_neon_ndhwc(), arm_compute::cpu::elementwise_arithmetic_op(), arm_compute::cpu::elementwise_arithmetic_quantized_op(), arm_compute::cpu::elementwise_comp_quantized_signed(), arm_compute::cpu::elementwise_comparison_op(), arm_compute::cpu::elementwise_comparison_quantized_op(), arm_compute::cpu::elementwise_op(), arm_compute::cpu::elementwise_op< int8_t >(), arm_compute::cpu::elementwise_op< uint8_t >(), arm_compute::cpu::elementwise_op_quantized(), arm_compute::cpu::elementwise_op_quantized_signed(), arm_compute::cpu::elementwise_sve_op(), arm_compute::utils::fill_random_tensor(), arm_compute::utils::fill_tensor_value(), arm_compute::utils::fill_tensor_vector(), arm_compute::cpu::fp_neon_activation_impl(), arm_compute::cpu::fused_batch_normalization_conv(), arm_compute::cpu::fused_batch_normalization_dwc_nchw(), arm_compute::cpu::fused_batch_normalization_dwc_nhwc(), arm_compute::cpu::instance_normalization_nchw(), arm_compute::cpu::l2_normalize_x(), arm_compute::cpu::l2_normalize_yz(), arm_compute::utils::load_trained_data(), arm_compute::cpu::matrix_addition_f32(), arm_compute::cpu::matrix_matrix_multiply_f32(), arm_compute::cpu::max_poolingMxNxD_q8_neon_ndhwc(), arm_compute::cpu::max_unpooling(), arm_compute::cpu::mean_stddev_normalization(), arm_compute::cpu::nearest_neon_scale(), arm_compute::cpu::neon_logits_1d_max(), arm_compute::cpu::neon_qasymm8_activation(), arm_compute::cpu::neon_qasymm8_meanstddevnorm(), arm_compute::cpu::neon_qasymm8_signed_activation(), arm_compute::cpu::neon_qsymm16_activation(), arm_compute::cpu::neon_range_function(), 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_fp32_neon_nhwc_kernel_indices(), arm_compute::cpu::poolingMxN_q8_neon_nhwc(), CPPUpsampleKernel::run(), NEBitwiseNotKernel::run(), NEBitwiseXorKernel::run(), NEBitwiseAndKernel::run(), NEBitwiseOrKernel::run(), NETileKernel::run(), NESpaceToDepthLayerKernel::run(), NEDepthToSpaceLayerKernel::run(), NEFFTScaleKernel::run(), NEReorgLayerKernel::run(), NEFFTRadixStageKernel::run(), NEStackLayerKernel::run(), NEBatchToSpaceLayerKernel::run(), NESpaceToBatchLayerKernel::run(), CpuConvertQuantizedSignednessKernel::run_op(), CpuCopyKernel::run_op(), CpuConcatenateHeightKernel::run_op(), CpuConcatenateWidthKernel::run_op(), CpuConvertFullyConnectedWeightsKernel::run_op(), CpuFloorKernel::run_op(), CpuGemmInterleave4x4Kernel::run_op(), CpuCastKernel::run_op(), CpuCol2ImKernel::run_op(), NEFillBorderKernel::run_op(), CpuWeightsReshapeKernel::run_op(), CpuGemmTranspose1xWKernel::run_op(), NEStridedSliceKernel::run_op(), arm_compute::run_reverse(), arm_compute::utils::save_to_npy(), arm_compute::utils::save_to_ppm(), arm_compute::cpu::select_op(), arm_compute::cpu::sub_qsymm16_neon(), arm_compute::cpu::sub_same_neon(), arm_compute::cpu::sve2_q8_elementwise_unary(), arm_compute::cpu::sve2_qasymm8_activation(), arm_compute::cpu::sve2_qasymm8_signed_activation(), arm_compute::cpu::sve2_qsymm16_activation(), arm_compute::cpu::sve2_softmax_logits_1d_quantized(), arm_compute::cpu::sve_fp32_activation(), arm_compute::cpu::sve_logits_1d_max(), arm_compute::cpu::sve_softmax_logits_1d_float(), arm_compute::test::validation::TEST_CASE(), CpuQuantizeKernel::validate(), CpuGemmLowpMatrixAReductionKernel::validate(), NEFFTDigitReverseKernel::validate(), CpuGemmLowpMatrixBReductionKernel::validate(), and arm_compute::cpu::vector_matrix_multiply_f32().

150 {
151  return _ptr + _dims.at(0)._dim_start;
152 }

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

References ARM_COMPUTE_ERROR_ON, arm_compute::test::validation::n, and Dimensions< int >::num_max_dimensions.

155 {
157 
158  _dims[dimension]._dim_start = _dims[dimension + 1]._dim_start;
159 
160  for(unsigned int n = 0; n < dimension; ++n)
161  {
162  _dims[n]._dim_start = _dims[dimension]._dim_start;
163  }
164 }
#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: