Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
HDembinski committed Jul 21, 2018
1 parent 699bb51 commit bfc437b
Show file tree
Hide file tree
Showing 53 changed files with 1,815 additions and 1,538 deletions.
88 changes: 88 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
Language: Cpp
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: true
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 78
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeCategories:
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IndentCaseLabels: true
IndentWidth: 2
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
TabWidth: 8
UseTab: Never
...
127 changes: 61 additions & 66 deletions examples/getting_started_listing_01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,80 +4,75 @@
#include <iostream>

int main(int, char**) {
namespace bh = boost::histogram;
using namespace bh::literals; // enables _c suffix
namespace bh = boost::histogram;
using namespace bh::literals; // enables _c suffix

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

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

/*
a regular axis is a sequence of semi-open bins; extra under- and
overflow bins extend the axis in the default configuration
index : -1 0 1 2 3 4 5 6
bin edge: -inf -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 inf
*/
h(-1.5); // put in underflow bin -1
h(-1.0); // put in bin 0, bin interval is semi-open
h(2.0); // put in overflow bin 6, bin interval is semi-open
h(20.0); // put in overflow bin 6
/*
a regular axis is a sequence of semi-open bins; extra under- and
overflow bins extend the axis in the default configuration
index : -1 0 1 2 3 4 5 6
bin edge: -inf -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 inf
*/
h(-1.5); // put in underflow bin -1
h(-1.0); // put in bin 0, bin interval is semi-open
h(2.0); // put in overflow bin 6, bin interval is semi-open
h(20.0); // put in overflow bin 6

/*
do a weighted fill using bh::weight, a wrapper for any type,
which may appear at the beginning of the argument list
*/
h(bh::weight(1.0), 0.1);
/*
do a weighted fill using bh::weight, a wrapper for any type,
which may appear at the beginning of the argument list
*/
h(bh::weight(1.0), 0.1);

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

/* program output: (note that under- and overflow bins appear at the end)
/* program output: (note that under- and overflow bins appear at the end)
bin 0 x in [-1.0, -0.5): 1 +/- 1
bin 1 x in [-0.5, 0.0): 0 +/- 0
bin 2 x in [ 0.0, 0.5): 1 +/- 1
bin 3 x in [ 0.5, 1.0): 0 +/- 0
bin 4 x in [ 1.0, 1.5): 0 +/- 0
bin 5 x in [ 1.5, 2.0): 0 +/- 0
bin 6 x in [ 2.0, inf): 2 +/- 1.41421
bin -1 x in [-inf, -1): 1 +/- 1
bin 0 x in [-1.0, -0.5): 1 +/- 1
bin 1 x in [-0.5, 0.0): 0 +/- 0
bin 2 x in [ 0.0, 0.5): 1 +/- 1
bin 3 x in [ 0.5, 1.0): 0 +/- 0
bin 4 x in [ 1.0, 1.5): 0 +/- 0
bin 5 x in [ 1.5, 2.0): 0 +/- 0
bin 6 x in [ 2.0, inf): 2 +/- 1.41421
bin -1 x in [-inf, -1): 1 +/- 1
*/
*/
}

//]
66 changes: 33 additions & 33 deletions examples/getting_started_listing_02.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,42 @@ namespace br = boost::random;
namespace bh = boost::histogram;

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

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

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

//]
81 changes: 37 additions & 44 deletions examples/guide_access_bin_counts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,43 @@
namespace bh = boost::histogram;

int main() {
// make histogram with 2 x 2 = 4 bins (not counting under-/overflow bins)
auto h = bh::make_static_histogram(
bh::axis::regular<>(2, -1, 1),
bh::axis::regular<>(2, 2, 4)
);

h(bh::weight(1), -0.5, 2.5); // bin index 0, 0
h(bh::weight(2), -0.5, 3.5); // bin index 0, 1
h(bh::weight(3), 0.5, 2.5); // bin index 1, 0
h(bh::weight(4), 0.5, 3.5); // bin index 1, 1

// access count value, number of indices must match number of axes
std::cout << h.at(0, 0).value() << " "
<< h.at(0, 1).value() << " "
<< h.at(1, 0).value() << " "
<< h.at(1, 1).value()
<< std::endl;

// prints: 1 2 3 4

// access count variance, number of indices must match number of axes
std::cout << h.at(0, 0).variance() << " "
<< h.at(0, 1).variance() << " "
<< h.at(1, 0).variance() << " "
<< h.at(1, 1).variance()
<< std::endl;
// prints: 1 4 9 16

// you can also make a copy of the type that holds the bin count
auto c11 = h.at(1, 1);
std::cout << c11.value() << " " << c11.variance() << std::endl;
// prints: 4 16

// histogram also supports access via container; using a container of
// wrong size trips an assertion in debug mode
auto idx = {0, 1};
std::cout << h.at(idx).value() << std::endl;
// prints: 2

// histogram also provides extended iterators
auto sum = std::accumulate(h.begin(), h.end(),
typename decltype(h)::element_type(0));
std::cout << sum.value() << " " << sum.variance() << std::endl;
// prints: 10 30
// make histogram with 2 x 2 = 4 bins (not counting under-/overflow bins)
auto h = bh::make_static_histogram(bh::axis::regular<>(2, -1, 1),
bh::axis::regular<>(2, 2, 4));

h(bh::weight(1), -0.5, 2.5); // bin index 0, 0
h(bh::weight(2), -0.5, 3.5); // bin index 0, 1
h(bh::weight(3), 0.5, 2.5); // bin index 1, 0
h(bh::weight(4), 0.5, 3.5); // bin index 1, 1

// access count value, number of indices must match number of axes
std::cout << h.at(0, 0).value() << " " << h.at(0, 1).value() << " "
<< h.at(1, 0).value() << " " << h.at(1, 1).value() << std::endl;

// prints: 1 2 3 4

// access count variance, number of indices must match number of axes
std::cout << h.at(0, 0).variance() << " " << h.at(0, 1).variance() << " "
<< h.at(1, 0).variance() << " " << h.at(1, 1).variance()
<< std::endl;
// prints: 1 4 9 16

// you can also make a copy of the type that holds the bin count
auto c11 = h.at(1, 1);
std::cout << c11.value() << " " << c11.variance() << std::endl;
// prints: 4 16

// histogram also supports access via container; using a container of
// wrong size trips an assertion in debug mode
auto idx = {0, 1};
std::cout << h.at(idx).value() << std::endl;
// prints: 2

// histogram also provides extended iterators
auto sum = std::accumulate(h.begin(), h.end(),
typename decltype(h)::element_type(0));
std::cout << sum.value() << " " << sum.variance() << std::endl;
// prints: 10 30
}

//]
Loading

0 comments on commit bfc437b

Please sign in to comment.