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 ? mat.
nrow() : mat.
ncol());
67 Index_ otherdim = (row ? mat.
ncol() : mat.
nrow());
70 std::vector<Value_> xbuffer(otherdim);
72 auto ngroups = group_sizes.size();
73 std::vector<std::vector<Value_> > workspace(ngroups);
74 for (
decltype(ngroups) 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 (
decltype(ngroups) 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 (
decltype(ngroups) g = 0; g < ngroups; ++g) {
106 auto& w = workspace[g];
119template<
typename Value_,
typename Index_,
typename Group_,
class GroupSizes_,
typename Output_>
121 apply(row, *p, group, group_sizes, output, mopt);
144template<
typename Output_ =
double,
typename Value_,
typename Index_,
typename Group_>
146 auto mydim = mat.
nrow();
149 std::vector<std::vector<Output_> > output(group_sizes.size());
150 std::vector<Output_*> ptrs;
151 ptrs.reserve(output.size());
152 for (
auto& o : output) {
154 ptrs.push_back(o.data());
157 apply(
true, mat, group, group_sizes, ptrs.data(), mopt);
164template<
typename Output_ =
double,
typename Value_,
typename Index_,
typename Group_>
169template<
typename Output_ =
double,
typename Value_,
typename Index_,
typename Group_>
174template<
typename Output_ =
double,
typename Value_,
typename Index_,
typename Group_>
199template<
typename Output_ =
double,
typename Value_,
typename Index_,
typename Group_>
201 auto mydim = mat.
ncol();
204 std::vector<std::vector<Output_> > output(group_sizes.size());
205 std::vector<Output_*> ptrs;
206 ptrs.reserve(output.size());
207 for (
auto& o : output) {
209 ptrs.push_back(o.data());
212 apply(
false, mat, group, group_sizes, ptrs.data(), mopt);
220template<
typename Output_ =
double,
typename Value_,
typename Index_,
typename Group_>
225template<
typename Output_ =
double,
typename Value_,
typename Index_,
typename Group_>
230template<
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:50
void parallelize(Function_ fun, Index_ tasks, int threads)
auto consecutive_extractor(const Matrix< Value_, Index_ > &matrix, bool row, Index_ iter_start, Index_ iter_length, Args_ &&... args)
bool sparse_ordered_index
Utilities for computing matrix statistics.