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

N-dimensional array line iterator. More...

#include <cartobase/containers/nditerator.h>

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

Public Member Functions

 line_NDIterator (T *buffer, const std::vector< int > &dims)
 
 line_NDIterator (T *buffer, const std::vector< int > &dims, const std::vector< int > &strides)
 
 line_NDIterator (T *buffer, const std::vector< int > &dims, const std::vector< size_t > &strides)
 
 line_NDIterator (T *buffer, const std::vector< int > &dims, const std::vector< long > &strides)
 
T & operator* () const
 
- Public Member Functions inherited from carto::line_NDIterator_base
 line_NDIterator_base (const std::vector< int > &dims)
 
 line_NDIterator_base (const std::vector< int > &dims, const std::vector< int > &strides)
 
 line_NDIterator_base (const std::vector< int > &dims, const std::vector< size_t > &strides)
 
 line_NDIterator_base (const std::vector< int > &dims, const std::vector< long > &strides)
 
NDIterator_baseoperator++ ()
 
- 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::line_NDIterator< T >

N-dimensional array line iterator.

Iterates over every "line" of a N-D array, using strides. The "lines" are arrays over the smallest dimension of the array. Thus the iterator iterates over all dimensions but the smallest one. This allows to optimize code iterating directly on the smallest dimension, which is much more efficient than the regular NDIterator: for a very simple item operation using a line_NDIterator instead of a NDIterator can be about 20 times faster.

float *data; // fill it...
std::vector<int> dimensions;
std::vector<int> strdes;
// fill dimensions and strides...
float sum = 0.;
line_NDIterator<float> it( data, dimensions, strides );
float *p, *pp;
for( ; !it.ended(); ++it )
{
p = &*it;
for( pp=p + dimensions[0]; p!=pp; ++p )
sum += *p;
}

Definition at line 183 of file nditerator.h.

Constructor & Destructor Documentation

◆ line_NDIterator() [1/4]

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

Definition at line 458 of file nditerator.h.

◆ line_NDIterator() [2/4]

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

Definition at line 466 of file nditerator.h.

◆ line_NDIterator() [3/4]

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

Definition at line 474 of file nditerator.h.

◆ line_NDIterator() [4/4]

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

Definition at line 482 of file nditerator.h.

Member Function Documentation

◆ operator*()

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

Member Data Documentation

◆ _buffer

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

Definition at line 198 of file nditerator.h.

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


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