22template<
bool weighted_,
typename Stat_,
typename Weight_,
typename Output_>
23void average_vectors(
size_t n, std::vector<Stat_*> in,
const Weight_* w, Output_* out,
bool skip_nan) {
25 std::fill_n(out, n, std::numeric_limits<Output_>::quiet_NaN());
27 }
else if (in.size() == 1) {
28 if constexpr(weighted_) {
30 std::fill_n(out, n, std::numeric_limits<Output_>::quiet_NaN());
34 std::copy(in[0], in[0] + n, out);
38 std::fill_n(out, n, 0);
39 std::vector<Weight_> accumulated(skip_nan ? n : 0);
42 for (
auto current : in) {
45 if constexpr(weighted_) {
48 Weight_ weight = *(wcopy++);
53 for (
size_t i = 0; i < n; ++i, ++current, ++copy) {
54 auto x = *current * weight;
57 accumulated[i] += weight;
61 for (
size_t i = 0; i < n; ++i, ++current, ++copy) {
62 *copy += *current * weight;
70 for (
size_t i = 0; i < n; ++i, ++current, ++copy) {
78 for (
size_t i = 0; i < n; ++i, ++current, ++copy) {
85 for (
size_t i = 0; i < n; ++i, ++out) {
86 *out /= accumulated[i];
90 if constexpr(weighted_) {
91 denom /= std::accumulate(w, w + in.size(), 0.0);
95 for (
size_t i = 0; i < n; ++i, ++out) {
120template<
typename Stat_,
typename Output_>
122 internal::average_vectors<false>(
n, std::move(
in),
static_cast<int*
>(
NULL),
out,
skip_nan);
138template<
typename Output_ =
double,
typename Stat_>
140 std::vector<Output_>
out(
n);
162template<
typename Stat_,
typename Weight_,
typename Output_>
166 for (
size_t i = 1,
end =
in.size();
i <
end; ++
i) {
175 std::fill_n(
out,
n, std::numeric_limits<Output_>::quiet_NaN());
202template<
typename Output_ =
double,
typename Stat_,
typename Weight_>
204 std::vector<Output_>
out(
n);
void average_vectors_weighted(size_t n, std::vector< Stat_ * > in, const Weight_ *w, Output_ *out, bool skip_nan)
Definition average_vectors.hpp:163
void average_vectors(size_t n, std::vector< Stat_ * > in, Output_ *out, bool skip_nan)
Definition average_vectors.hpp:121