tatami_stats
Matrix statistics for tatami
Loading...
Searching...
No Matches
tatami_stats Namespace Reference

Functions to compute statistics from a tatami::Matrix. More...

Namespaces

namespace  skip_nan
 Compute statistics from a tatami::Matrix while skipping NaNs.
 

Classes

struct  CountOptions
 Options for count(). More...
 
struct  GroupMedianOptions
 Options for group_median(). More...
 
struct  GroupRssBuffers
 Result buffers for group_rss(). More...
 
struct  GroupRssOptions
 Options for group_rss(). More...
 
struct  GroupRssResult
 Results of group_rss(). More...
 
struct  GroupSumOptions
 Options for group_sum(). More...
 
struct  GroupVarianceBuffers
 Result buffers for group_variance(). More...
 
struct  GroupVarianceOptions
 Options for group_variance(). More...
 
struct  GroupVarianceResult
 Results of group_variance(). More...
 
struct  MedianOptions
 Options for median(). More...
 
struct  QuantileOptions
 Options for quantile(). More...
 
struct  RangeBuffers
 Result buffers for range(). More...
 
struct  RangeOptions
 Options for range(). More...
 
struct  RangeResult
 Results of range(). More...
 
struct  RssBuffers
 Result buffers for rss(). More...
 
struct  RssOptions
 Options for rss(). More...
 
struct  RssResult
 Results of rss(). More...
 
struct  SumOptions
 Options for sum(). More...
 
struct  VarianceBuffers
 Result buffers for variance(). More...
 
struct  VarianceOptions
 Options for variance(). More...
 
struct  VarianceResult
 Results of variance(). More...
 

Functions

template<typename Value_ , typename Index_ , typename Output_ , class Condition_ >
void count (const bool row, const tatami::Matrix< Value_, Index_ > &mat, Output_ *const output, Condition_ condition, const CountOptions &opt)
 
template<typename Output_ , typename Value_ , typename Index_ , class Condition_ >
std::vector< Output_ > count (const bool row, const tatami::Matrix< Value_, Index_ > &mat, Condition_ condition, const CountOptions &opt)
 
template<typename Value_ , typename Index_ , typename Group_ , typename Output_ >
void group_median (bool row, const tatami::Matrix< Value_, Index_ > &mat, const Group_ *const group, const std::size_t num_groups, std::vector< Output_ * > &output, const GroupMedianOptions &opt)
 
template<typename Output_ = double, typename Value_ , typename Index_ , typename Group_ >
std::vector< std::vector< Output_ > > group_median (bool row, const tatami::Matrix< Value_, Index_ > &mat, const Group_ *const group, const std::size_t num_groups, const GroupMedianOptions &opt)
 
template<typename Value_ , typename Index_ , typename Group_ , typename Output_ , typename Count_ >
void group_rss (bool row, const tatami::Matrix< Value_, Index_ > &mat, const Group_ *const group, const std::size_t num_groups, GroupRssBuffers< Output_, Count_ > &output, const GroupRssOptions &opt)
 
template<typename Output_ , typename Count_ , typename Value_ , typename Index_ , typename Group_ >
GroupRssResult< Output_, Count_ > group_rss (bool row, const tatami::Matrix< Value_, Index_ > &mat, const Group_ *const group, const std::size_t num_groups, const GroupRssOptions &opt)
 
template<typename Value_ , typename Index_ , typename Group_ , typename Output_ >
void group_sum (bool row, const tatami::Matrix< Value_, Index_ > &mat, const Group_ *group, const std::size_t num_groups, std::vector< Output_ * > &output, const GroupSumOptions &opt)
 
template<typename Output_ = double, typename Value_ , typename Index_ , typename Group_ >
std::vector< std::vector< Output_ > > group_sum (bool row, const tatami::Matrix< Value_, Index_ > &mat, const Group_ *group, const std::size_t num_groups, const GroupSumOptions &opt)
 
template<typename Value_ , typename Index_ , typename Group_ , typename Output_ >
void group_variance (bool row, const tatami::Matrix< Value_, Index_ > &mat, const Group_ *const group, const std::size_t num_groups, GroupVarianceBuffers< Output_ > &output, const GroupVarianceOptions &opt)
 
template<typename Output_ = double, typename Value_ , typename Index_ , typename Group_ >
GroupVarianceResult< Output_ > group_variance (bool row, const tatami::Matrix< Value_, Index_ > &mat, const Group_ *const group, const std::size_t num_groups, const GroupVarianceOptions &opt)
 
template<typename Value_ , typename Index_ , typename Output_ >
void median (const bool row, const tatami::Matrix< Value_, Index_ > &mat, Output_ *const output, const MedianOptions &opt)
 
template<typename Output_ = double, typename Value_ , typename Index_ >
std::vector< Output_ > median (const bool row, const tatami::Matrix< Value_, Index_ > &mat, const MedianOptions &opt)
 
template<typename Value_ , typename Index_ , typename Output_ >
void quantile (const bool row, const tatami::Matrix< Value_, Index_ > &mat, const double prob, Output_ *const output, const QuantileOptions &opt)
 
template<typename Output_ = double, typename Value_ , typename Index_ >
std::vector< Output_ > quantile (const bool row, const tatami::Matrix< Value_, Index_ > &mat, const double prob, const QuantileOptions &opt)
 
template<typename Value_ , typename Index_ , typename Output_ >
void range (bool row, const tatami::Matrix< Value_, Index_ > &mat, RangeBuffers< Output_ > &output, const RangeOptions &opt)
 
template<typename Value_ , typename Index_ , typename Output_ = Value_>
RangeResult< Output_ > range (bool row, const tatami::Matrix< Value_, Index_ > &mat, const RangeOptions &opt)
 
template<typename Value_ , typename Index_ , typename Output_ >
void rss (bool row, const tatami::Matrix< Value_, Index_ > &mat, RssBuffers< Output_ > &output, const RssOptions &opt)
 
template<typename Output_ = double, typename Value_ , typename Index_ >
RssResult< Output_ > rss (bool row, const tatami::Matrix< Value_, Index_ > &mat, const RssOptions &opt)
 
template<typename Value_ , typename Index_ , typename Output_ >
void sum (bool row, const tatami::Matrix< Value_, Index_ > &mat, Output_ *output, const SumOptions &opt)
 
template<typename Output_ = double, typename Value_ , typename Index_ >
std::vector< Output_ > sum (bool row, const tatami::Matrix< Value_, Index_ > &mat, const SumOptions &opt)
 
template<typename Value_ , typename Index_ , typename Output_ >
void variance (bool row, const tatami::Matrix< Value_, Index_ > &mat, VarianceBuffers< Output_ > &output, const VarianceOptions &opt)
 
template<typename Output_ = double, typename Value_ , typename Index_ >
VarianceResult< Output_ > variance (bool row, const tatami::Matrix< Value_, Index_ > &mat, const VarianceOptions &opt)
 

Detailed Description

Functions to compute statistics from a tatami::Matrix.

Function Documentation

◆ count() [1/2]

template<typename Value_ , typename Index_ , typename Output_ , class Condition_ >
void tatami_stats::count ( const bool row,
const tatami::Matrix< Value_, Index_ > & mat,
Output_ *const output,
Condition_ condition,
const CountOptions & opt )

Count the number of values that satisfy the condition in each element of a chosen dimension.

Template Parameters
Value_Numeric type of the matrix value.
Index_Integer type of the row/column indices.
Output_Numeric type of the output count. To avoid overflow, we recommend using a type that is large enough to hold the dimension extents of mat.
Condition_Function that accepts a single Value_ and returns a bool.
Parameters
rowWhether to perform the count within each row. If false, the count is performed within each column instead.
matInstance of 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 counts.
conditionFunction to indicate whether a value should be counted. This function is responsible for handling any NaNs that might be present in p. This function should be thread-safe.
optFurther options.

◆ count() [2/2]

template<typename Output_ , typename Value_ , typename Index_ , class Condition_ >
std::vector< Output_ > tatami_stats::count ( const bool row,
const tatami::Matrix< Value_, Index_ > & mat,
Condition_ condition,
const CountOptions & opt )

Overload of count() that allocates memory for the output vector.

Template Parameters
Output_Numeric type of the output count. To avoid overflow, we recommend using a type that is large enough to hold the dimension extents of mat.
Value_Numeric type of the matrix value.
Index_Integer type of the row/column indices.
Condition_Function that accepts a single Value_ and returns a bool.
Parameters
rowWhether to perform the count within each row. If false, the count is performed within each column instead.
matInstance of a tatami::Matrix.
conditionFunction to indicate whether a value should be counted. This function is also responsible for handling any NaNs that might be present in p. This function should be thread-safe.
optFurther options.

◆ group_median() [1/2]

template<typename Value_ , typename Index_ , typename Group_ , typename Output_ >
void tatami_stats::group_median ( bool row,
const tatami::Matrix< Value_, Index_ > & mat,
const Group_ *const group,
const std::size_t num_groups,
std::vector< Output_ * > & output,
const GroupMedianOptions & opt )

Compute per-group medians for each element of a chosen dimension of a tatami::Matrix.

Template Parameters
Value_Numeric type of the matrix value.
Index_Integer type of the row/column indices.
Group_Integer type of the group assignments for each column.
GroupSizes_Vector-like class that has size() and [ methods and contains integers.
Output_Floating-point type of the output value, capable of storing averages or NaNs.
Parameters
rowWhether to compute group-wise medians within each row. If false, medians are computed in each column instead.
matInstance of a tatami::Matrix.
[in]groupPointer to an array of length equal to the number of columns (if row = true) or rows (otherwise). Each value should be an integer that specifies the group assignment. Values should lie in \([0, N)\) where \(N\) is the number of unique groups.
num_groupsNumber of groups, i.e., \(N\).
[out]outputPointer to an array of pointers of length equal to the number of groups. Each inner pointer should reference an array of length equal to the number of rows (if row = true) or columns (otherwise). On output, this will contain the row/column medians for each group (indexed according to the assignment in group).
optFurther options.

◆ group_median() [2/2]

template<typename Output_ = double, typename Value_ , typename Index_ , typename Group_ >
std::vector< std::vector< Output_ > > tatami_stats::group_median ( bool row,
const tatami::Matrix< Value_, Index_ > & mat,
const Group_ *const group,
const std::size_t num_groups,
const GroupMedianOptions & opt )

Overload of group_median() that allocates memory for the output medians.

Template Parameters
Output_Floating-point type of the output value, capable of storing averages or NaNs.
Value_Numeric type of the matrix value.
Index_Integer type of the row/column indices.
Group_Integer type of the group assignments for each column.
Parameters
rowWhether to compute group-wise medians within each row. If false, medians are computed in each column instead.
matInstance of a tatami::Matrix.
[in]groupPointer to an array of length equal to the number of columns (if row = true) or rows (otherwise). Each value should be an integer that specifies the group assignment. Values should lie in \([0, N)\) where \(N\) is the number of unique groups.
num_groupsNumber of groups, i.e., \(N\).
optFurther options.
Returns
Vector of length equal to the number of groups. Each element is a vector of length equal to the number of rows (if row = true) or columns (otherwise), containing the row/column medians for the corresponding group.

◆ group_rss() [1/2]

template<typename Value_ , typename Index_ , typename Group_ , typename Output_ , typename Count_ >
void tatami_stats::group_rss ( bool row,
const tatami::Matrix< Value_, Index_ > & mat,
const Group_ *const group,
const std::size_t num_groups,
GroupRssBuffers< Output_, Count_ > & output,
const GroupRssOptions & opt )

Compute per-group residual sums of squares (RSS) for each element of a chosen dimension of a tatami::Matrix.

Template Parameters
Value_Numeric type of the matrix value.
Index_Integer type of the row/column indices.
Group_Integer type of the group assignments for each row/column.
Output_Floating-point type of the output value. This should be capable of storing NaNs.
Count_Numeric type of the group sizes, typically integer.
Parameters
rowWhether to compute RSS values for the rows.
matInstance of a tatami::Matrix.
[in]groupPointer to an array of length equal to the number of columns (if row = true) or rows (otherwise). Each value should be an integer that specifies the group assignment. Values should lie in \([0, N)\) where \(N\) is the number of unique groups.
num_groupsNumber of groups, i.e., \(N\).
[out]outputBuffers in which to store the results. On output, each array stores the means and RSS values of the corresponding group.
optFurther options.

◆ group_rss() [2/2]

template<typename Output_ , typename Count_ , typename Value_ , typename Index_ , typename Group_ >
GroupRssResult< Output_, Count_ > tatami_stats::group_rss ( bool row,
const tatami::Matrix< Value_, Index_ > & mat,
const Group_ *const group,
const std::size_t num_groups,
const GroupRssOptions & opt )

Compute per-group residual sums of squares (RSS) for each element of a chosen dimension of a tatami::Matrix.

Template Parameters
Output_Floating-point type of the output value. This should be capable of storing NaNs.
Count_Numeric type of the group sizes, typically integer.
Value_Numeric type of the matrix value.
Index_Integer type of the row/column indices.
Group_Integer type of the group assignments for each row/column.
Parameters
rowWhether to compute RSS values for the rows.
matInstance of a tatami::Matrix.
[in]groupPointer to an array of length equal to the number of columns (if row = true) or rows (otherwise). Each value should be an integer that specifies the group assignment. Values should lie in \([0, N)\) where \(N\) is the number of unique groups.
num_groupsNumber of groups, i.e., \(N\).
optFurther options.
Returns
RSS and mean of each group for each row/column.

◆ group_sum() [1/2]

template<typename Value_ , typename Index_ , typename Group_ , typename Output_ >
void tatami_stats::group_sum ( bool row,
const tatami::Matrix< Value_, Index_ > & mat,
const Group_ * group,
const std::size_t num_groups,
std::vector< Output_ * > & output,
const GroupSumOptions & opt )

Compute per-group sums for each element of a chosen dimension of a tatami::Matrix.

Template Parameters
Value_Numeric type of the matrix value.
Index_Integer type of the row/column indices.
Group_Integer type of the group assignments for each row.
Output_Numeric type of the output value. It is assumed that this is large enough to store the sums.
Parameters
rowWhether to compute group-wise sums within each row. If false, sums are computed within the column instead.
matInstance of a tatami::Matrix.
[in]groupPointer to an array of length equal to the number of columns (if row = true) or rows (otherwise). Each value should be an integer that specifies the group assignment. Values should lie in \([0, N)\) where \(N\) is the number of unique groups.
num_groupsNumber of groups, i.e., \(N\). This can be determined by calling tatami_stats::total_groups() on group.
[out]outputVector of length equal to the number of groups. Each element is a pointer to an array of length equal to the number of rows (if row = true) or columns (otherwise). On output, each array will contain the row/column sums for the corresponding group.
optFurther options.

◆ group_sum() [2/2]

template<typename Output_ = double, typename Value_ , typename Index_ , typename Group_ >
std::vector< std::vector< Output_ > > tatami_stats::group_sum ( bool row,
const tatami::Matrix< Value_, Index_ > & mat,
const Group_ * group,
const std::size_t num_groups,
const GroupSumOptions & opt )

Overload of group_sum() that allocates memory for the output sums.

Template Parameters
Output_Numeric type of the output value. It is assumed that this is large enough to store the sums.
Value_Numeric type of the matrix value.
Index_Integer type of the row/column indices.
Group_Integer type of the group assignments for each row.
Parameters
rowWhether to compute group-wise sums within each row. If false, sums are computed within the column instead.
matInstance of a tatami::Matrix.
[in]groupPointer to an array of length equal to the number of columns (if row = true) or rows (otherwise). Each value should be an integer that specifies the group assignment. Values should lie in \([0, N)\) where \(N\) is the number of unique groups.
num_groupsNumber of groups, i.e., \(N\). This can be determined by calling tatami_stats::total_groups() on group.
optFurther options.
Returns
Vector of length equal to the number of groups. Each element is a vector of length equal to the number of rows (if row = true) or columns (otherwise), containing the row/column sums for the corresponding group.

◆ group_variance() [1/2]

template<typename Value_ , typename Index_ , typename Group_ , typename Output_ >
void tatami_stats::group_variance ( bool row,
const tatami::Matrix< Value_, Index_ > & mat,
const Group_ *const group,
const std::size_t num_groups,
GroupVarianceBuffers< Output_ > & output,
const GroupVarianceOptions & opt )

Compute per-group variances for each element of a chosen dimension of a tatami::Matrix.

Template Parameters
Value_Numeric type of the matrix value.
Index_Integer type of the row/column indices.
Group_Integer type of the group assignments for each row/column.
Output_Floating-point type of the output value. This should be capable of storing NaNs.
Parameters
rowWhether to compute variances for the rows.
matInstance of a tatami::Matrix.
[in]groupPointer to an array of length equal to the number of columns (if row = true) or rows (otherwise). Each value should be an integer that specifies the group assignment. Values should lie in \([0, N)\) where \(N\) is the number of unique groups.
num_groupsNumber of groups, i.e., \(N\).
[out]outputBuffers in which to store the results. On output, each array stores the means and variances of the corresponding group.
optFurther options.

◆ group_variance() [2/2]

template<typename Output_ = double, typename Value_ , typename Index_ , typename Group_ >
GroupVarianceResult< Output_ > tatami_stats::group_variance ( bool row,
const tatami::Matrix< Value_, Index_ > & mat,
const Group_ *const group,
const std::size_t num_groups,
const GroupVarianceOptions & opt )

Compute per-group variances for each element of a chosen dimension of a tatami::Matrix.

Template Parameters
Output_Floating-point type of the output value. This should be capable of storing NaNs.
Value_Numeric type of the matrix value.
Index_Integer type of the row/column indices.
Group_Integer type of the group assignments for each row/column.
Parameters
rowWhether to compute variances for the rows.
matInstance of a tatami::Matrix.
[in]groupPointer to an array of length equal to the number of columns (if row = true) or rows (otherwise). Each value should be an integer that specifies the group assignment. Values should lie in \([0, N)\) where \(N\) is the number of unique groups.
num_groupsNumber of groups, i.e., \(N\).
optFurther options.
Returns
Variance and mean of each group for each row/column.

◆ median() [1/2]

template<typename Value_ , typename Index_ , typename Output_ >
void tatami_stats::median ( const bool row,
const tatami::Matrix< Value_, Index_ > & mat,
Output_ *const output,
const MedianOptions & opt )

Compute medians for each element of a chosen dimension of a tatami::Matrix.

Template Parameters
Value_Numeric type of the input values.
Index_Integer type of the row/column indices.
Output_Floating-point type of the output value. This should be capable of storing NaNs.
Parameters
rowWhether to compute the median for each row. If false, the median is computed for each column instead.
matInstance of 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 medians.
optFurther options.

◆ median() [2/2]

template<typename Output_ = double, typename Value_ , typename Index_ >
std::vector< Output_ > tatami_stats::median ( const bool row,
const tatami::Matrix< Value_, Index_ > & mat,
const MedianOptions & opt )

Overload of median() that allocates memory for the output medians.

Template Parameters
Output_Floating-point type of the output value. This should be capable of storing NaNs.
Value_Numeric type of the input values.
Index_Integer type of the row/column indices.
Parameters
rowWhether to compute the median for each row. If false, the median is computed for each column instead.
matInstance of a tatami::Matrix.
optFurther options.
Returns
Vector of length equal to the number of rows (if row = true) or columns (otherwise). On output, this will contain the row/column medians.

◆ quantile() [1/2]

template<typename Value_ , typename Index_ , typename Output_ >
void tatami_stats::quantile ( const bool row,
const tatami::Matrix< Value_, Index_ > & mat,
const double prob,
Output_ *const output,
const QuantileOptions & opt )

Compute quantiles for each element of a chosen dimension of a tatami::Matrix.

Template Parameters
Value_Numeric type of the input values.
Index_Integer type of the row/column indices.
Output_Floating-point type of the output value. This should be capable of storing NaNs.
Parameters
rowWhether to compute the quantile for each row. If false, the quantile is computed for each column instead.
matInstance of a tatami::Matrix.
probProbability of the quantile to compute. This should be in \([0, 1]\).
[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 quantiles.
optFurther options.

◆ quantile() [2/2]

template<typename Output_ = double, typename Value_ , typename Index_ >
std::vector< Output_ > tatami_stats::quantile ( const bool row,
const tatami::Matrix< Value_, Index_ > & mat,
const double prob,
const QuantileOptions & opt )

Overload of quantile() that allocates memory for the output quantiles.

Template Parameters
Value_Numeric type of the input values.
Index_Integer type of the row/column indices.
Output_Floating-point type of the output value. This should be capable of storing NaNs.
Parameters
rowWhether to compute the quantile for each row. If false, the quantile is computed for each column instead.
matInstance of a tatami::Matrix.
probProbability of the quantile to compute. This should be in \([0, 1]\).
optFurther options.
Returns
Vector of length equal to the number of rows (if row = true) or columns (otherwise), containing the row/column quantiles.

◆ range() [1/2]

template<typename Value_ , typename Index_ , typename Output_ >
void tatami_stats::range ( bool row,
const tatami::Matrix< Value_, Index_ > & mat,
RangeBuffers< Output_ > & output,
const RangeOptions & opt )

Compute ranges for each element of a chosen dimension of a tatami::Matrix.

Template Parameters
Value_Numeric type of the input data.
Index_Integer type of the row/column indices.
Output_Numeric type of the output data. It is assumed that this is large enough to store the maxima/minima.
Parameters
rowWhether to compute the range for each row. If false, the range is computed for each column instead.
matInstance of a tatami::Matrix.
[out]outputBuffers to output arrays. On output, this will contain the row/column variances.
optFurther options.

◆ range() [2/2]

template<typename Value_ , typename Index_ , typename Output_ = Value_>
RangeResult< Output_ > tatami_stats::range ( bool row,
const tatami::Matrix< Value_, Index_ > & mat,
const RangeOptions & opt )

Overload of range() that allocates memory for the minimum/maximum.

Template Parameters
Value_Numeric type of the input data.
Index_Integer type of the row/column indices.
Output_Numeric type of the output data. It is assumed that this is large enough to store the maxima/minima.
Parameters
rowWhether to compute the range for each row. If false, the range is computed for each column instead.
matInstance of a tatami::Matrix.
optFurther options.
Returns
Minimum and maximum for each row/column.

◆ rss() [1/2]

template<typename Value_ , typename Index_ , typename Output_ >
void tatami_stats::rss ( bool row,
const tatami::Matrix< Value_, Index_ > & mat,
RssBuffers< Output_ > & output,
const RssOptions & opt )

Compute residual sums of squares (RSS) for each element of a chosen dimension of a tatami::Matrix. This may use either Welford's method or the standard two-pass method, depending on the dimension in row and the preferred access dimension of p.

Template Parameters
Value_Numeric type of the input data.
Index_Integer type of the row/column indices.
Output_Floating-point type of the output data. This should be capable of storing NaNs.
Parameters
rowWhether to compute the RSS for each row. If false, the RSS is computed for each column instead.
matInstance of a tatami::Matrix.
[out]outputBuffers to output arrays. On output, this will contain the row/column RSSs.
optFurther options.

◆ rss() [2/2]

template<typename Output_ = double, typename Value_ , typename Index_ >
RssResult< Output_ > tatami_stats::rss ( bool row,
const tatami::Matrix< Value_, Index_ > & mat,
const RssOptions & opt )

Overload of rss() that allocates memory for the output arrays.

Template Parameters
Output_Floating-point type of the output data. This should be capable of storing NaNs.
Value_Numeric type of the input data.
Index_Integer type of the row/column indices.
Parameters
rowWhether to compute the RSS for each row. If false, the RSS is computed for each column instead.
matInstance of a tatami::Matrix.
optFurther options.
Returns
The mean and RSS of each row/column.

◆ sum() [1/2]

template<typename Value_ , typename Index_ , typename Output_ >
void tatami_stats::sum ( bool row,
const tatami::Matrix< Value_, Index_ > & mat,
Output_ * output,
const SumOptions & opt )

Compute sums for each element of a chosen dimension of a tatami::Matrix. This may either use pairwise summation or direct accumulation, depending on the requested dimension in row, the preferred dimension for access in p and whether NaNs are to be skipped. It is best to use a sufficiently high-precision Output_ to mitigate round-off errors.

Template Parameters
Value_Numeric type of the matrix value.
Index_Integer type of the row/column indices.
Output_Numeric type of the output value. It is assumed that this is large enough to store the sums.
Parameters
rowWhether to compute the sum for each row. If false, the sum is computed for each column instead.
matInstance of 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 sums.
optFurther options.

◆ sum() [2/2]

template<typename Output_ = double, typename Value_ , typename Index_ >
std::vector< Output_ > tatami_stats::sum ( bool row,
const tatami::Matrix< Value_, Index_ > & mat,
const SumOptions & opt )

Overload of sum() that allocates memory for the output sums.

Template Parameters
Output_Numeric type of the output value. It is assumed that this is large enough to store the sums.
Value_Numeric type of the matrix value.
Index_Integer type of the row/column indices.
Parameters
rowWhether to compute the sum for each row. If false, the sum is computed for each column instead.
matInstance of a tatami::Matrix.
optFurther options.
Returns
Vector of length equal to the number of rows (if row = true) or columns (otherwise), containing the row/column sums.

◆ variance() [1/2]

template<typename Value_ , typename Index_ , typename Output_ >
void tatami_stats::variance ( bool row,
const tatami::Matrix< Value_, Index_ > & mat,
VarianceBuffers< Output_ > & output,
const VarianceOptions & opt )

Compute sample variances for each element of a chosen dimension of a tatami::Matrix. This may use either Welford's method or the standard two-pass method, depending on the dimension in row and the preferred access dimension of p.

Template Parameters
Value_Numeric type of the input data.
Index_Integer type of the row/column indices.
Output_Floating-point type of the output data. This should be capable of storing NaNs.
Parameters
rowWhether to compute the variance for each row. If false, the variance is computed for each column instead.
matInstance of a tatami::Matrix.
[out]outputBuffers to output arrays. On output, this will contain the row/column variances.
optFurther options.

◆ variance() [2/2]

template<typename Output_ = double, typename Value_ , typename Index_ >
VarianceResult< Output_ > tatami_stats::variance ( bool row,
const tatami::Matrix< Value_, Index_ > & mat,
const VarianceOptions & opt )

Overload of variance() that allocates memory for the output arrays.

Template Parameters
Output_Floating-point type of the output data. This should be capable of storing NaNs.
Value_Numeric type of the input data.
Index_Integer type of the row/column indices.
Parameters
rowWhether to compute the variance for each row. If false, the variance is computed for each column instead.
matInstance of a tatami::Matrix.
optFurther options.
Returns
The mean and variance of each row/column.