]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/histogram/examples/guide_axis_growing.cpp
1 // Copyright 2019 Hans Dembinski
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)
11 #include <boost/histogram.hpp>
17 using namespace boost::histogram
;
19 // make a growing regular axis
20 // - it grows new bins with its constant bin width until the value is covered
21 auto h1
= make_histogram(axis::regular
<double,
24 axis::option::growth_t
>{2, 0., 1.});
25 // nothing special happens here
28 // state: [0, 0.5): 1, [0.5, 1.0): 1
29 assert(h1
.axis().size() == 2);
30 assert(h1
.axis().bin(0).lower() == 0.0);
31 assert(h1
.axis().bin(1).upper() == 1.0);
33 // value below range: axis grows new bins until value is in range
35 // state: [-0.5, 0.0): 1, [0, 0.5): 1, [0.5, 1.0): 1
36 assert(h1
.axis().size() == 3);
37 assert(h1
.axis().bin(0).lower() == -0.5);
38 assert(h1
.axis().bin(2).upper() == 1.0);
41 // state: [-0.5, 0.0): 1, [0, 0.5): 1, [0.5, 1.0): 1, [1.0, 1.5): 0 [1.5, 2.0): 1
42 assert(h1
.axis().size() == 5);
43 assert(h1
.axis().bin(0).lower() == -0.5);
44 assert(h1
.axis().bin(4).upper() == 2.0);
46 // make a growing category axis (here strings)
47 // - empty axis is allowed: very useful if categories are not known at the beginning
48 auto h2
= make_histogram(axis::category
<std::string
,
50 axis::option::growth_t
>());
51 assert(h2
.size() == 0); // histogram is empty
52 h2("foo"); // new bin foo, index 0
53 assert(h2
.size() == 1);
54 h2("bar"); // new bin bar, index 1
55 assert(h2
.size() == 2);
57 assert(h2
.size() == 2);