Skip to content

Commit

Permalink
Enable pre-commit (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
HDembinski authored Sep 28, 2022
1 parent 10c19df commit 1c9077a
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 15 deletions.
39 changes: 39 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# To use:
#
# pre-commit run -a
#
# Or:
#
# pre-commit install # (runs every time you commit in git)
#
# To update this file:
#
# pre-commit autoupdate
#
# See https://github.com/pre-commit/pre-commit

repos:
# Standard hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
args: ["--allow-multiple-documents"]
- id: debug-statements
- id: mixed-line-ending
- id: sort-simple-yaml
- id: file-contents-sorter
- id: trailing-whitespace
exclude: .*.(xml?)|(svg?)

# C++ formatting
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v13.0.1
hooks:
- id: clang-format
types_or: [c++, c]
2 changes: 1 addition & 1 deletion benchmark/histogram_filling_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

print(timeit.timeit("np.histogram(x, bins=100, range=(0, 1))",
"from __main__ import x, np", number=nrepeat) / (nrepeat * len(x)) / 1e-9)

print(timeit.timeit("histogram1d(x, bins=100, range=(0, 1))",
"from __main__ import x, histogram1d", number=nrepeat) / (nrepeat * len(x)) / 1e-9)
2 changes: 1 addition & 1 deletion doc/getting_started.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ The library was designed to work well with the C++ standard library. Here is an

[section Making classes that hold histograms]

The histograms get their great flexibility and performance from being templated, but this can make the types a bit cumbersome to write. Often it is possible to use `auto` to let the compiler deduce the type, but when you want to store histograms in a class, you need to write the type explicitly. The next example shows how this works.
The histograms get their great flexibility and performance from being templated, but this can make the types a bit cumbersome to write. Often it is possible to use `auto` to let the compiler deduce the type, but when you want to store histograms in a class, you need to write the type explicitly. The next example shows how this works.

[import ../examples/getting_started_listing_05.cpp]
[getting_started_listing_05]
Expand Down
2 changes: 1 addition & 1 deletion doc/overview.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ This library provides a histogram for multi-dimensional data. In the multi-dimen

The term /histogram/ is usually strictly used for something with cells over discrete or continuous data. This histogram class can also process categorical variables and it even allows for non-consecutive cells if that is desired. There is no restriction to numbers as input either. Any C++ type can be fed into the histogram, if the user provides a specialized axis class that maps values of this type to a cell index. The only remaining restriction is that cells are non-overlapping, since there must be a unique mapping from input value to cell. The library is not able to automatically ensure this for user-provided axis classes, so the responsibly is on the user.

Furthermore, the histogram can handle weighted input. Normally, the cell counter which is connected to an input tuple is incremented by one, but sometimes it is useful to increment by a weight, an integral or floating point number. Finally, the histogram can be configured to store any kind of accumulator in each cell. Arbitrary samples can be passed to this accumulator, which may compute the mean or other interesting quantities from the samples that are sorted into the cell. When the accumulator computes a mean, the result is called a /profile/. The feature set is informed by popular libraries for scientific computing, notably [@https://root.cern.ch CERN's ROOT framework] and the [@https://www.gnu.org/software/gsl GNU Scientific Library].
Furthermore, the histogram can handle weighted input. Normally, the cell counter which is connected to an input tuple is incremented by one, but sometimes it is useful to increment by a weight, an integral or floating point number. Finally, the histogram can be configured to store any kind of accumulator in each cell. Arbitrary samples can be passed to this accumulator, which may compute the mean or other interesting quantities from the samples that are sorted into the cell. When the accumulator computes a mean, the result is called a /profile/. The feature set is informed by popular libraries for scientific computing, notably [@https://root.cern.ch CERN's ROOT framework] and the [@https://www.gnu.org/software/gsl GNU Scientific Library].

[endsect]

Expand Down
2 changes: 1 addition & 1 deletion examples/getting_started_listing_01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ int main() {

std::ostringstream os;
for (auto&& x : indexed(h, coverage::all)) {
os << boost::format("bin %2i [%4.1f, %4.1f): %i\n")
os << boost::format("bin %2i [%4.1f, %4.1f): %i\n")
% x.index() % x.bin().lower() % x.bin().upper() % *x;
}

Expand Down
4 changes: 2 additions & 2 deletions examples/getting_started_listing_03.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ int main() {
*/
std::ostringstream os;
for (auto&& x : indexed(p)) {
os << boost::format("bin %i [%3.1f, %3.1f) count %i mean %g\n")
% x.index() % x.bin().lower() % x.bin().upper()
os << boost::format("bin %i [%3.1f, %3.1f) count %i mean %g\n")
% x.index() % x.bin().lower() % x.bin().upper()
% x->count() % x->value();
}

Expand Down
6 changes: 3 additions & 3 deletions examples/getting_started_listing_05.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct HolderOfStaticHistogram {
// put axis types here
using axes_t = std::tuple<
boost::histogram::axis::regular<>,
boost::histogram::axis::integer<>
boost::histogram::axis::integer<>
>;
using hist_t = boost::histogram::histogram<axes_t>;
hist_t hist_;
Expand All @@ -34,8 +34,8 @@ struct HolderOfDynamicHistogram {
// put all axis types here that you are going to use
using axis_t = boost::histogram::axis::variant<
boost::histogram::axis::regular<>,
boost::histogram::axis::variable<>,
boost::histogram::axis::integer<>
boost::histogram::axis::variable<>,
boost::histogram::axis::integer<>
>;
using axes_t = std::vector<axis_t>;
using hist_t = boost::histogram::histogram<axes_t>;
Expand Down
5 changes: 3 additions & 2 deletions include/boost/histogram/axis/variant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ class variant : public iterator_mixin<variant<Ts...>> {
template <class T>
using requires_bounded_type = std::enable_if_t<is_bounded_type<T>::value>;

using metadata_type = std::remove_const_t<std::remove_reference_t<decltype(
traits::metadata(std::declval<std::remove_pointer_t<mp11::mp_first<variant>>>()))>>;
using metadata_type =
std::remove_const_t<std::remove_reference_t<decltype(traits::metadata(
std::declval<std::remove_pointer_t<mp11::mp_first<variant>>>()))>>;

public:
// cannot import ctors with using directive, it breaks gcc and msvc
Expand Down
5 changes: 3 additions & 2 deletions include/boost/histogram/detail/axes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,9 @@ using has_non_inclusive_axis = mp11::mp_any_of<axis_types<Axes>, is_not_inclusiv

template <class T>
constexpr std::size_t type_score() {
return sizeof(T) *
(std::is_integral<T>::value ? 1 : std::is_floating_point<T>::value ? 10 : 100);
return sizeof(T) * (std::is_integral<T>::value ? 1
: std::is_floating_point<T>::value ? 10
: 100);
}

// arbitrary ordering of types
Expand Down
2 changes: 1 addition & 1 deletion test/boost_range_support_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

#include <boost/core/lightweight_test.hpp>
#include <boost/histogram/axis/integer.hpp>
#include "throw_exception.hpp"
#include <boost/histogram/histogram.hpp>
#include <boost/histogram/make_histogram.hpp>
#include <boost/range/adaptor/filtered.hpp>
#include <boost/range/numeric.hpp>
#include "throw_exception.hpp"

using namespace boost::histogram;
using namespace boost::adaptors;
Expand Down
2 changes: 1 addition & 1 deletion test/boost_units_support_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <boost/core/lightweight_test.hpp>
#include <boost/histogram/axis/ostream.hpp>
#include <boost/histogram/axis/regular.hpp>
#include "throw_exception.hpp"
#include <boost/histogram/histogram.hpp>
#include <boost/histogram/indexed.hpp>
#include <boost/histogram/literals.hpp>
Expand All @@ -17,6 +16,7 @@
#include <boost/units/systems/si/length.hpp>
#include <limits>
#include "is_close.hpp"
#include "throw_exception.hpp"

using namespace boost::histogram;
using namespace boost::histogram::literals;
Expand Down

0 comments on commit 1c9077a

Please sign in to comment.