tatami_stats
Matrix statistics for tatami
Loading...
Searching...
No Matches
Classes | Functions
tatami_stats::sums Namespace Reference

Functions for computing dimension-wise sums. More...

Classes

struct  Options
 Summation options. More...
 
class  RunningDense
 Running sums from dense data. More...
 
class  RunningSparse
 Running sums from sparse data. More...
 

Functions

template<typename Output_ = double, typename Value_ , typename Index_ >
Output_ direct (const Value_ *ptr, Index_ num, bool skip_nan)
 
template<typename Value_ , typename Index_ , typename Output_ >
void apply (bool row, const tatami::Matrix< Value_, Index_ > *p, Output_ *output, const Options &sopt)
 
template<typename Output_ = double, typename Value_ , typename Index_ >
std::vector< Output_ > by_column (const tatami::Matrix< Value_, Index_ > *p, const Options &sopt)
 
template<typename Output_ = double, typename Value_ , typename Index_ >
std::vector< Output_ > by_column (const tatami::Matrix< Value_, Index_ > *p)
 
template<typename Output_ = double, typename Value_ , typename Index_ >
std::vector< Output_ > by_row (const tatami::Matrix< Value_, Index_ > *p, const Options &sopt)
 
template<typename Output_ = double, typename Value_ , typename Index_ >
std::vector< Output_ > by_row (const tatami::Matrix< Value_, Index_ > *p)
 

Detailed Description

Functions for computing dimension-wise sums.

Function Documentation

◆ direct()

template<typename Output_ = double, typename Value_ , typename Index_ >
Output_ tatami_stats::sums::direct ( const Value_ *  ptr,
Index_  num,
bool  skip_nan 
)

Compute the sum across an objective vector using naive accumulation. This is best used with a sufficiently high-precision Output_, hence the default of double.

Template Parameters
Output_Type of the output data.
Value_Type of the input data.
Index_Type of the row/column index.
Parameters
[in]ptrPointer to an array of length num, containing the values of the objective vector.
numSize of the array at ptr. This may be less than the length of the objective vector for sparse data.
skip_nanSee Options::skip_nan.
Returns
The sum.

◆ apply()

template<typename Value_ , typename Index_ , typename Output_ >
void tatami_stats::sums::apply ( bool  row,
const tatami::Matrix< Value_, Index_ > *  p,
Output_ *  output,
const Options sopt 
)

Compute sums for each element of a chosen dimension of a tatami::Matrix. This is done using direct(), RunningDense or RunningSparse, depending on the requested dimension in row and the preferred dimension for access in p. Note that all sums are obtained using naive accumulation, so it is best to use a sufficiently high-precision Output_ to mitigate round-off errors.

Template Parameters
Value_Type of the matrix value, should be numeric.
Index_Type of the row/column indices.
Output_Type of the output value.
Parameters
rowWhether to compute the sum for each row. If false, the sum is computed for each column instead.
pPointer to a tatami::Matrix.
[out]outputPointer to an array of length equal to the number of rows (if row = true) or columns (otherwise). On output, this will contain the row/column variances.
soptSummation options.

◆ by_column() [1/2]

template<typename Output_ = double, typename Value_ , typename Index_ >
std::vector< Output_ > tatami_stats::sums::by_column ( const tatami::Matrix< Value_, Index_ > *  p,
const Options sopt 
)

Wrapper around apply() for column sums.

Template Parameters
Value_Type of the matrix value, should be summable.
Index_Type of the row/column indices.
Output_Type of the output value.
Parameters
pPointer to a tatami::Matrix.
soptSummation options.
Returns
Vector containing the sum for each column.

◆ by_column() [2/2]

template<typename Output_ = double, typename Value_ , typename Index_ >
std::vector< Output_ > tatami_stats::sums::by_column ( const tatami::Matrix< Value_, Index_ > *  p)

Overload with default options.

Template Parameters
Value_Type of the matrix value, should be summable.
Index_Type of the row/column indices.
Output_Type of the output value.
Parameters
pPointer to a tatami::Matrix.
Returns
Vector containing the sum for each column.

◆ by_row() [1/2]

template<typename Output_ = double, typename Value_ , typename Index_ >
std::vector< Output_ > tatami_stats::sums::by_row ( const tatami::Matrix< Value_, Index_ > *  p,
const Options sopt 
)

Wrapper around apply() for row sums.

Template Parameters
Output_Type of the output value.
Value_Type of the matrix value, should be summable.
Index_Type of the row/column indices.
Parameters
pPointer to a tatami::Matrix.
soptSummation options.
Returns
Vector containing the sum of each row.

◆ by_row() [2/2]

template<typename Output_ = double, typename Value_ , typename Index_ >
std::vector< Output_ > tatami_stats::sums::by_row ( const tatami::Matrix< Value_, Index_ > *  p)

Overload with default options.

Template Parameters
Output_Type of the output value.
Value_Type of the matrix value, should be summable.
Index_Type of the row/column indices.
Parameters
pPointer to a tatami::Matrix.
Returns
Vector containing the sum of each row.