Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / histogram / README.md
1 <!--
2   Copyright Hans Dembinski 2016 - 2019.
3   Distributed under the Boost Software License, Version 1.0.
4   (See accompanying file LICENSE_1_0.txt or copy at
5   https://www.boost.org/LICENSE_1_0.txt)
6 -->
7
8 ![](doc/logo/color.svg)
9
10 **Fast multi-dimensional histogram with convenient interface for C++14**
11
12 Coded with ❤. Powered by the [Boost community](https://www.boost.org) and the [Scikit-HEP Project](http://scikit-hep.org). Licensed under the [Boost Software License](http://www.boost.org/LICENSE_1_0.txt).
13
14 **Supported compiler versions** gcc >= 5.5, clang >= 3.8, msvc >= 14.1
15
16 Branch  | Linux and OSX | Windows | Coverage
17 ------- | ------------- |-------- | --------
18 develop | [![Build Status Travis](https://travis-ci.org/boostorg/histogram.svg?branch=develop)](https://travis-ci.org/boostorg/histogram/branches) | [![Build status Appveyor](https://ci.appveyor.com/api/projects/status/p27laa26ti1adyf1/branch/develop?svg=true)](https://ci.appveyor.com/project/HDembinski/histogram-d5g5k/branch/develop) | [![Coveralls](https://coveralls.io/repos/github/boostorg/histogram/badge.svg?branch=develop)](https://coveralls.io/github/boostorg/histogram?branch=develop)
19 master  | [![Build Status Travis](https://travis-ci.org/boostorg/histogram.svg?branch=master)](https://travis-ci.org/boostorg/histogram/branches) | [![Build status Appveyor](https://ci.appveyor.com/api/projects/status/p27laa26ti1adyf1/branch/master?svg=true)](https://ci.appveyor.com/project/HDembinski/histogram-d5g5k/branch/master) | [![Coveralls](https://coveralls.io/repos/github/boostorg/histogram/badge.svg?branch=master)](https://coveralls.io/github/boostorg/histogram?branch=master)
20
21 Boost.Histogram is a very fast state-of-the-art multi-dimensional [histogram](https://en.wikipedia.org/wiki/Histogram) class for the beginner and expert alike.
22
23 * Header-only
24 * Easy to use, easy to customize
25 * Just count or use arbitrary accumulators to compute means, minimum, maximum, ...
26 * Supports multi-threading and restricted environments (no heap allocation, exceptions or RTTI)
27 * Has [Python bindings](https://github.com/scikit-hep/boost-histogram)
28
29 Check out the [full documentation](https://www.boost.org/doc/libs/develop/libs/histogram/doc/html/index.html).
30
31 💡 Boost.Histogram is a mature library, but if you find some issue or find the documentation lacking, tell us about it by [submitting an issue](https://github.com/boostorg/histogram/issues). Chat with us on the [Boost channel on Slack](https://cpplang.slack.com) and [Gitter](https://gitter.im/boostorg/histogram).
32
33 ## Code examples
34
35 The following stripped-down example was taken from the [Getting started](https://www.boost.org/doc/libs/develop/libs/histogram/doc/html/histogram/getting_started.html) section in the documentation. Have a look into the docs to see the full version with comments and more examples.
36
37 Example: Make and fill a 1d-histogram ([try it live on Wandbox](https://wandbox.org/permlink/NSM2ZiDyntUi6RDC)). The core of this example [compiles into 53 lines of assembly code](https://godbolt.org/z/632yzE).
38
39 ```cpp
40 #include <boost/histogram.hpp>
41 #include <boost/format.hpp> // used here for printing
42 #include <iostream>
43
44 int main() {
45     using namespace boost::histogram;
46
47     // make 1d histogram with 4 regular bins from 0 to 2
48     auto h = make_histogram( axis::regular<>(4, 0.0, 2.0) );
49
50     // push some values into the histogram
51     for (auto&& value : { 0.4, 1.1, 0.3, 1.7, 10. })
52       h(value);
53
54     // iterate over bins
55     for (auto&& x : indexed(h)) {
56       std::cout << boost::format("bin %i [ %.1f, %.1f ): %i\n")
57         % x.index() % x.bin().lower() % x.bin().upper() % *x;
58     }
59
60     std::cout << std::flush;
61
62     /* program output:
63
64     bin 0 [ 0.0, 0.5 ): 2
65     bin 1 [ 0.5, 1.0 ): 0
66     bin 2 [ 1.0, 1.5 ): 1
67     bin 3 [ 1.5, 2.0 ): 1
68     */
69 }
70 ```
71
72 ## Features
73
74 * Extremely customisable multi-dimensional histogram
75 * Simple, convenient, STL and Boost-compatible interface
76 * Counters with high dynamic range, cannot overflow or be capped [[1]](#note1)
77 * Better performance than other libraries (see benchmarks for details)
78 * Efficient use of memory [[1]](#note1)
79 * Support for custom axis types: define how input values should map to indices
80 * Support for under-/overflow bins (can be disabled individually to reduce memory consumption)
81 * Support for axes that grow automatically with input values [[2]](#note2)
82 * Support for weighted increments
83 * Support for profiles and more generally, user-defined accumulators in cells [[3]](#note3)
84 * Support for completely stack-based histograms
85 * Support for compilation without exceptions or RTTI [[4]](#note4)
86 * Support for adding, subtracting, multiplying, dividing, and scaling histograms
87 * Support for custom allocators
88 * Support for programming with units [[5]](#note5)
89 * Optional serialization based on [Boost.Serialization](https://www.boost.org/doc/libs/release/libs/serialization/)
90
91 <b id="note1">Note 1</b> In the standard configuration, if you don't use weighted increments. The counter capacity is increased dynamically as the cell counts grow. When even the largest plain integral type would overflow, the storage switches to a multiprecision integer similar to those in [Boost.Multiprecision](https://www.boost.org/doc/libs/release/libs/multiprecision/), which is only limited by available memory.
92
93 <b id="note2">Note 2</b> An axis can be configured to grow when a value is encountered that is outside of its range. It then grows new bins towards this value so that the value ends up in the new highest or lowest bin.
94
95 <b id="note3">Note 3</b> The histogram can be configured to hold an arbitrary accumulator in each cell instead of a simple counter. Extra values can be passed to the histogram, for example, to compute the mean and variance of values which fall into the same cell. This feature can be used to calculate variance estimates for each cell, which are useful when you need to fit a statistical model to the cell values.
96
97 <b id="note4">Note 4</b> The library throws exceptions when exceptions are enabled. When exceptions are disabled, a user-defined exception handler is called instead upon a throw and the program terminates, see [boost::throw_exception](https://www.boost.org/doc/libs/master/libs/exception/doc/throw_exception.html) for details. Disabling exceptions improves performance by 10 % to 20 % in benchmarks. The library does not use RTTI (only CTTI) so disabling it has no effect.
98
99 <b id="note5">Note 5</b> Builtin axis types can be configured to only accept dimensional quantities, like those from [Boost.Units](https://www.boost.org/doc/libs/release/libs/units/). This means you get a useful error if you accidentally try to fill a length where the histogram axis expects a time, for example.
100
101 ## Benchmarks
102
103 Boost.Histogram is more flexible and faster than other C/C++ libraries. It was compared to:
104  - [GNU Scientific Library](https://www.gnu.org/software/gsl)
105  - [ROOT framework from CERN](https://root.cern.ch)
106
107 Details on the benchmark are given in the [documentation](https://www.boost.org/doc/libs/develop/libs/histogram/doc/html/histogram/benchmarks.html).
108
109 ## What users say
110
111 **John Buonagurio** | Manager at [**E<sup><i>x</i></sup>ponent<sup>&reg;</sup>**](https://www.exponent.com)
112
113 *"I just wanted to say 'thanks' for your awesome Histogram library. I'm working on a software package for processing meteorology data and I'm using it to generate wind roses with the help of Qt and QwtPolar. Looks like you thought of just about everything here &ndash; the circular axis type was practically designed for this application, everything 'just worked'."*