1#ifndef TATAMI_STATS_MEDIAN_HPP
2#define TATAMI_STATS_MEDIAN_HPP
12#include "sanisizer/sanisizer.hpp"
13#include "quickstats/quickstats.hpp"
43template<
typename Output_ =
double,
typename Value_,
typename Index_>
44Output_ median_direct(Value_* ptr, Index_ num,
bool skip_nan) {
45 nanable_ifelse<Value_>(
48 num = shift_nans(ptr, num);
53 return quickstats::median<Output_>(num, ptr);
56template<
typename Output_ =
double,
typename Value_,
typename Index_>
57Output_ median_direct(Value_* value, Index_ num_nonzero, Index_ num_all,
bool skip_nan) {
58 nanable_ifelse<Value_>(
61 auto new_nonzero = shift_nans(value, num_nonzero);
62 num_all -= num_nonzero - new_nonzero;
63 num_nonzero = new_nonzero;
68 return quickstats::median<Output_>(num_all, num_nonzero, value);
89template<
typename Value_,
typename Index_,
typename Output_>
91 const auto dim = (row ? mat.
nrow() : mat.
ncol());
92 const auto otherdim = (row ? mat.
ncol() : mat.
nrow());
102 auto vbuffer = buffer.data();
103 for (Index_ x = 0; x < l; ++x) {
104 auto range = ext->fetch(vbuffer, NULL);
106 output[x + s] = median_direct<Output_>(vbuffer,
range.number, otherdim, opt.
skip_nan);
114 for (Index_ x = 0; x < l; ++x) {
115 auto ptr = ext->fetch(buffer.data());
117 output[x + s] = median_direct<Output_>(buffer.data(), otherdim, opt.
skip_nan);
139template<
typename Output_ =
double,
typename Value_,
typename Index_>
141 const auto dim = (row ? mat.
nrow() : mat.
ncol());
142 auto output = sanisizer::create<std::vector<Output_> >(dim
143#ifdef TATAMI_STATS_TEST_DIRTY
147 median(row, mat, output.data(), opt);
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 count.hpp:20
void median(const bool row, const tatami::Matrix< Value_, Index_ > &mat, Output_ *const output, const MedianOptions &opt)
Definition median.hpp:90
void range(bool row, const tatami::Matrix< Value_, Index_ > &mat, RangeBuffers< Output_ > &output, const RangeOptions &opt)
Definition range.hpp:400
int parallelize(Function_ fun, const Index_ tasks, const int workers)
Value_ * copy_n(const Value_ *const input, const Size_ n, Value_ *const output)
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