1#ifndef TATAMI_STATS_SUM_HPP
2#define TATAMI_STATS_SUM_HPP
42template<
typename Value_,
typename Index_,
typename Output_>
44 const auto dim = (row ? mat.
nrow() : mat.
ncol());
45 const auto otherdim = (row ? mat.
ncol() : mat.
nrow());
54 nanable_ifelse<Value_>(
57 for (Index_ x = 0; x < l; ++x) {
58 const auto out = ext->fetch(vbuffer.data(), NULL);
60 for (Index_ i = 0; i < out.number; ++i) {
61 const auto val = out.value[i];
62 if (!std::isnan(val)) {
71 for (Index_ x = 0; x < l; ++x) {
72 const auto out = ext->fetch(vbuffer.data(), NULL);
84 nanable_ifelse<Value_>(
87 for (Index_ x = 0; x < l; ++x) {
88 const auto ptr = ext->fetch(buffer.data());
90 for (Index_ i = 0; i < otherdim; ++i) {
91 const auto val = ptr[i];
92 if (!std::isnan(val)) {
101 for (Index_ x = 0; x < l; ++x) {
102 const auto ptr = ext->fetch(buffer.data());
107 }, dim, opt.num_threads);
111template<
typename Value_,
typename Index_,
typename Output_>
113 const auto dim = (row ? mat.
nrow() : mat.
ncol());
114 const auto otherdim = (row ? mat.
ncol() : mat.
nrow());
116 const bool do_parallel = (opt.num_threads > 1);
117 std::optional<std::vector<std::optional<std::vector<Output_> > > > all_partial_sum;
119 all_partial_sum.emplace(sanisizer::cast<I<
decltype(all_partial_sum->size())> >(opt.num_threads - 1));
122 std::fill_n(output, dim, 0);
126 std::optional<std::vector<Output_> > cur_sum;
134 sum_ptr = cur_sum->data();
145 for (Index_ x = 0; x < l; ++x) {
146 const auto out = ext->fetch(vbuffer.data(), ibuffer.data());
147 nanable_ifelse<Value_>(
150 for (Index_ i = 0; i < out.number; ++i) {
151 const auto val = out.value[i];
152 sum_ptr[out.index[i]] += (std::isnan(val) ? 0 : val);
156 for (Index_ i = 0; i < out.number; ++i) {
157 sum_ptr[out.index[i]] += out.value[i];
167 for (Index_ x = 0; x < l; ++x) {
168 const auto ptr = ext->fetch(buffer.data());
169 nanable_ifelse<Value_>(
172 for (Index_ i = 0; i < dim; ++i) {
173 const auto val = ptr[i];
174 sum_ptr[i] += (std::isnan(val) ? 0 : val);
178 for (Index_ i = 0; i < dim; ++i) {
179 sum_ptr[i] += ptr[i];
188 (*all_partial_sum)[thread - 1] = std::move(cur_sum);
191 }, otherdim, opt.num_threads);
194 for (
int u = 1; u < nused; ++u) {
195 const auto& cur_sum = *((*all_partial_sum)[u - 1]);
196 for (Index_ d = 0; d < dim; ++d) {
197 output[d] += cur_sum[d];
224template<
typename Value_,
typename Index_,
typename Output_>
227 sum_direct(row, mat, output, opt);
229 sum_running(row, mat, output, opt);
249template<
typename Output_ =
double,
typename Value_,
typename Index_>
251 const auto dim = (row ? mat.
nrow() : mat.
ncol());
252 auto output = sanisizer::create<std::vector<Output_> >(dim
253#ifdef TATAMI_STATS_TEST_DIRTY
257 sum(row, mat, output.data(), opt);
virtual Index_ ncol() const=0
virtual Index_ nrow() const=0
virtual bool prefer_rows() const=0
virtual bool is_sparse() const=0
Output_ pairwise_sum(const std::size_t num_total, const Input_ *const ptr, PairwiseSumWorkspace< Output_ > &work, const PairwiseSumOptions &options)
Functions to compute statistics from a tatami::Matrix.
Definition count.hpp:20
void sum(bool row, const tatami::Matrix< Value_, Index_ > &mat, Output_ *output, const SumOptions &opt)
Definition sum.hpp:225
int parallelize(Function_ fun, const Index_ tasks, const int workers)
I< decltype(std::declval< Container_ >().size())> cast_Index_to_container_size(const Index_ x)
Container_ create_container_of_Index_size(const Index_ x, Args_ &&... args)
auto consecutive_extractor(const Matrix< Value_, Index_ > &matrix, const bool row, const Index_ iter_start, const Index_ iter_length, Args_ &&... args)
bool sparse_extract_index
bool sparse_ordered_index
Options for sum().
Definition sum.hpp:25
int num_threads
Definition sum.hpp:36
bool skip_nan
Definition sum.hpp:30