diff --git a/examples/guide_histogram_operators.cpp b/examples/guide_histogram_operators.cpp index 9eadfe0a..6d2d5d6c 100644 --- a/examples/guide_histogram_operators.cpp +++ b/examples/guide_histogram_operators.cpp @@ -40,8 +40,8 @@ int main() { assert(h5.at(0) == 1 && h5.at(1) == 1); assert(h4 != h5 && h4 == 4 * h5); - // note special effect of multiplication on weight_counter variance - auto h = bh::make_histogram_with(std::vector>(), + // note special effect of multiplication on weighted_sum variance + auto h = bh::make_histogram_with(std::vector>(), bh::axis::regular<>(2, -1, 1)); h(-0.5); diff --git a/include/boost/histogram.hpp b/include/boost/histogram.hpp index 2d393970..cf36de8b 100644 --- a/include/boost/histogram.hpp +++ b/include/boost/histogram.hpp @@ -8,7 +8,9 @@ #define BOOST_HISTOGRAM_HPP #include -#include +#include +#include +#include #include #include #include diff --git a/include/boost/histogram/accumulators/mean.hpp b/include/boost/histogram/accumulators/mean.hpp index 374da1e7..ea427222 100644 --- a/include/boost/histogram/accumulators/mean.hpp +++ b/include/boost/histogram/accumulators/mean.hpp @@ -27,7 +27,7 @@ public: mean(const std::size_t n, const RealType& mean, const RealType& variance) : sum_(n), mean_(mean), dsum2_(variance * (sum_ - 1)) {} - void operator()(const RealType& x) noexcept { + void operator()(const RealType& x) { sum_ += 1; const auto delta = x - mean_; mean_ += delta / sum_; @@ -43,7 +43,7 @@ public: return *this; } - mean& operator*=(const RealType& s) noexcept { + mean& operator*=(const RealType& s) { mean_ *= s; dsum2_ *= s * s; return *this; @@ -61,7 +61,7 @@ public: std::size_t sum() const noexcept { return sum_; } const RealType& value() const noexcept { return mean_; } - RealType variance() const noexcept { return dsum2_ / (sum_ - 1); } + RealType variance() const { return dsum2_ / (sum_ - 1); } template void serialize(Archive&, unsigned /* version */); diff --git a/include/boost/histogram/accumulators/ostream_operators.hpp b/include/boost/histogram/accumulators/ostream_operators.hpp index 64a2d234..f08e2fca 100644 --- a/include/boost/histogram/accumulators/ostream_operators.hpp +++ b/include/boost/histogram/accumulators/ostream_operators.hpp @@ -15,15 +15,15 @@ namespace histogram { namespace accumulators { template std::basic_ostream& operator<<(std::basic_ostream& os, - const neumaier& x) { - os << "neumaier(" << x.large() << " + " << x.small() << ")"; + const sum& x) { + os << "sum(" << x.large() << " + " << x.small() << ")"; return os; } template std::basic_ostream& operator<<(std::basic_ostream& os, - const weight& x) { - os << "weight(" << x.value() << ", " << x.variance() << ")"; + const weighted_sum& x) { + os << "weighted_sum(" << x.value() << ", " << x.variance() << ")"; return os; } @@ -37,8 +37,7 @@ std::basic_ostream& operator<<(std::basic_ostream& template std::basic_ostream& operator<<(std::basic_ostream& os, const weighted_mean& x) { - os << "weighted_mean(" << x.sum() << ", " << x.sum2() << ", " << x.value() << ", " - << x.variance() << ")"; + os << "weighted_mean(" << x.sum() << ", " << x.value() << ", " << x.variance() << ")"; return os; } } // namespace accumulators diff --git a/include/boost/histogram/accumulators/neumaier.hpp b/include/boost/histogram/accumulators/sum.hpp similarity index 54% rename from include/boost/histogram/accumulators/neumaier.hpp rename to include/boost/histogram/accumulators/sum.hpp index 394bfb20..34ad4bb9 100644 --- a/include/boost/histogram/accumulators/neumaier.hpp +++ b/include/boost/histogram/accumulators/sum.hpp @@ -4,8 +4,8 @@ // (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) -#ifndef BOOST_HISTOGRAM_ACCUMULATORS_NEUMAIER_HPP -#define BOOST_HISTOGRAM_ACCUMULATORS_NEUMAIER_HPP +#ifndef BOOST_HISTOGRAM_ACCUMULATORS_SUM_HPP +#define BOOST_HISTOGRAM_ACCUMULATORS_SUM_HPP #include #include @@ -17,31 +17,32 @@ namespace accumulators { /** Uses Neumaier algorithm to compute accurate sums. - The algorithm is about four times slower compared to using - a simple floating point number to accumulate a sum, but the - relative error of the sum for non-negative numbers is - constant and at the level of the machine precision. + The algorithm uses memory for two floats and is three to + five times slower compared to a simple floating point + number used to accumulate a sum, but the relative error + of the sum is at the level of the machine precision, + independent of the number of samples. A. Neumaier, Zeitschrift fuer Angewandte Mathematik und Mechanik 54 (1974) 39–51. */ template -class neumaier { +class sum { public: - neumaier() = default; - neumaier(const RealType& value) noexcept : sum_(value), cor_(0) {} - neumaier& operator=(const RealType& value) noexcept { + sum() = default; + explicit sum(const RealType& value) noexcept : sum_(value), cor_(0) {} + sum& operator=(const RealType& value) noexcept { sum_ = value; cor_ = 0; return *this; } - void operator()() noexcept { operator+=(1); } + void operator()() { operator+=(1); } - void operator()(const RealType& x) noexcept { operator+=(x); } + void operator()(const RealType& x) { operator+=(x); } - neumaier& operator+=(const RealType& x) noexcept { - volatile auto temp = sum_ + x; // prevent optimization + sum& operator+=(const RealType& x) { + auto temp = sum_ + x; // prevent optimization if (std::abs(sum_) >= std::abs(x)) cor_ += (sum_ - temp) + x; else @@ -50,27 +51,27 @@ public: return *this; } - neumaier& operator*=(const RealType& x) noexcept { + sum& operator*=(const RealType& x) { sum_ *= x; cor_ *= x; return *this; } template - bool operator==(const neumaier& rhs) const noexcept { + bool operator==(const sum& rhs) const noexcept { return sum_ == rhs.sum_ && cor_ == rhs.cor_; } template - bool operator!=(const neumaier& rhs) const noexcept { + bool operator!=(const T& rhs) const noexcept { return !operator==(rhs); } - RealType value() const noexcept { return sum_ + cor_; } const RealType& large() const noexcept { return sum_; } const RealType& small() const noexcept { return cor_; } - operator RealType() const noexcept { return value(); } + // allow implicit conversion to RealType + operator RealType() const { return sum_ + cor_; } template void serialize(Archive&, unsigned /* version */); diff --git a/include/boost/histogram/accumulators/weight.hpp b/include/boost/histogram/accumulators/weight.hpp deleted file mode 100644 index 36c5fec5..00000000 --- a/include/boost/histogram/accumulators/weight.hpp +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright 2015-2018 Hans Dembinski -// -// Distributed under the Boost Software License, version 1.0. -// (See accompanying file LICENSE_1_0.txt -// or copy at http://www.boost.org/LICENSE_1_0.txt) - -#ifndef BOOST_HISTOGRAM_ACCUMULATORS_WEIGHT_HPP -#define BOOST_HISTOGRAM_ACCUMULATORS_WEIGHT_HPP - -#include - -namespace boost { -namespace histogram { -namespace accumulators { - -/// Holds sum of weights and sum of weights squared -template -class weight { -public: - weight() = default; - weight(const RealType& value) noexcept : w_(value), w2_(value) {} - weight(const RealType& value, const RealType& variance) noexcept - : w_(value), w2_(variance) {} - - void operator()() noexcept { - w_ += 1; - w2_ += 1; - } - - void operator()(const RealType& w) noexcept { - w_ += w; - w2_ += w * w; - } - - // used when adding non-weighted histogram to weighted histogram - weight& operator+=(const RealType& x) noexcept { - w_ += x; - w2_ += x; - return *this; - } - - template - weight& operator+=(const weight& rhs) { - w_ += static_cast(rhs.w_); - w2_ += static_cast(rhs.w2_); - return *this; - } - - weight& operator*=(const RealType& x) noexcept { - w_ *= x; - w2_ *= x * x; - return *this; - } - - bool operator==(const weight& rhs) const noexcept { - return w_ == rhs.w_ && w2_ == rhs.w2_; - } - - bool operator!=(const weight& rhs) const noexcept { return !operator==(rhs); } - - template - bool operator==(const weight& rhs) const noexcept { - return w_ == rhs.w_ && w2_ == rhs.w2_; - } - - template - bool operator!=(const weight& rhs) const noexcept { - return !operator==(rhs); - } - - const RealType& value() const noexcept { return w_; } - const RealType& variance() const noexcept { return w2_; } - - // lossy conversion must be explicit - template - explicit operator T() const { - return static_cast(w_); - } - - template - void serialize(Archive&, unsigned /* version */); - -private: - RealType w_ = 0, w2_ = 0; -}; - -} // namespace accumulators -} // namespace histogram -} // namespace boost - -#endif diff --git a/include/boost/histogram/accumulators/weighted_mean.hpp b/include/boost/histogram/accumulators/weighted_mean.hpp index 47317044..1d6fb4d2 100644 --- a/include/boost/histogram/accumulators/weighted_mean.hpp +++ b/include/boost/histogram/accumulators/weighted_mean.hpp @@ -25,32 +25,29 @@ public: weighted_mean() = default; weighted_mean(const RealType& wsum, const RealType& wsum2, const RealType& mean, const RealType& variance) - : wsum_(wsum) - , wsum2_(wsum2) - , mean_(mean) - , dsum2_(variance * (wsum_ - wsum2_ / wsum_)) {} + : sum_(wsum), sum2_(wsum2), mean_(mean), dsum2_(variance * (sum_ - sum2_ / sum_)) {} - void operator()(const RealType& x) noexcept { operator()(1, x); } + void operator()(const RealType& x) { operator()(1, x); } - void operator()(const RealType& w, const RealType& x) noexcept { - wsum_ += w; - wsum2_ += w * w; + void operator()(const RealType& w, const RealType& x) { + sum_ += w; + sum2_ += w * w; const auto delta = x - mean_; - mean_ += w * delta / wsum_; + mean_ += w * delta / sum_; dsum2_ += w * delta * (x - mean_); } template weighted_mean& operator+=(const weighted_mean& rhs) { - const auto tmp = mean_ * wsum_ + static_cast(rhs.mean_ * rhs.wsum_); - wsum_ += static_cast(rhs.wsum_); - wsum2_ += static_cast(rhs.wsum2_); - mean_ = tmp / wsum_; + const auto tmp = mean_ * sum_ + static_cast(rhs.mean_ * rhs.sum_); + sum_ += static_cast(rhs.sum_); + sum2_ += static_cast(rhs.sum2_); + mean_ = tmp / sum_; dsum2_ += static_cast(rhs.dsum2_); return *this; } - weighted_mean& operator*=(const RealType& s) noexcept { + weighted_mean& operator*=(const RealType& s) { mean_ *= s; dsum2_ *= s * s; return *this; @@ -58,25 +55,24 @@ public: template bool operator==(const weighted_mean& rhs) const noexcept { - return wsum_ == rhs.wsum_ && wsum2_ == rhs.wsum2_ && mean_ == rhs.mean_ && + return sum_ == rhs.sum_ && sum2_ == rhs.sum2_ && mean_ == rhs.mean_ && dsum2_ == rhs.dsum2_; } template - bool operator!=(const weighted_mean& rhs) const noexcept { + bool operator!=(const T& rhs) const noexcept { return !operator==(rhs); } - const RealType& sum() const noexcept { return wsum_; } - const RealType& sum2() const noexcept { return wsum2_; } + const RealType& sum() const noexcept { return sum_; } const RealType& value() const noexcept { return mean_; } - RealType variance() const noexcept { return dsum2_ / (wsum_ - wsum2_ / wsum_); } + RealType variance() const { return dsum2_ / (sum_ - sum2_ / sum_); } template void serialize(Archive&, unsigned /* version */); private: - RealType wsum_ = 0, wsum2_ = 0, mean_ = 0, dsum2_ = 0; + RealType sum_ = RealType(), sum2_ = RealType(), mean_ = RealType(), dsum2_ = RealType(); }; } // namespace accumulators diff --git a/include/boost/histogram/accumulators/weighted_sum.hpp b/include/boost/histogram/accumulators/weighted_sum.hpp new file mode 100644 index 00000000..33ff8632 --- /dev/null +++ b/include/boost/histogram/accumulators/weighted_sum.hpp @@ -0,0 +1,91 @@ +// Copyright 2015-2018 Hans Dembinski +// +// Distributed under the Boost Software License, version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_HISTOGRAM_ACCUMULATORS_WEIGHTED_SUM_HPP +#define BOOST_HISTOGRAM_ACCUMULATORS_WEIGHTED_SUM_HPP + +#include + +namespace boost { +namespace histogram { +namespace accumulators { + +/// Holds sum of weights and its variance estimate +template +class weighted_sum { +public: + weighted_sum() = default; + explicit weighted_sum(const RealType& value) noexcept : sum_(value), sum2_(value) {} + weighted_sum(const RealType& value, const RealType& variance) noexcept + : sum_(value), sum2_(variance) {} + + void operator()() { + sum_ += 1; + sum2_ += 1; + } + + template + void operator()(const T& w) { + sum_ += w; + sum2_ += w * w; + } + + // used when adding non-weighted histogram to weighted histogram + template + weighted_sum& operator+=(const T& x) { + sum_ += x; + sum2_ += x; + return *this; + } + + template + weighted_sum& operator+=(const weighted_sum& rhs) { + sum_ += static_cast(rhs.sum_); + sum2_ += static_cast(rhs.sum2_); + return *this; + } + + weighted_sum& operator*=(const RealType& x) { + sum_ *= x; + sum2_ *= x * x; + return *this; + } + + bool operator==(const RealType& rhs) const noexcept { + return sum_ == rhs && sum2_ == rhs; + } + + template + bool operator==(const weighted_sum& rhs) const noexcept { + return sum_ == rhs.sum_ && sum2_ == rhs.sum2_; + } + + template + bool operator!=(const T& rhs) const noexcept { + return !operator==(rhs); + } + + const RealType& value() const noexcept { return sum_; } + const RealType& variance() const noexcept { return sum2_; } + + // lossy conversion must be explicit + template + explicit operator T() const { + return static_cast(sum_); + } + + template + void serialize(Archive&, unsigned /* version */); + +private: + RealType sum_ = RealType(), sum2_ = RealType(); +}; + +} // namespace accumulators +} // namespace histogram +} // namespace boost + +#endif diff --git a/include/boost/histogram/algorithm/sum.hpp b/include/boost/histogram/algorithm/sum.hpp index 26d24a14..74a70a1f 100644 --- a/include/boost/histogram/algorithm/sum.hpp +++ b/include/boost/histogram/algorithm/sum.hpp @@ -7,7 +7,7 @@ #ifndef BOOST_HISTOGRAM_ALGORITHM_SUM_HPP #define BOOST_HISTOGRAM_ALGORITHM_SUM_HPP -#include +#include #include #include #include @@ -15,10 +15,15 @@ namespace boost { namespace histogram { namespace algorithm { -template ::value_type> -T sum(const histogram& h, T init = T(0)) { - for (auto x : h) init += x; - return init; +template < + typename A, typename S, typename T = typename histogram::value_type, + typename ReturnType = std::conditional_t::value, double, T>, + typename InternalSum = + std::conditional_t::value, accumulators::sum, T>> +ReturnType sum(const histogram& h) { + InternalSum sum; + for (auto x : h) sum += x; + return sum; } } // namespace algorithm } // namespace histogram diff --git a/include/boost/histogram/histogram_fwd.hpp b/include/boost/histogram/histogram_fwd.hpp index d4e59034..7ea907e8 100644 --- a/include/boost/histogram/histogram_fwd.hpp +++ b/include/boost/histogram/histogram_fwd.hpp @@ -62,9 +62,9 @@ struct sample_type; namespace accumulators { template -class neumaier; +class sum; template -class weight; +class weighted_sum; template class mean; template @@ -80,6 +80,7 @@ template > struct adaptive_storage; using default_storage = adaptive_storage<>; +using weight_storage = storage_adaptor>>; template class histogram; diff --git a/include/boost/histogram/make_histogram.hpp b/include/boost/histogram/make_histogram.hpp index a9e9f054..f37bc095 100644 --- a/include/boost/histogram/make_histogram.hpp +++ b/include/boost/histogram/make_histogram.hpp @@ -7,10 +7,12 @@ #ifndef BOOST_HISTOGRAM_MAKE_HISTOGRAM_HPP #define BOOST_HISTOGRAM_MAKE_HISTOGRAM_HPP +#include #include // implements default_storage #include #include #include +#include namespace boost { namespace histogram { @@ -24,13 +26,20 @@ auto make_histogram_with(C&& c, T&& axis0, Ts&&... axis) { return histogram(std::move(axes), std::forward(c)); } -/// histogram factory from compile-time axis configuration with standard storage +/// histogram factory from compile-time axis configuration with default storage template > auto make_histogram(T&& axis0, Ts&&... axis) { return make_histogram_with(default_storage(), std::forward(axis0), std::forward(axis)...); } +/// histogram factory from compile-time axis configuration with weight storage +template > +auto make_weighted_histogram(T&& axis0, Ts&&... axis) { + return make_histogram_with(weight_storage(), std::forward(axis0), + std::forward(axis)...); +} + /// histogram factory from vector-like with custom storage template > auto make_histogram_with(C&& c, T&& t) { @@ -39,12 +48,18 @@ auto make_histogram_with(C&& c, T&& t) { return histogram, S>(std::forward(t), std::forward(c)); } -/// dynamic type factory from vector-like with default storage +/// histogram factory from vector-like with default storage template > auto make_histogram(T&& t) { return make_histogram_with(default_storage(), std::forward(t)); } +/// histogram factory from vector-like with default storage +template > +auto make_weighted_histogram(T&& t) { + return make_histogram_with(weight_storage(), std::forward(t)); +} + /// histogram factory from iterator range with custom storage template > auto make_histogram_with(C&& c, Iterator begin, Iterator end) { @@ -59,6 +74,12 @@ auto make_histogram(Iterator begin, Iterator end) { return make_histogram_with(default_storage(), begin, end); } +/// dynamic type factory from iterator range with weight storage +template > +auto make_weighted_histogram(Iterator begin, Iterator end) { + return make_histogram_with(weight_storage(), begin, end); +} + } // namespace histogram } // namespace boost diff --git a/include/boost/histogram/ostream_operators.hpp b/include/boost/histogram/ostream_operators.hpp index c17fb709..cf012684 100644 --- a/include/boost/histogram/ostream_operators.hpp +++ b/include/boost/histogram/ostream_operators.hpp @@ -7,6 +7,7 @@ #ifndef BOOST_HISTOGRAM_OSTREAM_OPERATORS_HPP #define BOOST_HISTOGRAM_OSTREAM_OPERATORS_HPP +#include #include #include #include @@ -23,20 +24,6 @@ std::basic_ostream& operator<<(std::basic_ostream& return os; } -template -std::basic_ostream& operator<<(std::basic_ostream& os, - const accumulators::weight& x) { - os << "weight(" << x.value() << ", " << x.variance() << ")"; - return os; -} - -template -std::basic_ostream& operator<<(std::basic_ostream& os, - const accumulators::mean& x) { - os << "mean(" << x.sum() << ", " << x.value() << ", " << x.variance() << ")"; - return os; -} - } // namespace histogram } // namespace boost diff --git a/include/boost/histogram/serialization.hpp b/include/boost/histogram/serialization.hpp index 4566fceb..94008162 100644 --- a/include/boost/histogram/serialization.hpp +++ b/include/boost/histogram/serialization.hpp @@ -8,8 +8,9 @@ #define BOOST_HISTOGRAM_SERIALIZATION_HPP #include -#include +#include #include +#include #include #include #include @@ -48,9 +49,16 @@ namespace histogram { namespace accumulators { template template -void weight::serialize(Archive& ar, unsigned /* version */) { - ar& w_; - ar& w2_; +void sum::serialize(Archive& ar, unsigned /* version */) { + ar& sum_; + ar& cor_; +} + +template +template +void weighted_sum::serialize(Archive& ar, unsigned /* version */) { + ar& sum_; + ar& sum2_; } template @@ -64,8 +72,8 @@ void mean::serialize(Archive& ar, unsigned /* version */) { template template void weighted_mean::serialize(Archive& ar, unsigned /* version */) { - ar& wsum_; - ar& wsum2_; + ar& sum_; + ar& sum2_; ar& mean_; ar& dsum2_; } diff --git a/test/adaptive_storage_serialization_test.cpp b/test/adaptive_storage_serialization_test.cpp index caa98802..0d88e652 100644 --- a/test/adaptive_storage_serialization_test.cpp +++ b/test/adaptive_storage_serialization_test.cpp @@ -4,12 +4,11 @@ // (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) -#include #include #include -#include -#include +#include #include +#include #include #include diff --git a/test/axis_category_test.cpp b/test/axis_category_test.cpp index cbc67ea0..d19a062b 100644 --- a/test/axis_category_test.cpp +++ b/test/axis_category_test.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include diff --git a/test/axis_circular_test.cpp b/test/axis_circular_test.cpp index 8e3269ea..ff0dc2d3 100644 --- a/test/axis_circular_test.cpp +++ b/test/axis_circular_test.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include "utility_axis.hpp" diff --git a/test/axis_integer_test.cpp b/test/axis_integer_test.cpp index 857d77db..542cc611 100644 --- a/test/axis_integer_test.cpp +++ b/test/axis_integer_test.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include diff --git a/test/axis_regular_test.cpp b/test/axis_regular_test.cpp index e5e9bc08..2612b0c1 100644 --- a/test/axis_regular_test.cpp +++ b/test/axis_regular_test.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include diff --git a/test/axis_variable_test.cpp b/test/axis_variable_test.cpp index 6203f4d0..38e36634 100644 --- a/test/axis_variable_test.cpp +++ b/test/axis_variable_test.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include "utility_axis.hpp" diff --git a/test/axis_variant_test.cpp b/test/axis_variant_test.cpp index dca57ca0..511ea192 100644 --- a/test/axis_variant_test.cpp +++ b/test/axis_variant_test.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -137,9 +136,9 @@ int main() { "category(0, 1, 2, metadata=\"category\", options=overflow)"); test(axis::category({"A", "B"}, "category2"), "category(\"A\", \"B\", metadata=\"category2\", options=overflow)"); - const auto ref = detail::cat("integer(-1, 1, metadata=", - boost::core::demangled_name(BOOST_CORE_TYPEID(user_defined)), - ", options=none)"); + const auto ref = detail::cat( + "integer(-1, 1, metadata=", + boost::core::demangled_name(BOOST_CORE_TYPEID(user_defined)), ", options=none)"); test(axis::integer(-1, 1, {}, axis::option_type::none), ref.c_str()); } diff --git a/test/boost_accumulators_test.cpp b/test/boost_accumulators_test.cpp index 328f6036..b7b0e9f9 100644 --- a/test/boost_accumulators_test.cpp +++ b/test/boost_accumulators_test.cpp @@ -24,7 +24,6 @@ #endif #include -#include #include #include diff --git a/test/detail_test.cpp b/test/detail_test.cpp index c554fec1..5c6b915f 100644 --- a/test/detail_test.cpp +++ b/test/detail_test.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include "utility_meta.hpp" diff --git a/test/histogram_test.cpp b/test/histogram_test.cpp index 19746c7c..bc4d1705 100644 --- a/test/histogram_test.cpp +++ b/test/histogram_test.cpp @@ -7,8 +7,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -269,7 +269,8 @@ void run_tests() { // d1 weight { - auto h = make_s(Tag(), std::vector>(), axis::integer<>(0, 2)); + auto h = + make_s(Tag(), std::vector>(), axis::integer<>(0, 2)); h(-1); h(0); h(weight(0.5), 0); @@ -365,9 +366,9 @@ void run_tests() { // d2w { - auto h = - make_s(Tag(), std::vector>(), axis::regular<>(2, -1, 1), - axis::integer<>(-1, 2, {}, axis::option_type::none)); + auto h = make_s(Tag(), std::vector>(), + axis::regular<>(2, -1, 1), + axis::integer<>(-1, 2, {}, axis::option_type::none)); h(-1, 0); // -> 0, 1 h(weight(10), -1, -1); // -> 0, 0 h(weight(5), -1, -10); // is ignored @@ -411,8 +412,8 @@ void run_tests() { // d3w { - auto h = make_s(Tag(), std::vector>(), axis::integer<>(0, 3), - axis::integer<>(0, 4), axis::integer<>(0, 5)); + auto h = make_s(Tag(), std::vector>(), + axis::integer<>(0, 3), axis::integer<>(0, 4), axis::integer<>(0, 5)); for (auto i = 0u; i < h.axis(0_c).size(); ++i) { for (auto j = 0u; j < h.axis(1_c).size(); ++j) { for (auto k = 0u; k < h.axis(2_c).size(); ++k) { h(i, j, k, weight(i + j + k)); } @@ -454,8 +455,10 @@ void run_tests() { // add_2 { - auto a = make_s(Tag(), std::vector>(), axis::integer<>(0, 2)); - auto b = make_s(Tag(), std::vector>(), axis::integer<>(0, 2)); + auto a = + make_s(Tag(), std::vector>(), axis::integer<>(0, 2)); + auto b = + make_s(Tag(), std::vector>(), axis::integer<>(0, 2)); a(0); BOOST_TEST_EQ(a.at(0).variance(), 1); @@ -624,7 +627,8 @@ void run_tests() { // histogram iterator 1D { - auto h = make_s(Tag(), std::vector>(), axis::integer<>(0, 3)); + auto h = + make_s(Tag(), std::vector>(), axis::integer<>(0, 3)); const auto& a = h.axis(); h(weight(2), 0); h(1); @@ -664,8 +668,9 @@ void run_tests() { // histogram iterator 2D { - auto h = make_s(Tag(), std::vector>(), axis::integer<>(0, 1), - axis::integer<>(2, 4, "", axis::option_type::none)); + auto h = + make_s(Tag(), std::vector>(), axis::integer<>(0, 1), + axis::integer<>(2, 4, "", axis::option_type::none)); const auto& a0 = h.axis(0_c); const auto& a1 = h.axis(1_c); h(weight(2), 0, 2); @@ -726,8 +731,8 @@ void run_tests() { // using static containers { - auto h = make_s(Tag(), std::vector>(), axis::integer<>(0, 2), - axis::regular<>(2, 2, 4)); + auto h = make_s(Tag(), std::vector>(), + axis::integer<>(0, 2), axis::regular<>(2, 2, 4)); // tuple in h(std::make_tuple(0, 2.0)); h(std::make_tuple(1, 3.0)); diff --git a/test/internal_accumulators_test.cpp b/test/internal_accumulators_test.cpp index 1c734449..d9600cd3 100644 --- a/test/internal_accumulators_test.cpp +++ b/test/internal_accumulators_test.cpp @@ -6,10 +6,10 @@ #include #include -#include #include -#include +#include #include +#include #include #include "is_close.hpp" @@ -17,15 +17,15 @@ using namespace boost::histogram; int main() { { - using w_t = accumulators::weight; + using w_t = accumulators::weighted_sum; w_t w; std::ostringstream os; os << w; - BOOST_TEST_EQ(os.str(), std::string("weight(0, 0)")); + BOOST_TEST_EQ(os.str(), std::string("weighted_sum(0, 0)")); BOOST_TEST_EQ(w, w_t(0)); BOOST_TEST_NE(w, w_t(1)); - w = 1; + w = w_t(1); BOOST_TEST_EQ(w.value(), 1); BOOST_TEST_EQ(w.variance(), 1); BOOST_TEST_EQ(w, 1); @@ -115,7 +115,7 @@ int main() { std::ostringstream os; os << a; - BOOST_TEST_EQ(os.str(), std::string("weighted_mean(2, 1.5, 2, 0.8)")); + BOOST_TEST_EQ(os.str(), std::string("weighted_mean(2, 2, 0.8)")); auto b = a; b += a; // same as feeding all samples twice @@ -133,16 +133,16 @@ int main() { bad_sum += -1e100; BOOST_TEST_EQ(bad_sum, 0); // instead of 2 - accumulators::neumaier sum; + accumulators::sum sum; sum(); // equivalent to sum += 1 sum(1e100); // equivalent to sum += 1e100 sum += 1; sum += -1e100; - BOOST_TEST_EQ(sum.value(), 2); + BOOST_TEST_EQ(sum, 2); } { - accumulators::weight> w; + accumulators::weighted_sum> w; w(); w(1e100); diff --git a/test/storage_adaptor_serialization_test.cpp b/test/storage_adaptor_serialization_test.cpp index 2a67a2ed..b05e9dfa 100644 --- a/test/storage_adaptor_serialization_test.cpp +++ b/test/storage_adaptor_serialization_test.cpp @@ -4,18 +4,17 @@ // (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) -#include +#include #include #include +#include #include -#include #include #include -#include -#include -#include #include #include +#include +#include using namespace boost::histogram; diff --git a/test/storage_adaptor_test.cpp b/test/storage_adaptor_test.cpp index 1df51d88..92d44b4e 100644 --- a/test/storage_adaptor_test.cpp +++ b/test/storage_adaptor_test.cpp @@ -6,10 +6,9 @@ #include #include -#include #include +#include #include -#include #include #include #include @@ -197,13 +196,13 @@ int main() { mixed_tests, storage_adaptor>>(); mixed_tests>, adaptive_storage<>>(); - // with accumulators::weight + // with accumulators::weighted_sum { - auto a = storage_adaptor>>(); + auto a = storage_adaptor>>(); a.reset(1); a(0); a.add(0, 1); - a.add(0, accumulators::weight(1, 0)); + a.add(0, accumulators::weighted_sum(1, 0)); BOOST_TEST_EQ(a[0].value(), 3); BOOST_TEST_EQ(a[0].variance(), 2); auto weight = 2;