From 493d6c7974e6669cbcc0da9e37b9c2c19ddf4350 Mon Sep 17 00:00:00 2001 From: Hans Dembinski Date: Tue, 28 Mar 2017 23:21:21 +0200 Subject: [PATCH] unified both histogram classes --- include/boost/histogram.hpp | 3 +- .../histogram/axis_ostream_operators.hpp | 1 - include/boost/histogram/detail/meta.hpp | 29 +---- include/boost/histogram/detail/variance.hpp | 4 +- include/boost/histogram/histogram.hpp | 14 +++ ...stogram.hpp => histogram_dynamic_impl.hpp} | 111 ++++++++--------- include/boost/histogram/histogram_fwd.hpp | 22 ++++ .../histogram/histogram_ostream_operators.hpp | 9 +- ...istogram.hpp => histogram_static_impl.hpp} | 117 ++++++++---------- include/boost/histogram/serialization.hpp | 11 +- .../histogram/storage/adaptive_storage.hpp | 6 +- .../histogram/storage/container_storage.hpp | 5 +- src/python/histogram.cpp | 35 +++--- test/container_storage_test.cpp | 5 +- test/dynamic_histogram_test.cpp | 40 +++--- test/speed_cpp.cpp | 63 ++++++++-- test/speed_gsl.cpp | 24 ++++ test/speed_numpy.py.in | 32 +++++ test/speed_root.cpp | 22 ++++ test/static_histogram_test.cpp | 29 ++++- 20 files changed, 356 insertions(+), 226 deletions(-) create mode 100644 include/boost/histogram/histogram.hpp rename include/boost/histogram/{dynamic_histogram.hpp => histogram_dynamic_impl.hpp} (70%) create mode 100644 include/boost/histogram/histogram_fwd.hpp rename include/boost/histogram/{static_histogram.hpp => histogram_static_impl.hpp} (58%) diff --git a/include/boost/histogram.hpp b/include/boost/histogram.hpp index 61a736a2..79a4fd0c 100644 --- a/include/boost/histogram.hpp +++ b/include/boost/histogram.hpp @@ -8,8 +8,7 @@ #define BOOST_HISTOGRAM_HPP_ #include -#include -#include +#include #include #include #include diff --git a/include/boost/histogram/axis_ostream_operators.hpp b/include/boost/histogram/axis_ostream_operators.hpp index ee63427f..da9addf8 100644 --- a/include/boost/histogram/axis_ostream_operators.hpp +++ b/include/boost/histogram/axis_ostream_operators.hpp @@ -11,7 +11,6 @@ #include #include #include -#include namespace boost { namespace histogram { diff --git a/include/boost/histogram/detail/meta.hpp b/include/boost/histogram/detail/meta.hpp index 8c86d580..33892cb3 100644 --- a/include/boost/histogram/detail/meta.hpp +++ b/include/boost/histogram/detail/meta.hpp @@ -19,12 +19,11 @@ namespace boost { namespace histogram { namespace detail { -template struct has_weight_support { +template struct has_variance { template static std::false_type test(...); template - static decltype(std::declval().increase(0, 0.0), - std::declval().variance(0), std::true_type{}) + static decltype(std::declval().variance(0), std::true_type{}) test(int); static bool const value = decltype(test(0))::value; @@ -43,11 +42,6 @@ template ()), std::end(std::declval()))> struct is_sequence {}; -struct histogram_tag {}; - -template -struct is_histogram {}; - template struct intersection { using type = typename std::conditional< mpl::equal::value, S1, @@ -55,25 +49,6 @@ template struct intersection { type; }; -// // prefer dynamic over static storage, choose -// // static_storage with larger capacity -// template -// struct select_storage { -// using type = typename std::conditional< -// (is_dynamic_storage::value || -// is_dynamic_storage::value), -// typename std::conditional< -// is_dynamic_storage::value, -// Storage1, Storage2 -// >::type, -// typename std::conditional< -// (std::numeric_limits::max() > -// std::numeric_limits::max()), -// Storage1, Storage2 -// >::type -// >::type; -// }; } // namespace detail } // namespace histogram } // namespace boost diff --git a/include/boost/histogram/detail/variance.hpp b/include/boost/histogram/detail/variance.hpp index f123a52b..8476f382 100644 --- a/include/boost/histogram/detail/variance.hpp +++ b/include/boost/histogram/detail/variance.hpp @@ -15,14 +15,14 @@ namespace detail { namespace { template -typename std::enable_if::value, +typename std::enable_if::value, typename Storage::value_type>::type variance_impl(const Storage &s, std::size_t i) { return s.variance(i); } // delegate to Storage implementation template -typename std::enable_if::value), +typename std::enable_if::value), typename Storage::value_type>::type variance_impl(const Storage &s, std::size_t i) { return s.value(i); diff --git a/include/boost/histogram/histogram.hpp b/include/boost/histogram/histogram.hpp new file mode 100644 index 00000000..7c73269f --- /dev/null +++ b/include/boost/histogram/histogram.hpp @@ -0,0 +1,14 @@ +// Copyright 2015-2017 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_HISTOGRAM_HPP_ +#define _BOOST_HISTOGRAM_HISTOGRAM_HPP_ + +#include +#include +#include + +#endif diff --git a/include/boost/histogram/dynamic_histogram.hpp b/include/boost/histogram/histogram_dynamic_impl.hpp similarity index 70% rename from include/boost/histogram/dynamic_histogram.hpp rename to include/boost/histogram/histogram_dynamic_impl.hpp index d5952f8f..7605b7c6 100644 --- a/include/boost/histogram/dynamic_histogram.hpp +++ b/include/boost/histogram/histogram_dynamic_impl.hpp @@ -4,18 +4,17 @@ // (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) -#ifndef _BOOST_HISTOGRAM_DYNAMIC_HISTOGRAM_HPP_ -#define _BOOST_HISTOGRAM_DYNAMIC_HISTOGRAM_HPP_ +#ifndef _BOOST_HISTOGRAM_HISTOGRAM_DYNAMIC_IMPL_HPP_ +#define _BOOST_HISTOGRAM_HISTOGRAM_DYNAMIC_IMPL_HPP_ #include #include #include +#include #include #include #include #include -#include -#include #include #include #include @@ -28,12 +27,11 @@ namespace boost { namespace histogram { -template > -class dynamic_histogram { +template +class histogram { static_assert(!mpl::empty::value, "at least one axis required"); - using pairs = std::pair; + using size_pair = std::pair; public: - using histogram_tag = detail::histogram_tag; using axis_type = typename make_variant_over::type; using value_type = typename Storage::value_type; @@ -41,34 +39,34 @@ private: using axes_type = std::vector; public: - dynamic_histogram() = default; + histogram() = default; template - explicit dynamic_histogram(const Axes1 &... axes) + explicit histogram(const Axes1 &... axes) : axes_({axis_type(axes)...}) { storage_ = Storage(field_count()); } template > - dynamic_histogram(Iterator axes_begin, Iterator axes_end) + histogram(Iterator axes_begin, Iterator axes_end) : axes_(std::distance(axes_begin, axes_end)) { std::copy(axes_begin, axes_end, axes_.begin()); storage_ = Storage(field_count()); } template - explicit dynamic_histogram( - const dynamic_histogram &other) + explicit histogram( + const histogram &other) : axes_(other.axes_.begin(), other.axes_.end()), storage_(other.storage_) {} template - explicit dynamic_histogram(dynamic_histogram &&other) + explicit histogram(histogram &&other) : axes_(std::move(other.axes_)), storage_(std::move(other.storage_)) {} template - dynamic_histogram & - operator=(const dynamic_histogram &other) { + histogram & + operator=(const histogram &other) { if (static_cast(this) != static_cast(&other)) { axes_ = other.axes_; storage_ = other.storage_; @@ -77,8 +75,8 @@ public: } template - dynamic_histogram & - operator=(dynamic_histogram &&other) { + histogram & + operator=(histogram &&other) { if (static_cast(this) != static_cast(&other)) { axes_ = std::move(other.axes_); storage_ = std::move(other.storage_); @@ -88,7 +86,7 @@ public: template bool - operator==(const dynamic_histogram &other) const { + operator==(const histogram &other) const { if (mpl::empty< typename detail::intersection::type>::value) { return false; @@ -105,13 +103,12 @@ public: return true; } - template