You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://travis-ci.org/HDembinski/histogram?branch=master)
6
+
[](https://ci.appveyor.com/project/HDembinski/histogram/branch/master)
This `C++11` library provides a multi-dimensional [histogram](https://en.wikipedia.org/wiki/Histogram) class for your statistics needs. The library is **header-only**, if you don't need the Python module.
8
10
@@ -12,7 +14,7 @@ Tested platforms:
12
14
- Windows: Visual Studio 2015
13
15
- Python: 2.7 and 3.6
14
16
15
-
The histogram is very customisable through policy classes, but the default policies were carefully designed so that most users won't need to customize anything. In the standard configuration, this library offers a unique safety guarantee not found elsewhere: bin counts *cannot overflow* or *be capped*. While being safe to use, the library also has a convenient interface, is memory conserving, and faster than other libraries (see benchmarks).
17
+
The histogram is very customisable through policy classes, but the default policies were carefully designed so that most users don't need to customize anything. In the standard configuration, this library offers a unique safety guarantee not found elsewhere: bin counts *cannot overflow* or *be capped*. While being safe to use, the library also has a convenient interface, is memory conserving, and faster than other libraries (see benchmarks).
16
18
17
19
The histogram class comes in two variants which share a common interface. The *static* variant uses compile-time information to provide maximum performance, at the cost of runtime flexibility and potentially larger executables. The *dynamic* variant is a bit slower, but configurable at run-time and may produce smaller executables. Python bindings for the latter are included, implemented with `Boost.Python`.
18
20
@@ -66,11 +68,9 @@ To run the tests, do `make test`.
66
68
67
69
### Trouble-shooting when compiling with Python support
68
70
69
-
If you compile the library with Python support (the default if Python is found) and have several versions of Python installed, `cmake` will pick the latest Python version by default. Please make sure that this is the same version that Boost.Python and Boost.Numpy were compiled against, otherwise you will get strange errors during compilation and/or at runtime. You can force `cmake` to pick a specific Python version with the PYTHON_VERSION flag. For example, to force the use of Python2.7, do: `cmake -DPYTHON_VERSION=2.7 ../histogram/build`
71
+
If you compile the library with Python support (the default, when you compile at all) and have several versions of Python installed, `cmake` will use the Python interpreter that is accessible as `python` on your system, and will use the headers and libraries of this version. Please make sure that this is the same version that Boost.Python and Boost.Numpy were compiled against, otherwise you will get strange errors during compilation and/or at runtime! You can force `cmake` to pick a specific Python interpreter with the PYTHON_EXECUTABLE flag. For example, to force the use of `python3`, do: `cmake ../histogram/build -DPYTHON_EXECUTABLE=python3`
70
72
71
-
In the future, the build system may be able to pick the right Python version automatically, but right now it has to be done manually.
72
-
73
-
If you installed Boost with `brew` on OSX, also have a look at this [Stackoverflow](https://stackoverflow.com/questions/33653001/unable-to-link-against-boost-python-on-os-x) question.
73
+
If you installed Boost with `brew` on OSX and have trouble with the build, have a look at this [Stackoverflow](https://stackoverflow.com/questions/33653001/unable-to-link-against-boost-python-on-os-x) question.
74
74
75
75
## Code examples
76
76
@@ -85,39 +85,13 @@ int main(int, char**) {
85
85
namespace bh = boost::histogram;
86
86
using namespace bh::literals; // enables _c suffix
87
87
88
-
/*
89
-
create a static 1d-histogram with an axis that has 6 equidistant
90
-
bins on the real line from -1.0 to 2.0, and label it as "x"
91
-
*/
92
88
auto h = bh::make_static_histogram(
93
89
bh::axis::regular<>(6, -1.0, 2.0, "x")
94
90
);
95
91
96
-
// fill histogram with data, typically this happens in a loop
97
-
// STL algorithms are supported
98
-
auto data = { -0.5, 1.1, 0.3, 1.7 };
92
+
auto data = { -0.4, 1.1, 0.3, 1.7 };
99
93
std::for_each(data.begin(), data.end(), h);
100
94
101
-
/*
102
-
a regular axis is a sequence of semi-open bins; extra under- and
103
-
overflow bins extend the axis in the default configuration
104
-
index : -1 0 1 2 3 4 5 6
105
-
bin edge: -inf -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 inf
106
-
*/
107
-
h(-1.5); // put in underflow bin -1
108
-
h(-1.0); // put in bin 0, bin interval is semi-open
109
-
h(2.0); // put in overflow bin 6, bin interval is semi-open
110
-
h(20.0); // put in overflow bin 6
111
-
112
-
/*
113
-
do a weighted fill using bh::weight, a wrapper for any type,
114
-
which may appear at the beginning of the argument list
115
-
*/
116
-
h(bh::weight(1.0), 0.1);
117
-
118
-
/*
119
-
iterate over bins with a fancy histogram iterator
120
-
*/
121
95
for (auto it = h.begin(); it != h.end(); ++it) {
122
96
const auto bin = it.bin(0_c);
123
97
std::cout << "bin " << it.idx(0) << " x in ["
@@ -129,14 +103,14 @@ int main(int, char**) {
129
103
130
104
/* program output: (note that under- and overflow bins appear at the end)
131
105
132
-
bin 0 x in [-1.0, -0.5): 1 +/- 1
133
-
bin 1 x in [-0.5, 0.0): 0 +/- 0
106
+
bin 0 x in [-1.0, -0.5): 0 +/- 0
107
+
bin 1 x in [-0.5, 0.0): 1 +/- 1
134
108
bin 2 x in [ 0.0, 0.5): 1 +/- 1
135
109
bin 3 x in [ 0.5, 1.0): 0 +/- 0
136
110
bin 4 x in [ 1.0, 1.5): 1 +/- 1
137
-
bin 5 x in [ 1.5, 2.0): 0 +/- 0
138
-
bin 6 x in [ 2.0, inf): 2 +/- 1.41421
139
-
bin -1 x in [-inf, -1): 1 +/- 1
111
+
bin 5 x in [ 1.5, 2.0): 1 +/- 1
112
+
bin 6 x in [ 2.0, inf): 0 +/- 0
113
+
bin -1 x in [-inf, -1): 0 +/- 0
140
114
141
115
*/
142
116
}
@@ -148,22 +122,14 @@ Example 2: Fill a 2d-histogram in Python with data in Numpy arrays
148
122
import histogram as bh
149
123
import numpy as np
150
124
151
-
# create 2d-histogram over polar coordinates, with
152
-
# 10 equidistant bins in radius from 0 to 5 and
153
-
# 4 equidistant bins in polar angle
154
125
h = bh.histogram(bh.axis.regular(10, 0.0, 5.0, "radius", uoflow=False),
155
126
bh.axis.circular(4, 0.0, 2 * np.pi, "phi"))
156
127
157
-
# generate some numpy arrays with data to fill into histogram,
158
-
# in this case normal distributed random numbers in x and y,
159
-
# converted into polar coordinates
160
128
x = np.random.randn(1000) # generate x
161
129
y = np.random.randn(1000) # generate y
162
130
radius = (x ** 2 + y ** 2) ** 0.5
163
131
phi = np.arctan2(y, x)
164
132
165
-
# fill histogram with numpy arrays; call looks as
166
-
# if radius and phi are numbers instead of arrays
167
133
h(radius, phi)
168
134
169
135
# access histogram counts (no copy)
@@ -201,6 +167,6 @@ Read more about the design choices in the [documentation](http://hdembinski.gith
201
167
202
168
The histogram is feature-complete. More than 500 individual tests make sure that the implementation works as expected. Full documentation is available. User feedback is appreciated!
203
169
204
-
As we are finalising the interface in the review process, code breaking changes of the interface are not unlikely to happen. If you want to use the library in production code, please use the [latest release](https://github.com/HDembinski/histogram/releases) instead of the master. After the library is accepted as part of Boost, the interface will be kept stable, of course.
170
+
We are finalising the interface for the review process, so code-breaking changes of the interface are currently happening on the master. If you want to use the library in production code, please use the [latest release](https://github.com/HDembinski/histogram/releases) instead of the master. After the library is accepted as part of Boost, the interface will be kept stable, of course.
205
171
206
-
Review of the library was planned to happen in March 2018, but is delayed.
172
+
Review of the library is planned in September 2018.
0 commit comments