1#ifndef SCRAN_BLOCKS_PARALLEL_MEANS_HPP
2#define SCRAN_BLOCKS_PARALLEL_MEANS_HPP
11#include "sanisizer/sanisizer.hpp"
25template<
bool weighted_,
typename Stat_,
typename Weight_,
typename Output_>
26void parallel_means_internal(
const std::size_t n, std::vector<Stat_*> in,
const Weight_*
const w, Output_*
const out,
const bool skip_nan) {
27 const auto nblocks = in.size();
29 std::fill_n(out, n, std::numeric_limits<Output_>::quiet_NaN());
31 }
else if (nblocks == 1) {
32 if constexpr(weighted_) {
34 std::fill_n(out, n, std::numeric_limits<Output_>::quiet_NaN());
38 std::copy(in[0], in[0] + n, out);
43 for (I<
decltype(n)> i = 0; i < n; ++i) {
47 for (I<
decltype(nblocks)> b = 0; b < nblocks; ++b) {
48 const auto val = in[b][i];
49 if (!std::isnan(val)) {
50 if constexpr(weighted_) {
51 const auto curw = w[b];
65 std::fill_n(out, n, 0);
67 for (
const auto current : in) {
68 if constexpr(weighted_) {
69 const Weight_ weight = *(wcopy++);
71 for (I<
decltype(n)> i = 0; i < n; ++i) {
72 out[i] += current[i] * weight;
77 for (I<
decltype(n)> i = 0; i < n; ++i) {
82 const Output_ denom = [&]() {
83 if constexpr(weighted_) {
84 return std::accumulate(w, w + in.size(),
static_cast<Output_
>(0));
89 for (I<
decltype(n)> i = 0; i < n; ++i) {
113template<
typename Stat_,
typename Output_>
114void parallel_means(
const std::size_t n, std::vector<Stat_*> in, Output_*
const out,
const bool skip_nan) {
115 parallel_means_internal<false>(n, std::move(in),
static_cast<int*
>(NULL), out, skip_nan);
133template<
typename Output_ =
double,
typename Stat_>
134std::vector<Output_>
parallel_means(
const std::size_t n, std::vector<Stat_*> in,
const bool skip_nan) {
135 auto out = sanisizer::create<std::vector<Output_> >(n);
158template<
typename Stat_,
typename Weight_,
typename Output_>
159void parallel_weighted_means(
const std::size_t n, std::vector<Stat_*> in,
const Weight_*
const w, Output_*
const out,
const bool skip_nan) {
162 const auto numin = in.size();
163 for (I<
decltype(numin)> i = 1; i < numin; ++i) {
172 std::fill_n(out, n, std::numeric_limits<Output_>::quiet_NaN());
180 parallel_means_internal<true>(n, std::move(in), w, out, skip_nan);
201template<
typename Output_ =
double,
typename Stat_,
typename Weight_>
202std::vector<Output_>
parallel_weighted_means(
const std::size_t n, std::vector<Stat_*> in,
const Weight_*
const w,
const bool skip_nan) {
203 auto out = sanisizer::create<std::vector<Output_> >(n);
212template<
typename Stat_,
typename Output_>
213void average_vectors(
const std::size_t n, std::vector<Stat_*> in, Output_*
const out,
const bool skip_nan) {
217template<
typename Output_ =
double,
typename Stat_>
218std::vector<Output_> average_vectors(
const std::size_t n, std::vector<Stat_*> in,
const bool skip_nan) {
222template<
typename Stat_,
typename Weight_,
typename Output_>
223void average_vectors_weighted(
const std::size_t n, std::vector<Stat_*> in,
const Weight_*
const w, Output_*
const out,
const bool skip_nan) {
227template<
typename Output_ =
double,
typename Stat_,
typename Weight_>
228std::vector<Output_> average_vectors_weighted(
const std::size_t n, std::vector<Stat_*> in,
const Weight_*
const w,
const bool skip_nan) {
Blocking utilities for libscran.
Definition block_weights.hpp:17
void parallel_weighted_means(const std::size_t n, std::vector< Stat_ * > in, const Weight_ *const w, Output_ *const out, const bool skip_nan)
Definition parallel_means.hpp:159
void parallel_means(const std::size_t n, std::vector< Stat_ * > in, Output_ *const out, const bool skip_nan)
Definition parallel_means.hpp:114