Enable pre-commit (#366)

This commit is contained in:
Hans Dembinski 2022-09-28 12:11:50 +02:00 committed by GitHub
parent 10c19df918
commit 1c9077a6e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 56 additions and 15 deletions

39
.pre-commit-config.yaml Normal file
View File

@ -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]

View File

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

View File

@ -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] [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] [import ../examples/getting_started_listing_05.cpp]
[getting_started_listing_05] [getting_started_listing_05]

View File

@ -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. 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] [endsect]

View File

@ -74,7 +74,7 @@ int main() {
std::ostringstream os; std::ostringstream os;
for (auto&& x : indexed(h, coverage::all)) { 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; % x.index() % x.bin().lower() % x.bin().upper() % *x;
} }

View File

@ -38,8 +38,8 @@ int main() {
*/ */
std::ostringstream os; std::ostringstream os;
for (auto&& x : indexed(p)) { for (auto&& x : indexed(p)) {
os << boost::format("bin %i [%3.1f, %3.1f) count %i mean %g\n") os << boost::format("bin %i [%3.1f, %3.1f) count %i mean %g\n")
% x.index() % x.bin().lower() % x.bin().upper() % x.index() % x.bin().lower() % x.bin().upper()
% x->count() % x->value(); % x->count() % x->value();
} }

View File

@ -23,7 +23,7 @@ struct HolderOfStaticHistogram {
// put axis types here // put axis types here
using axes_t = std::tuple< using axes_t = std::tuple<
boost::histogram::axis::regular<>, boost::histogram::axis::regular<>,
boost::histogram::axis::integer<> boost::histogram::axis::integer<>
>; >;
using hist_t = boost::histogram::histogram<axes_t>; using hist_t = boost::histogram::histogram<axes_t>;
hist_t hist_; hist_t hist_;
@ -34,8 +34,8 @@ struct HolderOfDynamicHistogram {
// put all axis types here that you are going to use // put all axis types here that you are going to use
using axis_t = boost::histogram::axis::variant< using axis_t = boost::histogram::axis::variant<
boost::histogram::axis::regular<>, boost::histogram::axis::regular<>,
boost::histogram::axis::variable<>, boost::histogram::axis::variable<>,
boost::histogram::axis::integer<> boost::histogram::axis::integer<>
>; >;
using axes_t = std::vector<axis_t>; using axes_t = std::vector<axis_t>;
using hist_t = boost::histogram::histogram<axes_t>; using hist_t = boost::histogram::histogram<axes_t>;

View File

@ -38,8 +38,9 @@ class variant : public iterator_mixin<variant<Ts...>> {
template <class T> template <class T>
using requires_bounded_type = std::enable_if_t<is_bounded_type<T>::value>; 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( using metadata_type =
traits::metadata(std::declval<std::remove_pointer_t<mp11::mp_first<variant>>>()))>>; std::remove_const_t<std::remove_reference_t<decltype(traits::metadata(
std::declval<std::remove_pointer_t<mp11::mp_first<variant>>>()))>>;
public: public:
// cannot import ctors with using directive, it breaks gcc and msvc // cannot import ctors with using directive, it breaks gcc and msvc

View File

@ -433,8 +433,9 @@ using has_non_inclusive_axis = mp11::mp_any_of<axis_types<Axes>, is_not_inclusiv
template <class T> template <class T>
constexpr std::size_t type_score() { constexpr std::size_t type_score() {
return sizeof(T) * return sizeof(T) * (std::is_integral<T>::value ? 1
(std::is_integral<T>::value ? 1 : std::is_floating_point<T>::value ? 10 : 100); : std::is_floating_point<T>::value ? 10
: 100);
} }
// arbitrary ordering of types // arbitrary ordering of types

View File

@ -6,11 +6,11 @@
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>
#include <boost/histogram/axis/integer.hpp> #include <boost/histogram/axis/integer.hpp>
#include "throw_exception.hpp"
#include <boost/histogram/histogram.hpp> #include <boost/histogram/histogram.hpp>
#include <boost/histogram/make_histogram.hpp> #include <boost/histogram/make_histogram.hpp>
#include <boost/range/adaptor/filtered.hpp> #include <boost/range/adaptor/filtered.hpp>
#include <boost/range/numeric.hpp> #include <boost/range/numeric.hpp>
#include "throw_exception.hpp"
using namespace boost::histogram; using namespace boost::histogram;
using namespace boost::adaptors; using namespace boost::adaptors;

View File

@ -7,7 +7,6 @@
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>
#include <boost/histogram/axis/ostream.hpp> #include <boost/histogram/axis/ostream.hpp>
#include <boost/histogram/axis/regular.hpp> #include <boost/histogram/axis/regular.hpp>
#include "throw_exception.hpp"
#include <boost/histogram/histogram.hpp> #include <boost/histogram/histogram.hpp>
#include <boost/histogram/indexed.hpp> #include <boost/histogram/indexed.hpp>
#include <boost/histogram/literals.hpp> #include <boost/histogram/literals.hpp>
@ -17,6 +16,7 @@
#include <boost/units/systems/si/length.hpp> #include <boost/units/systems/si/length.hpp>
#include <limits> #include <limits>
#include "is_close.hpp" #include "is_close.hpp"
#include "throw_exception.hpp"
using namespace boost::histogram; using namespace boost::histogram;
using namespace boost::histogram::literals; using namespace boost::histogram::literals;