tatami_stats
Matrix statistics for tatami
Loading...
Searching...
No Matches
Public Member Functions | List of all members
tatami_stats::LocalOutputBuffers< Output_, GetOutput_ > Class Template Reference

Local output buffers for running calculations. More...

#include <utils.hpp>

Public Member Functions

template<typename Index_ >
 LocalOutputBuffers (size_t thread, size_t number, Index_ start, Index_ length, GetOutput_ outfun, Output_ fill)
 
template<typename Index_ >
 LocalOutputBuffers (size_t thread, size_t number, Index_ start, Index_ length, GetOutput_ outfun)
 
 LocalOutputBuffers ()=default
 
size_t size () const
 
Output_ * data (size_t i)
 
const Output_ * data (size_t i) const
 
void transfer ()
 

Detailed Description

template<typename Output_, class GetOutput_>
class tatami_stats::LocalOutputBuffers< Output_, GetOutput_ >

Local output buffers for running calculations.

Zero, one or more local output buffers to be created in each thread to avoid false sharing. This class is equivalent to a vector of LocalOutputBuffer instances, but is easier to initialize and more memory-efficient. In particular, no vector is created at all for the first thread, avoiding an unnecessary allocation in the serial case.

Template Parameters
Output_Type of the result.
GetOutput_Functor object that returns a pointer to the output buffer.

Constructor & Destructor Documentation

◆ LocalOutputBuffers() [1/3]

template<typename Output_ , class GetOutput_ >
template<typename Index_ >
tatami_stats::LocalOutputBuffers< Output_, GetOutput_ >::LocalOutputBuffers ( size_t  thread,
size_t  number,
Index_  start,
Index_  length,
GetOutput_  outfun,
Output_  fill 
)
inline
Template Parameters
Index_Type of the start index and length.
Parameters
threadIdentity of the thread, starting from zero to the total number of threads.
numberNumber of output buffers.
startIndex of the first objective vector in the contiguous block for this thread.
lengthNumber of objective vectors in the contiguous block for this thread.
outfunFunction that accepts an Index_ specifying the index of an output buffer in [0, number) and returns a Output_* pointer to that buffer.
fillInitial value to fill the buffer.

◆ LocalOutputBuffers() [2/3]

template<typename Output_ , class GetOutput_ >
template<typename Index_ >
tatami_stats::LocalOutputBuffers< Output_, GetOutput_ >::LocalOutputBuffers ( size_t  thread,
size_t  number,
Index_  start,
Index_  length,
GetOutput_  outfun 
)
inline

Overloaded constructor that sets the default fill = 0.

Template Parameters
Index_Type of the start index and length.
Parameters
threadIdentity of the thread, starting from zero to the total number of threads.
numberNumber of output buffers.
startIndex of the first objective vector in the contiguous block for this thread.
lengthNumber of objective vectors in the contiguous block for this thread.
outfunFunction that accepts an Index_ specifying the index of an output buffer in [0, number) and returns a Output_* pointer to that buffer.

◆ LocalOutputBuffers() [3/3]

template<typename Output_ , class GetOutput_ >
tatami_stats::LocalOutputBuffers< Output_, GetOutput_ >::LocalOutputBuffers ( )
default

Default constructor.

Member Function Documentation

◆ size()

template<typename Output_ , class GetOutput_ >
size_t tatami_stats::LocalOutputBuffers< Output_, GetOutput_ >::size ( ) const
inline
Returns
Number of output buffers. This is the same as number in the constructor.

◆ data() [1/2]

template<typename Output_ , class GetOutput_ >
Output_ * tatami_stats::LocalOutputBuffers< Output_, GetOutput_ >::data ( size_t  i)
inline
Parameters
iIndex of the output buffer.
Returns
Pointer to the i-th output buffer to use in this thread. This contains at least length addressable elements (see the argument of the same name in the constructor). For thread = 0, this will be equal to outfun(i) + start.

◆ data() [2/2]

template<typename Output_ , class GetOutput_ >
const Output_ * tatami_stats::LocalOutputBuffers< Output_, GetOutput_ >::data ( size_t  i) const
inline
Parameters
iIndex of the output buffer.
Returns
Const pointer to the i-th output buffer to use for this thread. This contains at least length addressable elements (see the argument of the same name in the constructor). For thread = 0, this will be equal to outfun(i) + start.

◆ transfer()

template<typename Output_ , class GetOutput_ >
void tatami_stats::LocalOutputBuffers< Output_, GetOutput_ >::transfer ( )
inline

Transfer results from the local buffer to the global buffer (i.e., outfun(i) for i in [0, number) from the constructor). For thread = 0, this will be a no-op.


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