1#ifndef TATAMI_STATS__SUMS_HPP
2#define TATAMI_STATS__SUMS_HPP
56template<
typename Output_ =
double,
typename Value_,
typename Index_>
57Output_
direct(
const Value_* ptr, Index_ num,
bool skip_nan) {
58 return internal::nanable_ifelse_with_value<Value_>(
62 for (Index_ i = 0; i < num; ++i) {
64 if (!std::isnan(val)) {
71 return std::accumulate(ptr, ptr + num,
static_cast<Output_
>(0));
92template<
typename Output_,
typename Value_,
typename Index_>
101 RunningDense(Index_ num, Output_* sum,
bool skip_nan) : my_num(num), my_sum(sum), my_skip_nan(skip_nan) {}
107 void add(
const Value_* ptr) {
108 internal::nanable_ifelse<Value_>(
111 for (Index_ i = 0; i < my_num; ++i) {
113 if (!std::isnan(val)) {
119 for (Index_ i = 0; i < my_num; ++i) {
142template<
typename Output_,
typename Value_,
typename Index_>
154 my_sum(sum), my_skip_nan(skip_nan), my_subtract(subtract) {}
163 void add(
const Value_* value,
const Index_* index, Index_ number) {
164 internal::nanable_ifelse<Value_>(
167 for (Index_ i = 0; i < number; ++i) {
169 if (!std::isnan(val)) {
170 my_sum[index[i] - my_subtract] += val;
175 for (Index_ i = 0; i < number; ++i) {
176 my_sum[index[i] - my_subtract] += value[i];
206template<
typename Value_,
typename Index_,
typename Output_>
208 auto dim = (row ? p->
nrow() : p->
ncol());
209 auto otherdim = (row ? p->
ncol() : p->
nrow());
219 std::vector<Value_> vbuffer(otherdim);
220 for (Index_ x = 0; x < l; ++x) {
221 auto out = ext->fetch(vbuffer.data(), NULL);
232 std::vector<Value_> vbuffer(l);
233 std::vector<Index_> ibuffer(l);
238 for (Index_ x = 0; x < otherdim; ++x) {
239 auto out = ext->fetch(vbuffer.data(), ibuffer.data());
240 runner.
add(out.value, out.index, out.number);
251 std::vector<Value_> buffer(otherdim);
252 for (Index_ x = 0; x < l; ++x) {
253 auto out = ext->fetch(buffer.data());
261 std::vector<Value_> buffer(l);
266 for (Index_ x = 0; x < otherdim; ++x) {
267 auto out = ext->fetch(buffer.data());
290template<
typename Output_ =
double,
typename Value_,
typename Index_>
292 std::vector<Output_> output(p->
ncol());
293 apply(
false, p, output.data(), sopt);
307template<
typename Output_ =
double,
typename Value_,
typename Index_>
323template<
typename Output_ =
double,
typename Value_,
typename Index_>
325 std::vector<Output_> output(p->
nrow());
326 apply(
true, p, output.data(), sopt);
340template<
typename Output_ =
double,
typename Value_,
typename Index_>
virtual Index_ ncol() const=0
virtual Index_ nrow() const=0
virtual bool prefer_rows() const=0
virtual std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(bool row, const Options &opt) const=0
Local output buffer for running calculations.
Definition utils.hpp:78
void transfer()
Definition utils.hpp:135
Output_ * data()
Definition utils.hpp:118
Running sums from dense data.
Definition sums.hpp:93
void add(const Value_ *ptr)
Definition sums.hpp:107
RunningDense(Index_ num, Output_ *sum, bool skip_nan)
Definition sums.hpp:101
Running sums from sparse data.
Definition sums.hpp:143
void add(const Value_ *value, const Index_ *index, Index_ number)
Definition sums.hpp:163
RunningSparse(Output_ *sum, bool skip_nan, Index_ subtract=0)
Definition sums.hpp:153
std::vector< Output_ > by_column(const tatami::Matrix< Value_, Index_ > *p, const Options &sopt)
Definition sums.hpp:291
void apply(bool row, const tatami::Matrix< Value_, Index_ > *p, Output_ *output, const Options &sopt)
Definition sums.hpp:207
std::vector< Output_ > by_row(const tatami::Matrix< Value_, Index_ > *p, const Options &sopt)
Definition sums.hpp:324
Output_ direct(const Value_ *ptr, Index_ num, bool skip_nan)
Definition sums.hpp:57
Functions to compute statistics from a tatami::Matrix.
Definition counts.hpp:18
void parallelize(Function_ fun, Index_ tasks, int threads)
auto consecutive_extractor(const Matrix< Value_, Index_ > *mat, bool row, Index_ iter_start, Index_ iter_length, Args_ &&... args)
bool sparse_extract_index
bool sparse_ordered_index
Summation options.
Definition sums.hpp:28
int num_threads
Definition sums.hpp:39
bool skip_nan
Definition sums.hpp:33
Utilities for computing matrix statistics.