• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018-2019 Hans Dembinski
2 //
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt
5 // or copy at http://www.boost.org/LICENSE_1_0.txt)
6 
7 #include <boost/accumulators/accumulators.hpp>
8 #include <boost/accumulators/statistics/mean.hpp>
9 #include <boost/accumulators/statistics/stats.hpp>
10 #include <boost/core/lightweight_test.hpp>
11 #include <boost/histogram/axis/integer.hpp>
12 #include <boost/histogram/make_histogram.hpp>
13 #include <boost/histogram/storage_adaptor.hpp>
14 #include "throw_exception.hpp"
15 
16 namespace ba = boost::accumulators;
17 
main()18 int main() {
19   using namespace boost::histogram;
20 
21   // mean
22   {
23     using mean = ba::accumulator_set<double, ba::stats<ba::tag::mean> >;
24 
25     auto h = make_histogram_with(dense_storage<mean>(), axis::integer<>(0, 2));
26     h(0, sample(1));
27     h(0, sample(2));
28     h(0, sample(3));
29     h(1, sample(2));
30     h(1, sample(3));
31     BOOST_TEST_EQ(ba::count(h[0]), 3);
32     BOOST_TEST_EQ(ba::mean(h[0]), 2);
33     BOOST_TEST_EQ(ba::count(h[1]), 2);
34     BOOST_TEST_EQ(ba::mean(h[1]), 2.5);
35     BOOST_TEST_EQ(ba::count(h[2]), 0);
36 
37     auto h2 = h; // copy ok
38     BOOST_TEST_EQ(ba::count(h2[0]), 3);
39     BOOST_TEST_EQ(ba::mean(h2[0]), 2);
40     BOOST_TEST_EQ(ba::count(h2[1]), 2);
41     BOOST_TEST_EQ(ba::mean(h2[1]), 2.5);
42     BOOST_TEST_EQ(ba::count(h2[2]), 0);
43   }
44   return boost::report_errors();
45 }
46