1#ifndef TATAMI_STATS_GROUPED_MEDIANS_HPP
2#define TATAMI_STATS_GROUPED_MEDIANS_HPP
22namespace grouped_medians {
64template<
typename Value_,
typename Index_,
typename Group_,
class GroupSizes_,
typename Output_>
66 Index_ dim = (row ? p->
nrow() : p->
ncol());
67 Index_ otherdim = (row ? p->
ncol() : p->
nrow());
70 std::vector<Value_> xbuffer(otherdim);
72 size_t ngroups = group_sizes.size();
73 std::vector<std::vector<double> > workspace(ngroups);
74 for (
size_t g = 0; g < ngroups; ++g) {
75 workspace[g].reserve(group_sizes[g]);
83 std::vector<Index_> ibuffer(otherdim);
84 for (Index_ i = 0; i < len; ++i) {
85 auto range = ext->fetch(xbuffer.data(), ibuffer.data());
86 for (Index_ j = 0; j < range.number; ++j) {
87 workspace[group[range.index[j]]].push_back(range.value[j]);
90 for (
size_t g = 0; g < ngroups; ++g) {
91 auto& w = workspace[g];
99 for (Index_ i = 0; i < len; ++i) {
100 auto ptr = ext->fetch(xbuffer.data());
101 for (Index_ j = 0; j < otherdim; ++j) {
102 workspace[group[j]].push_back(ptr[j]);
105 for (
size_t g = 0; g < ngroups; ++g) {
106 auto& w = workspace[g];
132template<
typename Output_ =
double,
typename Value_,
typename Index_,
typename Group_>
134 size_t mydim = p->
nrow();
137 std::vector<std::vector<Output_> > output(group_sizes.size());
138 std::vector<Output_*> ptrs;
139 ptrs.reserve(output.size());
140 for (
auto& o : output) {
142 ptrs.push_back(o.data());
145 apply(
true, p, group, group_sizes, ptrs.data(), mopt);
165template<
typename Output_ =
double,
typename Value_,
typename Index_,
typename Group_>
187template<
typename Output_ =
double,
typename Value_,
typename Index_,
typename Group_>
189 size_t mydim = p->
ncol();
192 std::vector<std::vector<Output_> > output(group_sizes.size());
193 std::vector<Output_*> ptrs;
194 ptrs.reserve(output.size());
195 for (
auto& o : output) {
197 ptrs.push_back(o.data());
200 apply(
false, p, group, group_sizes, ptrs.data(), mopt);
220template<
typename Output_ =
double,
typename Value_,
typename Index_,
typename Group_>
virtual Index_ ncol() const=0
virtual Index_ nrow() const=0
virtual std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(bool row, const Options &opt) const=0
Functions to compute statistics from a tatami::Matrix.
Definition counts.hpp:18
std::vector< Size_ > tabulate_groups(const Group_ *group, Size_ n)
Definition utils.hpp:49
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_ordered_index
Utilities for computing matrix statistics.