cartobase  5.0.5
carto::NDIterator< T > Class Template Reference

N-dimensional array iterator. More...

#include <cartobase/containers/nditerator.h>

Inheritance diagram for carto::NDIterator< T >:
Collaboration diagram for carto::NDIterator< T >:

Public Member Functions

 NDIterator (T *buffer, const std::vector< int > &dims)
 
 NDIterator (T *buffer, const std::vector< int > &dims, const std::vector< int > &strides)
 
 NDIterator (T *buffer, const std::vector< int > &dims, const std::vector< size_t > &strides)
 
 NDIterator (T *buffer, const std::vector< int > &dims, const std::vector< long > &strides)
 
T & operator* () const
 
- Public Member Functions inherited from carto::NDIterator_base
 NDIterator_base (const std::vector< int > &dims)
 
 NDIterator_base (const std::vector< int > &dims, const std::vector< int > &strides)
 
 NDIterator_base (const std::vector< int > &dims, const std::vector< size_t > &strides)
 
 NDIterator_base (const std::vector< int > &dims, const std::vector< long > &strides)
 
const std::vector< int > & position () const
 
uint64_t offset () const
 
NDIterator_baseoperator++ ()
 
bool ended () const
 
void reset ()
 

Protected Attributes

T * _buffer
 
- Protected Attributes inherited from carto::NDIterator_base
std::vector< int > _dims
 
std::vector< size_t > _strides
 
std::vector< int > _position
 
uint64_t _offset
 
bool _ended
 

Additional Inherited Members

- Static Protected Member Functions inherited from carto::NDIterator_base
template<typename T >
static std::vector< size_t > to_int_v (const std::vector< T > &v)
 

Detailed Description

template<typename T>
class carto::NDIterator< T >

N-dimensional array iterator.

Iterates over every element of a N-D array, using strides. The iterator is used more or less like a pointer:

float *data; // fill it...
std::vector<int> dimensions;
std::vector<int> strdes;
// fill dimensions and strides...
float sum = 0.;
NDIterator<float> it( data, dimensions, strides );
for( ; !it.ended(); ++it )
sum += *it;

Note that the NDIterator is somewhat sub-optimal since it has to test, at each increment, the bounds of each dimension. In many cases it is possible to lowerage the overhead by implementing an ad-hoc loop for the smallest dimension, and using a line_NDIterator on higher dimensions.

Definition at line 118 of file nditerator.h.

Constructor & Destructor Documentation

◆ NDIterator() [1/4]

template<typename T >
carto::NDIterator< T >::NDIterator ( T *  buffer,
const std::vector< int > &  dims 
)
inline

Definition at line 395 of file nditerator.h.

◆ NDIterator() [2/4]

template<typename T >
carto::NDIterator< T >::NDIterator ( T *  buffer,
const std::vector< int > &  dims,
const std::vector< int > &  strides 
)
inline

Definition at line 402 of file nditerator.h.

◆ NDIterator() [3/4]

template<typename T >
carto::NDIterator< T >::NDIterator ( T *  buffer,
const std::vector< int > &  dims,
const std::vector< size_t > &  strides 
)
inline

Definition at line 410 of file nditerator.h.

◆ NDIterator() [4/4]

template<typename T >
carto::NDIterator< T >::NDIterator ( T *  buffer,
const std::vector< int > &  dims,
const std::vector< long > &  strides 
)
inline

Definition at line 418 of file nditerator.h.

Member Function Documentation

◆ operator*()

template<typename T >
T & carto::NDIterator< T >::operator* ( ) const
inline

Member Data Documentation

◆ _buffer

template<typename T >
T* carto::NDIterator< T >::_buffer
protected

Definition at line 133 of file nditerator.h.

Referenced by carto::NDIterator< T >::operator*().


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