diff --git a/include/boost/histogram/axis.hpp b/include/boost/histogram/axis.hpp index 2aabeff5..2653e7e9 100644 --- a/include/boost/histogram/axis.hpp +++ b/include/boost/histogram/axis.hpp @@ -214,7 +214,9 @@ struct pow { return std::pow(v, 1.0 / value); } double value = 1.0; - bool operator==(const pow &other) const noexcept { return value == other.value; } + bool operator==(const pow &other) const noexcept { + return value == other.value; + } template void serialize(Archive &, unsigned); }; } // namespace transform @@ -240,8 +242,7 @@ public: * \param uoflow whether to add under-/overflow bins. * \param trans arguments passed to the transform. */ - regular(unsigned n, value_type min, value_type max, - string_view label = {}, + regular(unsigned n, value_type min, value_type max, string_view label = {}, enum uoflow uo = ::boost::histogram::axis::uoflow::on, Transform trans = Transform()) : axis_base_uoflow(n, label, uo), Transform(trans), @@ -282,8 +283,7 @@ public: } bool operator==(const regular &o) const noexcept { - return axis_base_uoflow::operator==(o) && - Transform::operator==(o) && + return axis_base_uoflow::operator==(o) && Transform::operator==(o) && min_ == o.min_ && delta_ == o.delta_; } @@ -296,7 +296,7 @@ public: } const Transform &transform() const noexcept { - return static_cast(*this); + return static_cast(*this); } private: @@ -312,8 +312,7 @@ private: * perimeter value. Therefore, there are no overflow/underflow * bins for this axis. Binning is a O(1) operation. */ -template -class circular : public axis_base { +template class circular : public axis_base { public: using value_type = RealType; using bin_type = interval; @@ -377,8 +376,7 @@ private: * Binning is a O(log(N)) operation. If speed matters * and the problem domain allows it, prefer a regular. */ -template -class variable : public axis_base_uoflow { +template class variable : public axis_base_uoflow { public: using value_type = RealType; using bin_type = interval; @@ -390,8 +388,7 @@ public: * \param label description of the axis. * \param uoflow whether to add under-/overflow bins. */ - variable(std::initializer_list x, - string_view label = {}, + variable(std::initializer_list x, string_view label = {}, enum uoflow uo = ::boost::histogram::axis::uoflow::on) : axis_base_uoflow(x.size() - 1, label, uo), x_(new value_type[x.size()]) { @@ -473,8 +470,7 @@ private: * Binning is a O(1) operation. This axis operates * faster than a regular. */ -template -class integer : public axis_base_uoflow { +template class integer : public axis_base_uoflow { public: using value_type = IntType; using bin_type = interval; @@ -534,8 +530,7 @@ private: * for this axis, which counts values that are not part of the set. * Binning is a O(1) operation. The value type must be hashable. */ -template -class category : public axis_base { +template class category : public axis_base { using map_type = bimap; public: diff --git a/include/boost/histogram/detail/weight.hpp b/include/boost/histogram/detail/weight.hpp index 10d1bed8..b9cf6e78 100644 --- a/include/boost/histogram/detail/weight.hpp +++ b/include/boost/histogram/detail/weight.hpp @@ -57,7 +57,8 @@ struct weight { } template - explicit weight(const T &t) : w(static_cast(t)), w2(static_cast(t)) {} + explicit weight(const T &t) + : w(static_cast(t)), w2(static_cast(t)) {} template weight &operator=(const T &t) { w = static_cast(t); diff --git a/include/boost/histogram/histogram_fwd.hpp b/include/boost/histogram/histogram_fwd.hpp index f69127a0..a6a6d70f 100644 --- a/include/boost/histogram/histogram_fwd.hpp +++ b/include/boost/histogram/histogram_fwd.hpp @@ -67,44 +67,67 @@ inline detail::keep_dynamic keep(unsigned i, Rest... rest) { // fast operators (boost::operators does not use rvalue references yet) template -histogram && operator+(histogram &&a, - const histogram &b) -{ a+=b; return std::move(a); } +histogram && +operator+(histogram &&a, + const histogram &b) { + a += b; + return std::move(a); +} template -histogram&& operator+(histogram &&a, - histogram &&b) -{ a+=b; return std::move(a); } +histogram && +operator+(histogram &&a, + histogram &&b) { + a += b; + return std::move(a); +} template -histogram&& operator+(const histogram &a, - histogram &&b) -{ b+=a; return std::move(b); } +histogram && +operator+(const histogram &a, + histogram &&b) { + b += a; + return std::move(b); +} template -histogram operator+(const histogram &a, - const histogram &b) -{ histogram r(a); r+=b; return r; } +histogram +operator+(const histogram &a, + const histogram &b) { + histogram r(a); + r += b; + return r; +} template -histogram&& operator*(histogram &&a, - const double x) -{ a*=x; return std::move(a); } +histogram && +operator*(histogram &&a, const double x) { + a *= x; + return std::move(a); +} template -histogram&& operator*(const double x, - histogram &&b) -{ b*=x; return std::move(b); } +histogram && +operator*(const double x, histogram &&b) { + b *= x; + return std::move(b); +} template -histogram operator*(const histogram &a, - const double x) -{ histogram r(a); r*=x; return r; } +histogram +operator*(const histogram &a, const double x) { + histogram r(a); + r *= x; + return r; +} template -histogram operator*(const double x, - const histogram &b) -{ histogram r(b); r*=x; return r; } +histogram +operator*(const double x, const histogram &b) { + histogram r(b); + r *= x; + return r; +} } // namespace histogram } // namespace boost diff --git a/include/boost/histogram/histogram_impl_dynamic.hpp b/include/boost/histogram/histogram_impl_dynamic.hpp index 099328e8..1ed7e89a 100644 --- a/include/boost/histogram/histogram_impl_dynamic.hpp +++ b/include/boost/histogram/histogram_impl_dynamic.hpp @@ -430,24 +430,20 @@ private: }; template -inline histogram< - Dynamic, detail::combine>> +inline histogram>> make_dynamic_histogram(Axes &&... axes) { - return histogram>>( + return histogram>>( std::forward(axes)...); } template -inline histogram< - Dynamic, detail::combine>, - Storage> +inline histogram>, + Storage> make_dynamic_histogram_with(Axes &&... axes) { - return histogram< - Dynamic, - detail::combine>, - Storage>(std::forward(axes)...); + return histogram>, + Storage>(std::forward(axes)...); } } // namespace histogram diff --git a/include/boost/histogram/serialization.hpp b/include/boost/histogram/serialization.hpp index c867579c..8231dc0a 100644 --- a/include/boost/histogram/serialization.hpp +++ b/include/boost/histogram/serialization.hpp @@ -50,8 +50,7 @@ void serialize(Archive &ar, array_storage &store, } template -void adaptive_storage::serialize(Archive &ar, - unsigned /* version */) { +void adaptive_storage::serialize(Archive &ar, unsigned /* version */) { using detail::array; std::size_t size = this->size(); ar &size; @@ -106,11 +105,13 @@ void adaptive_storage::serialize(Archive &ar, tid = 4; ar &tid; ar &serialization::make_array(a->begin(), size); - } else if (array *a = get>(&buffer_)) { + } else if (array *a = + get>(&buffer_)) { tid = 5; ar &tid; ar &serialization::make_array(a->begin(), size); - } else if (array *a = get>(&buffer_)) { + } else if (array *a = + get>(&buffer_)) { tid = 6; ar &tid; ar &serialization::make_array(a->begin(), size); diff --git a/include/boost/histogram/storage/adaptive_storage.hpp b/include/boost/histogram/storage/adaptive_storage.hpp index 4f78ae1c..946b31f7 100644 --- a/include/boost/histogram/storage/adaptive_storage.hpp +++ b/include/boost/histogram/storage/adaptive_storage.hpp @@ -56,8 +56,7 @@ public: std::size_t size = 0; }; -template -class array : public array_base { +template class array : public array_base { public: explicit array(const std::size_t s) : array_base(s), ptr(new T[s]) { std::fill(begin(), end(), T(0)); @@ -76,8 +75,7 @@ public: } return *this; } - array(array &&rhs) - : array_base(std::move(rhs)), ptr(std::move(rhs.ptr)) { + array(array &&rhs) : array_base(std::move(rhs)), ptr(std::move(rhs.ptr)) { rhs.size = 0; } array &operator=(array &&rhs) { @@ -109,20 +107,14 @@ private: std::unique_ptr ptr; }; -template <> -class array : public array_base { +template <> class array : public array_base { public: using array_base::array_base; }; using any_array = - variant, - array, - array, - array, - array, - array, - array>; + variant, array, array, array, + array, array, array>; template struct next_type; template <> struct next_type { using type = uint16_t; }; @@ -131,16 +123,14 @@ template <> struct next_type { using type = uint64_t; }; template <> struct next_type { using type = mp_int; }; template using next = typename next_type::type; -template -inline bool safe_increase(T& t) { +template inline bool safe_increase(T &t) { if (t == std::numeric_limits::max()) return false; ++t; return true; } -template -inline bool safe_assign(T& t, const U& u) { +template inline bool safe_assign(T &t, const U &u) { if (std::numeric_limits::max() < std::numeric_limits::max() && std::numeric_limits::max() < u) return false; @@ -148,8 +138,7 @@ inline bool safe_assign(T& t, const U& u) { return true; } -template -inline bool safe_radd(T& t, const U& u) { +template inline bool safe_radd(T &t, const U &u) { if ((std::numeric_limits::max() - t) < u) return false; t += static_cast(u); @@ -157,8 +146,7 @@ inline bool safe_radd(T& t, const U& u) { } // float rounding is a mess, the equal sign is necessary here -template -inline bool safe_radd(T& t, const double u) { +template inline bool safe_radd(T &t, const double u) { if ((std::numeric_limits::max() - t) <= u) return false; t += u; @@ -171,8 +159,7 @@ struct size_visitor : public static_visitor { } }; -template -struct assign_visitor : public static_visitor { +template struct assign_visitor : public static_visitor { any_array &lhs_any; const std::size_t idx; const RHS &rhs; @@ -191,9 +178,7 @@ struct assign_visitor : public static_visitor { operator()(get>(lhs_any)); } - void operator()(array &lhs) const { - lhs[idx].assign(rhs); - } + void operator()(array &lhs) const { lhs[idx].assign(rhs); } void operator()(array &lhs) const { lhs[idx] = rhs; } }; @@ -201,8 +186,7 @@ struct assign_visitor : public static_visitor { struct increase_visitor : public static_visitor { any_array &lhs_any; const std::size_t idx; - increase_visitor(any_array& a, const std::size_t i) - : lhs_any(a), idx(i) {} + increase_visitor(any_array &a, const std::size_t i) : lhs_any(a), idx(i) {} template void operator()(array &lhs) const { if (!safe_increase(lhs[idx])) { @@ -253,13 +237,9 @@ struct value_visitor : public static_visitor { return static_cast(b[idx]); } - double operator()(const array & /*b*/) const { - return 0; - } + double operator()(const array & /*b*/) const { return 0; } - double operator()(const array &b) const { - return b[idx].w; - } + double operator()(const array &b) const { return b[idx].w; } }; struct variance_visitor : public static_visitor { @@ -270,13 +250,9 @@ struct variance_visitor : public static_visitor { return static_cast(b[idx]); } - double operator()(const array & /*b*/) const { - return 0; - } + double operator()(const array & /*b*/) const { return 0; } - double operator()(const array &b) const { - return b[idx].w2; - } + double operator()(const array &b) const { return b[idx].w2; } }; template struct radd_visitor : public static_visitor { @@ -307,7 +283,6 @@ template struct radd_visitor : public static_visitor { void operator()(array &lhs) const { lhs[idx] += rhs; } }; - template <> struct radd_visitor : public static_visitor { any_array &lhs_any; const std::size_t idx; @@ -325,15 +300,13 @@ template <> struct radd_visitor : public static_visitor { operator()(get>(lhs_any)); } - void operator()(array &lhs) const { - lhs[idx] += rhs; - } + void operator()(array &lhs) const { lhs[idx] += rhs; } }; // precondition: both arrays must have same size and may not be identical struct radd_array_visitor : public static_visitor { - any_array& lhs_any; - radd_array_visitor(any_array& l) : lhs_any(l) {} + any_array &lhs_any; + radd_array_visitor(any_array &l) : lhs_any(l) {} template void operator()(const array &rhs) const { for (auto i = 0ul; i < rhs.size; ++i) apply_visitor(radd_visitor(lhs_any, i, rhs[i]), lhs_any); @@ -342,15 +315,15 @@ struct radd_array_visitor : public static_visitor { }; struct rmul_visitor : public static_visitor { - any_array& lhs_any; + any_array &lhs_any; const double x; - rmul_visitor(any_array& l, const double v) : lhs_any(l), x(v) {} - template void operator()(array& lhs) const { + rmul_visitor(any_array &l, const double v) : lhs_any(l), x(v) {} + template void operator()(array &lhs) const { lhs_any = array(lhs); operator()(get>(lhs_any)); } - void operator()(array&) const {} - void operator()(array& lhs) const { + void operator()(array &) const {} + void operator()(array &lhs) const { for (auto i = 0ul; i != lhs.size; ++i) lhs[i] *= x; } @@ -368,7 +341,7 @@ struct bicmp_visitor : public static_visitor { bool operator()(const array &b1, const array &b2) const { if (b1.size != b2.size) return false; - return std::all_of(b1.begin(), b1.end(), [](const T& t) { return t == 0; }); + return std::all_of(b1.begin(), b1.end(), [](const T &t) { return t == 0; }); } template @@ -385,6 +358,7 @@ struct bicmp_visitor : public static_visitor { class adaptive_storage { using buffer_type = detail::any_array; + public: using value_type = double; @@ -397,12 +371,12 @@ public: adaptive_storage &operator=(adaptive_storage &&) = default; template > - explicit adaptive_storage(const RHS &rhs) : buffer_(detail::array(rhs.size())) { + explicit adaptive_storage(const RHS &rhs) + : buffer_(detail::array(rhs.size())) { using T = typename RHS::value_type; for (auto i = 0ul, n = rhs.size(); i < n; ++i) { - apply_visitor( - detail::assign_visitor(buffer_, i, rhs.value(i)), - buffer_); + apply_visitor(detail::assign_visitor(buffer_, i, rhs.value(i)), + buffer_); } } @@ -414,15 +388,16 @@ public: buffer_ = detail::array(n); } for (auto i = 0ul; i < n; ++i) { - apply_visitor( - detail::assign_visitor(buffer_, i, rhs.value(i)), - buffer_); + apply_visitor(detail::assign_visitor(buffer_, i, rhs.value(i)), + buffer_); } } return *this; } - std::size_t size() const { return apply_visitor(detail::size_visitor(), buffer_); } + std::size_t size() const { + return apply_visitor(detail::size_visitor(), buffer_); + } void increase(std::size_t i) { apply_visitor(detail::increase_visitor(buffer_, i), buffer_); @@ -433,11 +408,13 @@ public: } template - void add(std::size_t i, const T& value, const T& variance) { + void add(std::size_t i, const T &value, const T &variance) { if (value == variance) { apply_visitor(detail::radd_visitor(buffer_, i, value), buffer_); } else { - apply_visitor(detail::radd_visitor(buffer_, i, detail::weight(value, variance)), buffer_); + apply_visitor(detail::radd_visitor( + buffer_, i, detail::weight(value, variance)), + buffer_); } } @@ -458,12 +435,11 @@ public: } // precondition: storages have same size - adaptive_storage& operator+=(const adaptive_storage& rhs) { + adaptive_storage &operator+=(const adaptive_storage &rhs) { if (this == &rhs) { for (auto i = 0ul, n = size(); i < n; ++i) add(i, rhs.value(i), rhs.variance(i)); // this is losing precision - } - else { + } else { apply_visitor(detail::radd_array_visitor(buffer_), rhs.buffer_); } return *this; @@ -471,13 +447,15 @@ public: // precondition: storages have same size template > - adaptive_storage& operator+=(const RHS& rhs) { + adaptive_storage &operator+=(const RHS &rhs) { for (auto i = 0ul, n = size(); i < n; ++i) - apply_visitor(detail::radd_visitor(buffer_, i, rhs.value(i)), buffer_); + apply_visitor(detail::radd_visitor( + buffer_, i, rhs.value(i)), + buffer_); return *this; } - adaptive_storage& operator*=(const value_type x) { + adaptive_storage &operator*=(const value_type x) { apply_visitor(detail::rmul_visitor(buffer_, x), buffer_); return *this; } diff --git a/include/boost/histogram/storage/array_storage.hpp b/include/boost/histogram/storage/array_storage.hpp index 6d9abdef..eeae5881 100644 --- a/include/boost/histogram/storage/array_storage.hpp +++ b/include/boost/histogram/storage/array_storage.hpp @@ -9,9 +9,9 @@ #include #include -#include #include #include +#include // forward declaration for serialization namespace boost { @@ -74,10 +74,9 @@ public: std::size_t size() const noexcept { return size_; } void increase(std::size_t i) noexcept { ++array_[i]; } - void add(std::size_t i, const value_type& n) noexcept { - array_[i] += n; - } - void add(std::size_t i, const value_type& n, const value_type& /* variance */) noexcept { + void add(std::size_t i, const value_type &n) noexcept { array_[i] += n; } + void add(std::size_t i, const value_type &n, + const value_type & /* variance */) noexcept { array_[i] += n; } @@ -85,13 +84,13 @@ public: value_type variance(std::size_t i) const noexcept { return array_[i]; } template - array_storage& operator+=(const array_storage& rhs) noexcept { + array_storage &operator+=(const array_storage &rhs) noexcept { for (auto i = 0ul; i < size_; ++i) array_[i] += rhs.array_[i]; return *this; } - array_storage& operator*=(const value_type x) noexcept { + array_storage &operator*=(const value_type x) noexcept { for (auto i = 0ul; i < size_; ++i) array_[i] *= x; return *this; diff --git a/test/histogram_test.cpp b/test/histogram_test.cpp index 9cd74537..b860fae1 100644 --- a/test/histogram_test.cpp +++ b/test/histogram_test.cpp @@ -76,8 +76,8 @@ template void run_tests() { // init_2 { - auto h = make_histogram( - Type(), axis::regular<>{3, -1, 1}, axis::integer<>{-1, 2}); + auto h = make_histogram(Type(), axis::regular<>{3, -1, 1}, + axis::integer<>{-1, 2}); BOOST_TEST_EQ(h.dim(), 2); BOOST_TEST_EQ(h.size(), 25); BOOST_TEST_EQ(shape(h.axis(0_c)), 5); @@ -89,9 +89,9 @@ template void run_tests() { // init_3 { - auto h = make_histogram( - Type(), axis::regular<>{3, -1, 1}, axis::integer<>{-1, 2}, - axis::circular<>{3}); + auto h = make_histogram(Type(), axis::regular<>{3, -1, 1}, + axis::integer<>{-1, 2}, + axis::circular<>{3}); BOOST_TEST_EQ(h.dim(), 3); BOOST_TEST_EQ(h.size(), 75); auto h2 = make_histogram>( @@ -132,7 +132,7 @@ template void run_tests() { // copy_ctor { auto h = make_histogram(Type(), axis::integer<>{0, 2}, - axis::integer<>{0, 3}); + axis::integer<>{0, 3}); h.fill(0, 0); auto h2 = decltype(h)(h); BOOST_TEST(h2 == h); @@ -144,7 +144,7 @@ template void run_tests() { // copy_assign { auto h = make_histogram(Type(), axis::integer<>(0, 1), - axis::integer<>(0, 2)); + axis::integer<>(0, 2)); h.fill(0, 0); auto h2 = decltype(h)(); BOOST_TEST(h != h2); @@ -162,7 +162,7 @@ template void run_tests() { // move { auto h = make_histogram(Type(), axis::integer<>(0, 1), - axis::integer<>(0, 2)); + axis::integer<>(0, 2)); h.fill(0, 0); const auto href = h; decltype(h) h2(std::move(h)); @@ -182,8 +182,7 @@ template void run_tests() { // utility { - auto a = - make_histogram(Type(), axis::regular<>(1, 1, 2)); + auto a = make_histogram(Type(), axis::regular<>(1, 1, 2)); BOOST_TEST_EQ(size(a.axis()), 1); BOOST_TEST_EQ(shape(a.axis()), 3); BOOST_TEST_EQ(index(a.axis(), 1.0), 0); @@ -202,7 +201,7 @@ template void run_tests() { { auto a = make_histogram(Type(), axis::integer<>(0, 2)); auto b = make_histogram(Type(), axis::integer<>(0, 2), - axis::integer<>(0, 3)); + axis::integer<>(0, 3)); BOOST_TEST(a != b); BOOST_TEST(b != a); auto c = make_histogram(Type(), axis::integer<>(0, 2)); @@ -210,8 +209,7 @@ template void run_tests() { BOOST_TEST(c != b); BOOST_TEST(a == c); BOOST_TEST(c == a); - auto d = - make_histogram(Type(), axis::regular<>(2, 0, 1)); + auto d = make_histogram(Type(), axis::regular<>(2, 0, 1)); BOOST_TEST(c != d); BOOST_TEST(d != c); c.fill(0); @@ -417,8 +415,8 @@ template void run_tests() { // d3w { auto h = make_histogram(Type(), axis::integer<>(0, 3), - axis::integer<>(0, 4), - axis::integer<>(0, 5)); + axis::integer<>(0, 4), + axis::integer<>(0, 5)); for (auto i = 0; i < size(h.axis(0_c)); ++i) { for (auto j = 0; j < size(h.axis(1_c)); ++j) { for (auto k = 0; k < size(h.axis(2_c)); ++k) { @@ -613,7 +611,7 @@ template void run_tests() { // reduce { auto h1 = make_histogram(Type(), axis::integer<>(0, 2), - axis::integer<>(0, 3)); + axis::integer<>(0, 3)); h1.fill(0, 0); h1.fill(0, 1); h1.fill(1, 0); @@ -638,8 +636,8 @@ template void run_tests() { BOOST_TEST(axis_equal(Type(), h1_1.axis(), h1.axis(1_c))); auto h2 = make_histogram(Type(), axis::integer<>(0, 2), - axis::integer<>(0, 3), - axis::integer<>(0, 4)); + axis::integer<>(0, 3), + axis::integer<>(0, 4)); h2.fill(0, 0, 0); h2.fill(0, 1, 0); h2.fill(0, 1, 1); @@ -704,22 +702,22 @@ template void run_mixed_tests() { // compare { auto a = make_histogram(T1{}, axis::regular<>{3, 0, 3}, - axis::integer<>(0, 2)); + axis::integer<>(0, 2)); auto b = make_histogram>(T2{}, axis::regular<>{3, 0, 3}, axis::integer<>(0, 2)); BOOST_TEST_EQ(a, b); auto b2 = make_histogram(T2{}, axis::integer<>{0, 3}, - axis::integer<>(0, 2)); + axis::integer<>(0, 2)); BOOST_TEST_NE(a, b2); auto b3 = make_histogram(T2{}, axis::regular<>(3, 0, 4), - axis::integer<>(0, 2)); + axis::integer<>(0, 2)); BOOST_TEST_NE(a, b3); } // copy_assign { auto a = make_histogram(T1{}, axis::regular<>{3, 0, 3}, - axis::integer<>(0, 2)); + axis::integer<>(0, 2)); auto b = make_histogram>(T2{}, axis::regular<>{3, 0, 3}, axis::integer<>(0, 2)); a.fill(1, 1);