HiPipe  0.7.0
C++17 data pipeline with Python bindings.
Public Member Functions | List of all members
hipipe::stream::batch Class Reference

Container for multiple columns. More...

#include <hipipe/core/stream/batch_t.hpp>

Public Member Functions

template<typename Column >
std::unique_ptr< abstract_column > & at ()
 Retrieve the handle (unique pointer reference) to the given column. More...
 
template<typename Column >
Column::data_type & extract ()
 Extract a reference to the stored data of the given column. More...
 
template<typename Column >
const Column::data_type & extract () const
 
template<typename Column , typename... Args>
void insert_or_assign (Args &&... args)
 Insert a new column to the batch or overwrite an existing one. More...
 
template<typename Column >
void raw_insert_or_assign (std::unique_ptr< abstract_column > column_ptr)
 Insert a raw column handle to the batch or rewrite an existing one. More...
 
std::size_t size () const
 Get the number of columns in the batch.
 
template<typename Column >
bool contains () const
 Check whether the given column is present in the batch. More...
 
template<typename Column >
void erase ()
 Remove the given column from the batch. More...
 
std::size_t batch_size () const
 Calculate the batch size. More...
 
batch take (std::size_t n)
 Steal the given number of examples from all the columns and create a new batch of them. More...
 
void push_back (batch rhs)
 Concatenate the columns from two batches. More...
 

Detailed Description

Container for multiple columns.

This is the value type of the stream.

Definition at line 34 of file batch_t.hpp.

Member Function Documentation

◆ at()

template<typename Column >
std::unique_ptr<abstract_column>& hipipe::stream::batch::at ( )
inline

Retrieve the handle (unique pointer reference) to the given column.

Example:

stream::batch b;
b.insert_or_assign<IntCol>(std::vector<int>{0, 1, 2});
b.at<IntCol>()->extract<IntCol>() == std::vector<int>{0, 1, 2};
Template Parameters
ColumnThe column whose handle should be retrieved.
Exceptions
std::runtime_errorIf the batch does not contain the given column.

Definition at line 83 of file batch_t.hpp.

◆ batch_size()

std::size_t hipipe::stream::batch::batch_size ( ) const
inline

Calculate the batch size.

If the batch contains no columns, returns zero.

Exceptions
std::runtime_errorIf all the columns do not have the same size.

Definition at line 204 of file batch_t.hpp.

◆ contains()

template<typename Column >
bool hipipe::stream::batch::contains ( ) const
inline

Check whether the given column is present in the batch.

Template Parameters
ColumnThe column to be checked.

Definition at line 179 of file batch_t.hpp.

◆ erase()

template<typename Column >
void hipipe::stream::batch::erase ( )
inline

Remove the given column from the batch.

Template Parameters
ColumnThe column to be removed.
Exceptions
std::runtime_errorIf the columns is not in the batch.

Definition at line 191 of file batch_t.hpp.

◆ extract() [1/2]

template<typename Column >
Column::data_type& hipipe::stream::batch::extract ( )
inline

Extract a reference to the stored data of the given column.

Example:

stream::batch b;
b.insert_or_assign<IntCol>(std::vector<int>{0, 1, 2});
b.extract<IntCol>() == std::vector<int>{0, 1, 2};
Template Parameters
ColumnThe column whose data should be retrieved.
Exceptions
std::runtime_errorIf the batch does not contain the given column.

Definition at line 104 of file batch_t.hpp.

◆ extract() [2/2]

template<typename Column >
const Column::data_type& hipipe::stream::batch::extract ( ) const
inline

Extract a const reference to the stored data of the given column.

This is the same as previous, but returns a const reference.

Definition at line 114 of file batch_t.hpp.

◆ insert_or_assign()

template<typename Column , typename... Args>
void hipipe::stream::batch::insert_or_assign ( Args &&...  args)
inline

Insert a new column to the batch or overwrite an existing one.

The parameters of this function are forwarded to the constructor of the given column.

Example:

stream::batch b;
b.insert_or_assign<IntCol>(std::vector<int>{0, 1, 2});
b.extract<IntCol>() == std::vector<int>{0, 1, 2};
Template Parameters
ColumnThe column to be inserted.
Parameters
argsThe parameters that are forwarded to the constructor of the column.

Definition at line 137 of file batch_t.hpp.

◆ push_back()

void hipipe::stream::batch::push_back ( batch  rhs)
inline

Concatenate the columns from two batches.

If some of the pushed columns is not in this batch, it is inserted as a new column.

The behaviour of this function is almost equivalent to calling column_base::push_back() of on all the columns.

Parameters
rhsThe batch whose columns will be stolen and appended.

Definition at line 242 of file batch_t.hpp.

◆ raw_insert_or_assign()

template<typename Column >
void hipipe::stream::batch::raw_insert_or_assign ( std::unique_ptr< abstract_column column_ptr)
inline

Insert a raw column handle to the batch or rewrite an existing one.

This is particularly useful when a raw column handle is retrieved with the at() function and there is no need for creating a new column.

Example:

stream::batch b1, b2;
b1.insert_or_assign<IntCol>(std::vector<int>{0, 1, 2});
b2.raw_insert_or_assign<IntCol>(std::move(b1.at<IntCol>())); // b2 now holds the vector
Template Parameters
ColumnThe column to be inserted.
Parameters
column_ptrThe unique pointer to the column.

Definition at line 162 of file batch_t.hpp.

◆ take()

batch hipipe::stream::batch::take ( std::size_t  n)
inline

Steal the given number of examples from all the columns and create a new batch of them.

The behaviour of this function is equivalent to calling column_base::take() of on all the columns.

Parameters
nThe number of examples to steal.

Definition at line 225 of file batch_t.hpp.


The documentation for this class was generated from the following file:
HIPIPE_DEFINE_COLUMN
#define HIPIPE_DEFINE_COLUMN(column_name_, example_type_)
Macro for fast column definition.
Definition: column_t.hpp:250