From 1c9077a6e1452a82f8c3f476a206321adcd3757e Mon Sep 17 00:00:00 2001 From: Hans Dembinski Date: Wed, 28 Sep 2022 12:11:50 +0200 Subject: [PATCH] Enable pre-commit (#366) --- .pre-commit-config.yaml | 39 ++++++++++++++++++++++++ benchmark/histogram_filling_numpy.py | 2 +- doc/getting_started.qbk | 2 +- doc/overview.qbk | 2 +- examples/getting_started_listing_01.cpp | 2 +- examples/getting_started_listing_03.cpp | 4 +-- examples/getting_started_listing_05.cpp | 6 ++-- include/boost/histogram/axis/variant.hpp | 5 +-- include/boost/histogram/detail/axes.hpp | 5 +-- test/boost_range_support_test.cpp | 2 +- test/boost_units_support_test.cpp | 2 +- 11 files changed, 56 insertions(+), 15 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..123db6e0 --- /dev/null +++ b/.pre-commit-config.yaml @@ -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] diff --git a/benchmark/histogram_filling_numpy.py b/benchmark/histogram_filling_numpy.py index ce0fa2b7..11d574e8 100644 --- a/benchmark/histogram_filling_numpy.py +++ b/benchmark/histogram_filling_numpy.py @@ -9,6 +9,6 @@ nrepeat = 10 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) \ No newline at end of file diff --git a/doc/getting_started.qbk b/doc/getting_started.qbk index 53925346..54227865 100644 --- a/doc/getting_started.qbk +++ b/doc/getting_started.qbk @@ -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] diff --git a/doc/overview.qbk b/doc/overview.qbk index c9134464..90d54616 100644 --- a/doc/overview.qbk +++ b/doc/overview.qbk @@ -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] diff --git a/examples/getting_started_listing_01.cpp b/examples/getting_started_listing_01.cpp index a83df68d..7d74f380 100644 --- a/examples/getting_started_listing_01.cpp +++ b/examples/getting_started_listing_01.cpp @@ -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; } diff --git a/examples/getting_started_listing_03.cpp b/examples/getting_started_listing_03.cpp index f3ebfcd8..82bbb36b 100644 --- a/examples/getting_started_listing_03.cpp +++ b/examples/getting_started_listing_03.cpp @@ -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(); } diff --git a/examples/getting_started_listing_05.cpp b/examples/getting_started_listing_05.cpp index 52706284..e7769dc3 100644 --- a/examples/getting_started_listing_05.cpp +++ b/examples/getting_started_listing_05.cpp @@ -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; hist_t hist_; @@ -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; using hist_t = boost::histogram::histogram; diff --git a/include/boost/histogram/axis/variant.hpp b/include/boost/histogram/axis/variant.hpp index d687cd96..95cf71b6 100644 --- a/include/boost/histogram/axis/variant.hpp +++ b/include/boost/histogram/axis/variant.hpp @@ -38,8 +38,9 @@ class variant : public iterator_mixin> { template using requires_bounded_type = std::enable_if_t::value>; - using metadata_type = std::remove_const_t>>()))>>; + using metadata_type = + std::remove_const_t>>()))>>; public: // cannot import ctors with using directive, it breaks gcc and msvc diff --git a/include/boost/histogram/detail/axes.hpp b/include/boost/histogram/detail/axes.hpp index 5e4ee5e1..1aee9c6a 100644 --- a/include/boost/histogram/detail/axes.hpp +++ b/include/boost/histogram/detail/axes.hpp @@ -433,8 +433,9 @@ using has_non_inclusive_axis = mp11::mp_any_of, is_not_inclusiv template constexpr std::size_t type_score() { - return sizeof(T) * - (std::is_integral::value ? 1 : std::is_floating_point::value ? 10 : 100); + return sizeof(T) * (std::is_integral::value ? 1 + : std::is_floating_point::value ? 10 + : 100); } // arbitrary ordering of types diff --git a/test/boost_range_support_test.cpp b/test/boost_range_support_test.cpp index cf1bedc3..986facf3 100644 --- a/test/boost_range_support_test.cpp +++ b/test/boost_range_support_test.cpp @@ -6,11 +6,11 @@ #include #include -#include "throw_exception.hpp" #include #include #include #include +#include "throw_exception.hpp" using namespace boost::histogram; using namespace boost::adaptors; diff --git a/test/boost_units_support_test.cpp b/test/boost_units_support_test.cpp index 1a3df653..0fe6da6e 100644 --- a/test/boost_units_support_test.cpp +++ b/test/boost_units_support_test.cpp @@ -7,7 +7,6 @@ #include #include #include -#include "throw_exception.hpp" #include #include #include @@ -17,6 +16,7 @@ #include #include #include "is_close.hpp" +#include "throw_exception.hpp" using namespace boost::histogram; using namespace boost::histogram::literals;