1#ifndef TATAMI_STATS_GROUPED_MEDIANS_HPP
2#define TATAMI_STATS_GROUPED_MEDIANS_HPP
11#include "sanisizer/sanisizer.hpp"
25namespace grouped_medians {
67template<
typename Value_,
typename Index_,
typename Group_,
class GroupSizes_,
typename Output_>
69 Index_ dim = (row ? mat.
nrow() : mat.
ncol());
70 Index_ otherdim = (row ? mat.
ncol() : mat.
nrow());
75 auto ngroups = group_sizes.size();
76 auto workspace = sanisizer::create<std::vector<std::vector<Value_> > >(ngroups);
77 for (
decltype(ngroups) g = 0; g < ngroups; ++g) {
78 workspace[g].reserve(group_sizes[g]);
87 for (Index_ i = 0; i < len; ++i) {
88 auto range = ext->fetch(xbuffer.data(), ibuffer.data());
89 for (Index_ j = 0; j < range.number; ++j) {
90 workspace[group[range.index[j]]].push_back(range.value[j]);
93 for (
decltype(ngroups) g = 0; g < ngroups; ++g) {
94 auto& w = workspace[g];
102 for (Index_ i = 0; i < len; ++i) {
103 auto ptr = ext->fetch(xbuffer.data());
104 for (Index_ j = 0; j < otherdim; ++j) {
105 workspace[group[j]].push_back(ptr[j]);
108 for (
decltype(ngroups) g = 0; g < ngroups; ++g) {
109 auto& w = workspace[g];
122template<
typename Value_,
typename Index_,
typename Group_,
class GroupSizes_,
typename Output_>
124 apply(row, *p, group, group_sizes, output, mopt);
147template<
typename Output_ =
double,
typename Value_,
typename Index_,
typename Group_>
149 auto mydim = mat.
nrow();
152 auto output = sanisizer::create<std::vector<std::vector<Output_> > >(group_sizes.size());
153 std::vector<Output_*> ptrs;
154 ptrs.reserve(output.size());
155 for (
auto& o : output) {
157 ptrs.push_back(o.data());
160 apply(
true, mat, group, group_sizes, ptrs.data(), mopt);
167template<
typename Output_ =
double,
typename Value_,
typename Index_,
typename Group_>
172template<
typename Output_ =
double,
typename Value_,
typename Index_,
typename Group_>
177template<
typename Output_ =
double,
typename Value_,
typename Index_,
typename Group_>
202template<
typename Output_ =
double,
typename Value_,
typename Index_,
typename Group_>
204 auto mydim = mat.
ncol();
207 auto output = sanisizer::create<std::vector<std::vector<Output_> > >(group_sizes.size());
208 std::vector<Output_*> ptrs;
209 ptrs.reserve(output.size());
210 for (
auto& o : output) {
212 ptrs.push_back(o.data());
215 apply(
false, mat, group, group_sizes, ptrs.data(), mopt);
223template<
typename Output_ =
double,
typename Value_,
typename Index_,
typename Group_>
228template<
typename Output_ =
double,
typename Value_,
typename Index_,
typename Group_>
233template<
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:53
void parallelize(Function_ fun, Index_ tasks, int threads)
Container_ create_container_of_Index_size(Index_ x, Args_ &&... args)
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.