Skip to content

Commit bfc437b

Browse files
committed
clang-format
1 parent 699bb51 commit bfc437b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1815
-1538
lines changed

.clang-format

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
Language: Cpp
3+
AccessModifierOffset: -2
4+
AlignAfterOpenBracket: Align
5+
AlignConsecutiveAssignments: false
6+
AlignConsecutiveDeclarations: false
7+
AlignEscapedNewlinesLeft: true
8+
AlignOperands: true
9+
AlignTrailingComments: true
10+
AllowAllParametersOfDeclarationOnNextLine: true
11+
AllowShortBlocksOnASingleLine: true
12+
AllowShortCaseLabelsOnASingleLine: false
13+
AllowShortFunctionsOnASingleLine: All
14+
AllowShortIfStatementsOnASingleLine: true
15+
AllowShortLoopsOnASingleLine: true
16+
AlwaysBreakAfterDefinitionReturnType: None
17+
AlwaysBreakAfterReturnType: None
18+
AlwaysBreakBeforeMultilineStrings: true
19+
AlwaysBreakTemplateDeclarations: true
20+
BinPackArguments: true
21+
BinPackParameters: true
22+
BraceWrapping:
23+
AfterClass: false
24+
AfterControlStatement: false
25+
AfterEnum: false
26+
AfterFunction: false
27+
AfterNamespace: false
28+
AfterObjCDeclaration: false
29+
AfterStruct: false
30+
AfterUnion: false
31+
BeforeCatch: false
32+
BeforeElse: false
33+
IndentBraces: false
34+
BreakBeforeBinaryOperators: None
35+
BreakBeforeBraces: Attach
36+
BreakBeforeTernaryOperators: true
37+
BreakConstructorInitializersBeforeComma: false
38+
ColumnLimit: 78
39+
CommentPragmas: '^ IWYU pragma:'
40+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
41+
ConstructorInitializerIndentWidth: 4
42+
ContinuationIndentWidth: 4
43+
Cpp11BracedListStyle: true
44+
DerivePointerAlignment: false
45+
DisableFormat: false
46+
ExperimentalAutoDetectBinPacking: false
47+
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
48+
IncludeCategories:
49+
- Regex: '^<.*\.h>'
50+
Priority: 1
51+
- Regex: '^<.*'
52+
Priority: 2
53+
- Regex: '.*'
54+
Priority: 3
55+
IndentCaseLabels: true
56+
IndentWidth: 2
57+
IndentWrappedFunctionNames: false
58+
KeepEmptyLinesAtTheStartOfBlocks: true
59+
MacroBlockBegin: ''
60+
MacroBlockEnd: ''
61+
MaxEmptyLinesToKeep: 1
62+
NamespaceIndentation: None
63+
ObjCBlockIndentWidth: 2
64+
ObjCSpaceAfterProperty: false
65+
ObjCSpaceBeforeProtocolList: false
66+
PenaltyBreakBeforeFirstCallParameter: 1
67+
PenaltyBreakComment: 300
68+
PenaltyBreakFirstLessLess: 120
69+
PenaltyBreakString: 1000
70+
PenaltyExcessCharacter: 1000000
71+
PenaltyReturnTypeOnItsOwnLine: 200
72+
PointerAlignment: Left
73+
ReflowComments: true
74+
SortIncludes: true
75+
SpaceAfterCStyleCast: false
76+
SpaceBeforeAssignmentOperators: true
77+
SpaceBeforeParens: ControlStatements
78+
SpaceInEmptyParentheses: false
79+
SpacesBeforeTrailingComments: 1
80+
SpacesInAngles: false
81+
SpacesInContainerLiterals: true
82+
SpacesInCStyleCastParentheses: false
83+
SpacesInParentheses: false
84+
SpacesInSquareBrackets: false
85+
Standard: Auto
86+
TabWidth: 8
87+
UseTab: Never
88+
...

examples/getting_started_listing_01.cpp

Lines changed: 61 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -4,80 +4,75 @@
44
#include <iostream>
55

66
int main(int, char**) {
7-
namespace bh = boost::histogram;
8-
using namespace bh::literals; // enables _c suffix
7+
namespace bh = boost::histogram;
8+
using namespace bh::literals; // enables _c suffix
99

10-
/*
11-
create a static 1d-histogram with an axis that has 6 equidistant
12-
bins on the real line from -1.0 to 2.0, and label it as "x"
13-
*/
14-
auto h = bh::make_static_histogram(
15-
bh::axis::regular<>(6, -1.0, 2.0, "x")
16-
);
10+
/*
11+
create a static 1d-histogram with an axis that has 6 equidistant
12+
bins on the real line from -1.0 to 2.0, and label it as "x"
13+
*/
14+
auto h = bh::make_static_histogram(bh::axis::regular<>(6, -1.0, 2.0, "x"));
1715

18-
// fill histogram with data, typically this happens in a loop
19-
// STL algorithms are supported
20-
auto data = { -0.5, 1.1, 0.3, 1.7 };
21-
std::for_each(data.begin(), data.end(), h);
16+
// fill histogram with data, typically this happens in a loop
17+
// STL algorithms are supported
18+
auto data = {-0.5, 1.1, 0.3, 1.7};
19+
std::for_each(data.begin(), data.end(), h);
2220

23-
/*
24-
a regular axis is a sequence of semi-open bins; extra under- and
25-
overflow bins extend the axis in the default configuration
26-
index : -1 0 1 2 3 4 5 6
27-
bin edge: -inf -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 inf
28-
*/
29-
h(-1.5); // put in underflow bin -1
30-
h(-1.0); // put in bin 0, bin interval is semi-open
31-
h(2.0); // put in overflow bin 6, bin interval is semi-open
32-
h(20.0); // put in overflow bin 6
21+
/*
22+
a regular axis is a sequence of semi-open bins; extra under- and
23+
overflow bins extend the axis in the default configuration
24+
index : -1 0 1 2 3 4 5 6
25+
bin edge: -inf -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 inf
26+
*/
27+
h(-1.5); // put in underflow bin -1
28+
h(-1.0); // put in bin 0, bin interval is semi-open
29+
h(2.0); // put in overflow bin 6, bin interval is semi-open
30+
h(20.0); // put in overflow bin 6
3331

34-
/*
35-
do a weighted fill using bh::weight, a wrapper for any type,
36-
which may appear at the beginning of the argument list
37-
*/
38-
h(bh::weight(1.0), 0.1);
32+
/*
33+
do a weighted fill using bh::weight, a wrapper for any type,
34+
which may appear at the beginning of the argument list
35+
*/
36+
h(bh::weight(1.0), 0.1);
3937

40-
/*
41-
iterate over bins with a fancy histogram iterator
42-
- order in which bins are iterated over is an implementation detail
43-
- iterator dereferences to histogram::element_type, which is defined by
44-
its storage class; by default something with value() and
45-
variance() methods; the first returns the
46-
actual count, the second returns a variance estimate of the count
47-
(see Rationale section for what this means)
48-
- idx(N) method returns the index of the N-th axis
49-
- bin(N_c) method returns current bin of N-th axis; the suffx _c turns
50-
the argument into a compile-time number, which is needed to return
51-
different `bin_type`s for different axes
52-
- `bin_type` usually is a semi-open interval representing the bin, whose
53-
edges can be accessed with methods `lower()` and `upper()`, but the
54-
implementation depends on the axis, please look it up in the reference
55-
*/
56-
std::cout.setf(std::ios_base::fixed);
57-
for (auto it = h.begin(); it != h.end(); ++it) {
58-
const auto bin = it.bin(0_c);
59-
std::cout << "bin " << it.idx(0) << " x in ["
60-
<< std::setprecision(1)
61-
<< std::setw(4) << bin.lower() << ", "
62-
<< std::setw(4) << bin.upper() << "): "
63-
<< std::setprecision(1)
64-
<< it->value() << " +/- "
65-
<< std::setprecision(3) << std::sqrt(it->variance())
66-
<< std::endl;
67-
}
38+
/*
39+
iterate over bins with a fancy histogram iterator
40+
- order in which bins are iterated over is an implementation detail
41+
- iterator dereferences to histogram::element_type, which is defined by
42+
its storage class; by default something with value() and
43+
variance() methods; the first returns the
44+
actual count, the second returns a variance estimate of the count
45+
(see Rationale section for what this means)
46+
- idx(N) method returns the index of the N-th axis
47+
- bin(N_c) method returns current bin of N-th axis; the suffx _c turns
48+
the argument into a compile-time number, which is needed to return
49+
different `bin_type`s for different axes
50+
- `bin_type` usually is a semi-open interval representing the bin, whose
51+
edges can be accessed with methods `lower()` and `upper()`, but the
52+
implementation depends on the axis, please look it up in the reference
53+
*/
54+
std::cout.setf(std::ios_base::fixed);
55+
for (auto it = h.begin(); it != h.end(); ++it) {
56+
const auto bin = it.bin(0_c);
57+
std::cout << "bin " << it.idx(0) << " x in [" << std::setprecision(1)
58+
<< std::setw(4) << bin.lower() << ", " << std::setw(4)
59+
<< bin.upper() << "): " << std::setprecision(1) << it->value()
60+
<< " +/- " << std::setprecision(3) << std::sqrt(it->variance())
61+
<< std::endl;
62+
}
6863

69-
/* program output: (note that under- and overflow bins appear at the end)
64+
/* program output: (note that under- and overflow bins appear at the end)
7065
71-
bin 0 x in [-1.0, -0.5): 1 +/- 1
72-
bin 1 x in [-0.5, 0.0): 0 +/- 0
73-
bin 2 x in [ 0.0, 0.5): 1 +/- 1
74-
bin 3 x in [ 0.5, 1.0): 0 +/- 0
75-
bin 4 x in [ 1.0, 1.5): 0 +/- 0
76-
bin 5 x in [ 1.5, 2.0): 0 +/- 0
77-
bin 6 x in [ 2.0, inf): 2 +/- 1.41421
78-
bin -1 x in [-inf, -1): 1 +/- 1
66+
bin 0 x in [-1.0, -0.5): 1 +/- 1
67+
bin 1 x in [-0.5, 0.0): 0 +/- 0
68+
bin 2 x in [ 0.0, 0.5): 1 +/- 1
69+
bin 3 x in [ 0.5, 1.0): 0 +/- 0
70+
bin 4 x in [ 1.0, 1.5): 0 +/- 0
71+
bin 5 x in [ 1.5, 2.0): 0 +/- 0
72+
bin 6 x in [ 2.0, inf): 2 +/- 1.41421
73+
bin -1 x in [-inf, -1): 1 +/- 1
7974
80-
*/
75+
*/
8176
}
8277

8378
//]

examples/getting_started_listing_02.cpp

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,42 @@ namespace br = boost::random;
1010
namespace bh = boost::histogram;
1111

1212
int main() {
13-
/*
14-
create a dynamic histogram with the factory `make_dynamic_histogram`
15-
- axis can be passed directly just like for `make_static_histogram`
16-
- in addition, the factory also accepts iterators over a sequence of
17-
axis::any, the polymorphic type that can hold concrete axis types
18-
*/
19-
std::vector<bh::axis::any_std> axes;
20-
axes.emplace_back(bh::axis::category<std::string>({"red", "blue"}));
21-
axes.emplace_back(bh::axis::regular<>(5, -5, 5, "x"));
22-
axes.emplace_back(bh::axis::regular<>(5, -5, 5, "y"));
23-
auto h = bh::make_dynamic_histogram(axes.begin(), axes.end());
13+
/*
14+
create a dynamic histogram with the factory `make_dynamic_histogram`
15+
- axis can be passed directly just like for `make_static_histogram`
16+
- in addition, the factory also accepts iterators over a sequence of
17+
axis::any, the polymorphic type that can hold concrete axis types
18+
*/
19+
std::vector<bh::axis::any_std> axes;
20+
axes.emplace_back(bh::axis::category<std::string>({"red", "blue"}));
21+
axes.emplace_back(bh::axis::regular<>(5, -5, 5, "x"));
22+
axes.emplace_back(bh::axis::regular<>(5, -5, 5, "y"));
23+
auto h = bh::make_dynamic_histogram(axes.begin(), axes.end());
2424

25-
// fill histogram with random numbers
26-
br::mt19937 gen;
27-
br::normal_distribution<> norm;
28-
for (int i = 0; i < 1000; ++i)
29-
h(i % 2 ? "red" : "blue", norm(gen), norm(gen));
25+
// fill histogram with random numbers
26+
br::mt19937 gen;
27+
br::normal_distribution<> norm;
28+
for (int i = 0; i < 1000; ++i)
29+
h(i % 2 ? "red" : "blue", norm(gen), norm(gen));
3030

31-
/*
32-
print dynamic histogram by iterating over bins
33-
- for most axis types, the for loop looks just like for a static
34-
histogram, except that we can pass runtime numbers, too
35-
- if the [bin type] of the axis is not convertible to a
36-
double interval, one needs to cast axis::any before looping;
37-
this is here the case for the category axis
38-
*/
39-
using cas = bh::axis::category<std::string>;
40-
for (auto cbin : bh::axis::cast<cas>(h.axis(0))) {
41-
std::printf("%s\n", cbin.value().c_str());
42-
for (auto ybin : h.axis(2)) { // rows
43-
for (auto xbin : h.axis(1)) { // columns
44-
std::printf("%3.0f ", h.at(cbin, xbin, ybin).value());
45-
}
46-
std::printf("\n");
47-
}
31+
/*
32+
print dynamic histogram by iterating over bins
33+
- for most axis types, the for loop looks just like for a static
34+
histogram, except that we can pass runtime numbers, too
35+
- if the [bin type] of the axis is not convertible to a
36+
double interval, one needs to cast axis::any before looping;
37+
this is here the case for the category axis
38+
*/
39+
using cas = bh::axis::category<std::string>;
40+
for (auto cbin : bh::axis::cast<cas>(h.axis(0))) {
41+
std::printf("%s\n", cbin.value().c_str());
42+
for (auto ybin : h.axis(2)) { // rows
43+
for (auto xbin : h.axis(1)) { // columns
44+
std::printf("%3.0f ", h.at(cbin, xbin, ybin).value());
45+
}
46+
std::printf("\n");
4847
}
48+
}
4949
}
5050

5151
//]

examples/guide_access_bin_counts.cpp

Lines changed: 37 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,43 @@
77
namespace bh = boost::histogram;
88

99
int main() {
10-
// make histogram with 2 x 2 = 4 bins (not counting under-/overflow bins)
11-
auto h = bh::make_static_histogram(
12-
bh::axis::regular<>(2, -1, 1),
13-
bh::axis::regular<>(2, 2, 4)
14-
);
15-
16-
h(bh::weight(1), -0.5, 2.5); // bin index 0, 0
17-
h(bh::weight(2), -0.5, 3.5); // bin index 0, 1
18-
h(bh::weight(3), 0.5, 2.5); // bin index 1, 0
19-
h(bh::weight(4), 0.5, 3.5); // bin index 1, 1
20-
21-
// access count value, number of indices must match number of axes
22-
std::cout << h.at(0, 0).value() << " "
23-
<< h.at(0, 1).value() << " "
24-
<< h.at(1, 0).value() << " "
25-
<< h.at(1, 1).value()
26-
<< std::endl;
27-
28-
// prints: 1 2 3 4
29-
30-
// access count variance, number of indices must match number of axes
31-
std::cout << h.at(0, 0).variance() << " "
32-
<< h.at(0, 1).variance() << " "
33-
<< h.at(1, 0).variance() << " "
34-
<< h.at(1, 1).variance()
35-
<< std::endl;
36-
// prints: 1 4 9 16
37-
38-
// you can also make a copy of the type that holds the bin count
39-
auto c11 = h.at(1, 1);
40-
std::cout << c11.value() << " " << c11.variance() << std::endl;
41-
// prints: 4 16
42-
43-
// histogram also supports access via container; using a container of
44-
// wrong size trips an assertion in debug mode
45-
auto idx = {0, 1};
46-
std::cout << h.at(idx).value() << std::endl;
47-
// prints: 2
48-
49-
// histogram also provides extended iterators
50-
auto sum = std::accumulate(h.begin(), h.end(),
51-
typename decltype(h)::element_type(0));
52-
std::cout << sum.value() << " " << sum.variance() << std::endl;
53-
// prints: 10 30
10+
// make histogram with 2 x 2 = 4 bins (not counting under-/overflow bins)
11+
auto h = bh::make_static_histogram(bh::axis::regular<>(2, -1, 1),
12+
bh::axis::regular<>(2, 2, 4));
13+
14+
h(bh::weight(1), -0.5, 2.5); // bin index 0, 0
15+
h(bh::weight(2), -0.5, 3.5); // bin index 0, 1
16+
h(bh::weight(3), 0.5, 2.5); // bin index 1, 0
17+
h(bh::weight(4), 0.5, 3.5); // bin index 1, 1
18+
19+
// access count value, number of indices must match number of axes
20+
std::cout << h.at(0, 0).value() << " " << h.at(0, 1).value() << " "
21+
<< h.at(1, 0).value() << " " << h.at(1, 1).value() << std::endl;
22+
23+
// prints: 1 2 3 4
24+
25+
// access count variance, number of indices must match number of axes
26+
std::cout << h.at(0, 0).variance() << " " << h.at(0, 1).variance() << " "
27+
<< h.at(1, 0).variance() << " " << h.at(1, 1).variance()
28+
<< std::endl;
29+
// prints: 1 4 9 16
30+
31+
// you can also make a copy of the type that holds the bin count
32+
auto c11 = h.at(1, 1);
33+
std::cout << c11.value() << " " << c11.variance() << std::endl;
34+
// prints: 4 16
35+
36+
// histogram also supports access via container; using a container of
37+
// wrong size trips an assertion in debug mode
38+
auto idx = {0, 1};
39+
std::cout << h.at(idx).value() << std::endl;
40+
// prints: 2
41+
42+
// histogram also provides extended iterators
43+
auto sum = std::accumulate(h.begin(), h.end(),
44+
typename decltype(h)::element_type(0));
45+
std::cout << sum.value() << " " << sum.variance() << std::endl;
46+
// prints: 10 30
5447
}
5548

5649
//]

0 commit comments

Comments
 (0)