From 412238ded72f1c41be15ac76e524f82572e54d9c Mon Sep 17 00:00:00 2001 From: lucieleblanc Date: Thu, 30 Apr 2020 22:18:58 -0400 Subject: [PATCH] Start printing basic info --- test/testutil/sample_tools.hpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/testutil/sample_tools.hpp b/test/testutil/sample_tools.hpp index 1d0e2022..b1ec6955 100644 --- a/test/testutil/sample_tools.hpp +++ b/test/testutil/sample_tools.hpp @@ -1,6 +1,7 @@ #pragma once #include "gtest/gtest.h" #include +#include #include #include #include @@ -51,4 +52,23 @@ inline void plot_hist(const ArrayType& arr, } } +inline void print_vector_stats(const std::vector& arr, std::string name = "", int precision = 6) +{ + const double sum = std::accumulate(arr.cbegin(), arr.cend(), 0); + double mean = sum / arr.size(); + + auto stddev_fold = [mean](double base, double newItem) { + return base + std::pow((newItem - mean), 2); + }; + + double sum_squares = std::accumulate(arr.begin(), arr.end(), 0.0, stddev_fold); + double stddev = std::sqrt(sum_squares / arr.size() - 1); + + std::cout << name; + std::cout << std::scientific << std::setprecision(precision); + std::cout << mean << std::endl; + std::cout << stddev << std::endl; +} + + } // namespace ppl