Skip to content

Commit

Permalink
Start printing basic info
Browse files Browse the repository at this point in the history
  • Loading branch information
lucieleblanc committed May 1, 2020
1 parent 61a6fc4 commit 412238d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/testutil/sample_tools.hpp
@@ -1,6 +1,7 @@
#pragma once
#include "gtest/gtest.h"
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <cstddef>
Expand Down Expand Up @@ -51,4 +52,23 @@ inline void plot_hist(const ArrayType& arr,
}
}

inline void print_vector_stats(const std::vector<double>& 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

0 comments on commit 412238d

Please sign in to comment.