1#ifndef TATAMI_STATS_GROUPED_MEDIANS_HPP
2#define TATAMI_STATS_GROUPED_MEDIANS_HPP
11#include "sanisizer/sanisizer.hpp"
25namespace grouped_medians {
66template<
typename Value_,
typename Index_,
typename Group_,
class GroupSizes_,
typename Output_>
68 Index_ dim = (row ? mat.
nrow() : mat.
ncol());
69 Index_ otherdim = (row ? mat.
ncol() : mat.
nrow());
74 auto ngroups = group_sizes.size();
75 auto workspace = sanisizer::create<std::vector<std::vector<Value_> > >(ngroups);
76 for (I<
decltype(ngroups)> g = 0; g < ngroups; ++g) {
77 workspace[g].reserve(group_sizes[g]);
86 for (Index_ i = 0; i < len; ++i) {
87 auto range = ext->fetch(xbuffer.data(), ibuffer.data());
88 for (Index_ j = 0; j < range.number; ++j) {
89 workspace[group[range.index[j]]].push_back(range.value[j]);
92 for (I<
decltype(ngroups)> g = 0; g < ngroups; ++g) {
93 auto& w = workspace[g];
101 for (Index_ i = 0; i < len; ++i) {
102 auto ptr = ext->fetch(xbuffer.data());
103 for (Index_ j = 0; j < otherdim; ++j) {
104 workspace[group[j]].push_back(ptr[j]);
107 for (I<
decltype(ngroups)> g = 0; g < ngroups; ++g) {
108 auto& w = workspace[g];
121template<
typename Value_,
typename Index_,
typename Group_,
class GroupSizes_,
typename Output_>
123 apply(row, *p, group, group_sizes, output, mopt);
146template<
typename Output_ =
double,
typename Value_,
typename Index_,
typename Group_>
148 auto mydim = mat.
nrow();
151 auto output = sanisizer::create<std::vector<std::vector<Output_> > >(group_sizes.size());
152 std::vector<Output_*> ptrs;
153 ptrs.reserve(output.size());
154 for (
auto& o : output) {
156 ptrs.push_back(o.data());
159 apply(
true, mat, group, group_sizes, ptrs.data(), mopt);
166template<
typename Output_ =
double,
typename Value_,
typename Index_,
typename Group_>
171template<
typename Output_ =
double,
typename Value_,
typename Index_,
typename Group_>
176template<
typename Output_ =
double,
typename Value_,
typename Index_,
typename Group_>
201template<
typename Output_ =
double,
typename Value_,
typename Index_,
typename Group_>
203 auto mydim = mat.
ncol();
206 auto output = sanisizer::create<std::vector<std::vector<Output_> > >(group_sizes.size());
207 std::vector<Output_*> ptrs;
208 ptrs.reserve(output.size());
209 for (
auto& o : output) {
211 ptrs.push_back(o.data());
214 apply(
false, mat, group, group_sizes, ptrs.data(), mopt);
222template<
typename Output_ =
double,
typename Value_,
typename Index_,
typename Group_>
227template<
typename Output_ =
double,
typename Value_,
typename Index_,
typename Group_>
232template<
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:64
void parallelize(Function_ fun, const Index_ tasks, const int threads)
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_ordered_index
Utilities for computing matrix statistics.