27template<
bool weighted_,
typename Stat_,
typename Weight_,
typename Output_>
28void average_vectors(
const std::size_t n, std::vector<Stat_*> in,
const Weight_*
const w, Output_*
const out,
const bool skip_nan) {
30 std::fill_n(out, n, std::numeric_limits<Output_>::quiet_NaN());
32 }
else if (in.size() == 1) {
33 if constexpr(weighted_) {
35 std::fill_n(out, n, std::numeric_limits<Output_>::quiet_NaN());
39 std::copy(in[0], in[0] + n, out);
43 std::fill_n(out, n, 0);
44 std::vector<Weight_> accumulated(skip_nan ? n : 0);
47 for (
const auto current : in) {
48 if constexpr(weighted_) {
51 const Weight_ weight = *(wcopy++);
56 for (
decltype(I(n)) i = 0; i < n; ++i) {
57 const auto x = current[i] * weight;
60 accumulated[i] += weight;
64 for (
decltype(I(n)) i = 0; i < n; ++i) {
65 out[i] += current[i] * weight;
73 for (
decltype(I(n)) i = 0; i < n; ++i) {
74 const auto x = current[i];
81 for (
decltype(I(n)) i = 0; i < n; ++i) {
88 for (
decltype(I(n)) i = 0; i < n; ++i) {
89 out[i] /= accumulated[i];
93 if constexpr(weighted_) {
94 denom /= std::accumulate(w, w + in.size(),
static_cast<Output_
>(0));
98 for (
decltype(I(n)) i = 0; i < n; ++i) {
124template<
typename Stat_,
typename Output_>
125void average_vectors(
const std::size_t n, std::vector<Stat_*> in, Output_*
const out,
const bool skip_nan) {
126 internal::average_vectors<false>(n, std::move(in),
static_cast<int*
>(NULL), out, skip_nan);
143template<
typename Output_ =
double,
typename Stat_>
144std::vector<Output_>
average_vectors(
const std::size_t n, std::vector<Stat_*> in,
const bool skip_nan) {
145 auto out = sanisizer::create<std::vector<Output_> >(n);
168template<
typename Stat_,
typename Weight_,
typename Output_>
169void average_vectors_weighted(
const std::size_t n, std::vector<Stat_*> in,
const Weight_*
const w, Output_*
const out,
const bool skip_nan) {
172 const auto numin = in.size();
173 for (
decltype(I(numin)) i = 1; i < numin; ++i) {
182 std::fill_n(out, n, std::numeric_limits<Output_>::quiet_NaN());
190 internal::average_vectors<true>(n, std::move(in), w, out, skip_nan);
209template<
typename Output_ =
double,
typename Stat_,
typename Weight_>
210std::vector<Output_>
average_vectors_weighted(
const std::size_t n, std::vector<Stat_*> in,
const Weight_*
const w,
const bool skip_nan) {
211 auto out = sanisizer::create<std::vector<Output_> >(n);
void average_vectors(const std::size_t n, std::vector< Stat_ * > in, Output_ *const out, const bool skip_nan)
Definition average_vectors.hpp:125
void average_vectors_weighted(const std::size_t n, std::vector< Stat_ * > in, const Weight_ *const w, Output_ *const out, const bool skip_nan)
Definition average_vectors.hpp:169