Turi Create  4.0
turi::parallel_sframe_iterator Class Reference

#include <core/storage/sframe_data/sframe_iterators.hpp>

Public Member Functions

 parallel_sframe_iterator ()
 
 parallel_sframe_iterator (sframe data, size_t thread_idx=0, size_t num_threads=1)
 
 parallel_sframe_iterator (const std::vector< sframe > &data, size_t thread_idx=0, size_t num_threads=1)
 
 parallel_sframe_iterator (const parallel_sframe_iterator_initializer &data, size_t thread_idx, size_t num_threads)
 
const parallel_sframe_iteratoroperator++ ()
 
bool done () const
 
void reset ()
 
size_t row_index () const
 
void fill (std::vector< flexible_type > &x) const
 
void fill (size_t sframe_idx, std::vector< flexible_type > &x) const
 
const flexible_typevalue (size_t sframe_idx, size_t column_idx) const
 
const flexible_typevalue (size_t idx) const
 
flexible_type && move_value (size_t sframe_idx, size_t column_idx)
 
flexible_type && move_value (size_t idx)
 

Detailed Description

A simple convienience iterator for doing parallel iteration over the rows of one or more sframes. It is designed for easy integration with the in_parallel function.

This iterator class provides two features:

  1. The ability to easily and efficiently iterate over multiple sections of an sframe, divided evenly by thread.
  2. The ability to easily iterate over multiple sframes of the same length simultaneously.

To use this iterator:

parallel_sframe_iterator_initializer it_init(data);

in_parallel([&](size_t thread_idx, size_t num_threads) { for(parallel_sframe_iterator it(it_init, thread_idx, num_threads); !it.done(); ++it) { size_t row_idx = it.row_index(); double value_0 = it.value(0); double value_1 = it.value(1); ... } });

Definition at line 125 of file sframe_iterators.hpp.

Constructor & Destructor Documentation

◆ parallel_sframe_iterator() [1/4]

turi::parallel_sframe_iterator::parallel_sframe_iterator ( )
inline

Default empty constructor.

Definition at line 132 of file sframe_iterators.hpp.

◆ parallel_sframe_iterator() [2/4]

turi::parallel_sframe_iterator::parallel_sframe_iterator ( sframe  data,
size_t  thread_idx = 0,
size_t  num_threads = 1 
)
inlineexplicit

Initialize the sframe iterator with a single sframe. The sframe is divided into num_threads blocks of approximately equal size. This iterator claims the thread_idx block.

Parameters
[in]dataSFrame
[in]thread_idxThread id (Ranges from 0-num_threads)
[in]num_threadsNumber of threads in the turi::thread_pool

Definition at line 148 of file sframe_iterators.hpp.

◆ parallel_sframe_iterator() [3/4]

turi::parallel_sframe_iterator::parallel_sframe_iterator ( const std::vector< sframe > &  data,
size_t  thread_idx = 0,
size_t  num_threads = 1 
)
inlineexplicit

Initialize the sframe iterator with a vector of sframes. The sframe is divided into num_threads blocks of approximately equal size. This iterator claims the thread_idx block.

Parameters
[in]dataSFrame
[in]thread_idxThread id (Ranges from 0-num_threads)
[in]num_threadsNumber of threads in the turi::thread_pool

Definition at line 161 of file sframe_iterators.hpp.

◆ parallel_sframe_iterator() [4/4]

turi::parallel_sframe_iterator::parallel_sframe_iterator ( const parallel_sframe_iterator_initializer data,
size_t  thread_idx,
size_t  num_threads 
)

Initialize the parallel SFrame iterator.

Parameters
[in]dataParallel sframe initializer
[in]thread_idxThread id (Ranges from 0-num_threads)
[in]num_threadsNumber of threads in the turi::thread_pool

Member Function Documentation

◆ done()

bool turi::parallel_sframe_iterator::done ( ) const
inline

Check if the iterator is done (applies to the global block)

Returns
True if the iterator is done.

Definition at line 194 of file sframe_iterators.hpp.

◆ fill() [1/2]

void turi::parallel_sframe_iterator::fill ( std::vector< flexible_type > &  x) const
inline

Fills a vector x with the current row of data, If there are multiple sframes provided initially, then values from all columns are concatenated into a single vector of length data_sources[0].num_columns() + data_sources[1].num_columns() + ...

Parameters
[in,out]xFills the std::vector with the contents of the SFrame

Definition at line 227 of file sframe_iterators.hpp.

◆ fill() [2/2]

void turi::parallel_sframe_iterator::fill ( size_t  sframe_idx,
std::vector< flexible_type > &  x 
) const
inline

Fills a vector x with the current row of data from data_sources[idx].

Parameters
[in]idxSFrame idx to use.
[in,out]xFills the std::vector with the contents of the SFrame

Definition at line 245 of file sframe_iterators.hpp.

◆ move_value() [1/2]

flexible_type&& turi::parallel_sframe_iterator::move_value ( size_t  sframe_idx,
size_t  column_idx 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Exactly like value(...), except it returns a move reference to the current value, invalidating the present one.

Parameters
[in]sframe_idxSFrame idx.
[in]column_idxColumn idx.
Returns
Moved value corresponding to SFrame[sframe_idx][column_idx]

Definition at line 312 of file sframe_iterators.hpp.

◆ move_value() [2/2]

flexible_type&& turi::parallel_sframe_iterator::move_value ( size_t  idx)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns a move reference to the current value in column_idx of the first sframe 0, invalidating that reference. If multiple sframes are provided at initialization time, then this indexes the values as if all the columns were concatenated (in similar fashion to fill(x); )

Parameters
[in]sframe_idxSFrame idx.
Returns
Value corresponding to SFrame[0][column_idx]

Definition at line 336 of file sframe_iterators.hpp.

◆ operator++()

const parallel_sframe_iterator& turi::parallel_sframe_iterator::operator++ ( )
inline

Increments the parallel SFrame iterator to the next row.

Definition at line 178 of file sframe_iterators.hpp.

◆ reset()

void turi::parallel_sframe_iterator::reset ( )
inline

Resets the iterator to the state it had upon initialization.

Definition at line 203 of file sframe_iterators.hpp.

◆ row_index()

size_t turi::parallel_sframe_iterator::row_index ( ) const
inline

Returns the current row index that the iterator is at.

Definition at line 214 of file sframe_iterators.hpp.

◆ value() [1/2]

const flexible_type& turi::parallel_sframe_iterator::value ( size_t  sframe_idx,
size_t  column_idx 
) const
inline

Returns the current value in sframe data_sources[sframe_idx], column column_idx.

Parameters
[in]sframe_idxSFrame idx.
[in]column_idxColumn idx.
Returns
Value corresponding to SFrame[sframe_idx][column_idx]

Definition at line 270 of file sframe_iterators.hpp.

◆ value() [2/2]

const flexible_type& turi::parallel_sframe_iterator::value ( size_t  idx) const
inline

Returns the current value in column_idx of the first sframe 0. If multiple sframes are provided at initialization time, then this indexes the values as if all the columns were concatenated (in similar fashion to fill(x); )

Parameters
[in]sframe_idxSFrame idx.
Returns
Value corresponding to SFrame[0][column_idx]

Definition at line 293 of file sframe_iterators.hpp.


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