1#ifndef TATAMI_STATS_QUANTILE_HPP
2#define TATAMI_STATS_QUANTILE_HPP
13#include "sanisizer/sanisizer.hpp"
14#include "quickstats/quickstats.hpp"
58template<
typename Value_,
typename Index_,
typename Output_>
63 Output_*
const output,
66 const auto dim = (row ? mat.
nrow() : mat.
ncol());
67 const auto otherdim = (row ? mat.
ncol() : mat.
nrow());
70 std::fill_n(output, dim, std::numeric_limits<Output_>::quiet_NaN());
75 std::optional<quickstats::SingleQuantileFixedNumber<Output_> > qcalcs_fixed;
76 std::optional<quickstats::SingleQuantileVariableNumber<Output_> > qcalcs_var;
78 nanable_ifelse<Value_>(
81 qcalcs_var.emplace(otherdim, prob);
84 qcalcs_fixed.emplace(otherdim, prob);
94 auto vbuffer = buffer.data();
96 for (Index_ x = 0; x < l; ++x) {
97 auto range = ext->fetch(vbuffer, NULL);
100 nanable_ifelse<Value_>(
103 const auto new_non_zeros = shift_nans(vbuffer, range.number);
104 output[x + s] = (*qcalcs_var)(otherdim - (range.number - new_non_zeros), new_non_zeros, vbuffer);
107 output[x + s] = (*qcalcs_fixed)(range.number, vbuffer);
116 for (Index_ x = 0; x < l; ++x) {
117 auto bufptr = buffer.data();
118 auto raw = ext->fetch(bufptr);
121 nanable_ifelse<Value_>(
124 const auto new_total = shift_nans(bufptr, otherdim);
125 output[x + s] = (*qcalcs_var)(new_total, bufptr);
128 output[x + s] = (*qcalcs_fixed)(bufptr);
154template<
typename Output_ =
double,
typename Value_,
typename Index_>
161 const auto dim = (row ? mat.
nrow() : mat.
ncol());
162 auto output = sanisizer::create<std::vector<Output_> >(dim
163#ifdef TATAMI_STATS_TEST_DIRTY
167 quantile(row, mat, prob, 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 quantile(const bool row, const tatami::Matrix< Value_, Index_ > &mat, const double prob, Output_ *const output, const QuantileOptions &opt)
Definition quantile.hpp:59
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
Options for quantile().
Definition quantile.hpp:27
int num_threads
Definition quantile.hpp:38
bool skip_nan
Definition quantile.hpp:32