diff --git a/doc/getting_started.qbk b/doc/getting_started.qbk index 133cb03f..4cb10ed8 100644 --- a/doc/getting_started.qbk +++ b/doc/getting_started.qbk @@ -12,9 +12,11 @@ int main(int, char**) { namespace bh = boost::histogram; using namespace bh::literals; // enables _c suffix - // create 1d-histogram with 10 equidistant bins from -1.0 to 2.0, + // create static 1d-histogram with 10 equidistant bins from -1.0 to 2.0, // with axis of histogram labeled as "x" - auto h = bh::make_static_histogram(bh::axis::regular<>(10, -1.0, 2.0, "x")); + auto h = bh::make_static_histogram( + bh::axis::regular<>(10, -1.0, 2.0, "x") + ); // fill histogram with data h.fill(-1.5); // put in underflow bin @@ -77,12 +79,55 @@ int main(int, char**) { [endsect] +[section Make and use a dynamic 2d-histogram in C++] + +Here we fill the histogram with some random numbers. + +[c++]`` +#include +#include +#include +#include + +namespace br = boost::random; +namespace bh = boost::histogram; + +int main() { + /* + create dynamic histogram using `make_dynamic_histogram` + - axis can be passed directly, just like for `make_static_histogram` + - in addition, also accepts iterators over a sequence of axes + */ + std::vector> axes = {bh::axis::regular<>(5, -5, 5, "x"), + bh::axis::regular<>(5, -5, 5, "y")}; + auto h = bh::make_dynamic_histogram(axes.begin(), axes.end()); + + // fill histogram, random numbers are generated on the fly + br::mt19937 gen; + br::normal_distribution<> norm; + for (int i = 0; i < 1000; ++i) + h.fill(norm(gen), norm(gen)); + + /* + print histogram + - in opposition to the static case, we need to cast axis to correct + type since dynamic histogram cannot do this automatically + - + */ + for (const auto& ybin : h.axis(1)) { + for (const auto& xbin : h.axis(0)) { + std::printf("%3.0f ", h.value(xbin.first, ybin.first)); + } + std::printf("\n"); + } +} +`` + [section Make and use a 2d-histogram in Python] You need to build the library with Numpy support to run this example. -[python]`` -import histogram as hg +[python]`import histogram as hg import numpy as np # create 2d-histogram with two axes with 10 equidistant bins from -3 to 3 diff --git a/doc/guide.qbk b/doc/guide.qbk index cc587b06..b2b94605 100644 --- a/doc/guide.qbk +++ b/doc/guide.qbk @@ -79,7 +79,7 @@ When you work with [classref boost::histogram::histogram], you can namespace bh = boost::histogram; int main() { - using hist_type = bh::histogram; + using hist_type = bh::histogram; auto v = std::vector(); v.push_back(bh::axis::regular<>(100, -1, 1)); v.push_back(bh::axis::integer<>(1, 7)); diff --git a/examples/create_dynamic_histogram.cpp b/examples/create_dynamic_histogram.cpp index 94c83661..ae42a4ce 100644 --- a/examples/create_dynamic_histogram.cpp +++ b/examples/create_dynamic_histogram.cpp @@ -12,9 +12,7 @@ namespace bh = boost::histogram; */ int main(int argc, char** argv) { - using Histogram = bh::histogram; - - auto v = std::vector(); + auto v = std::vector>(); // parse arguments auto argi = 1; @@ -46,7 +44,7 @@ int main(int argc, char** argv) { } } - auto h = Histogram(v.begin(), v.end()); + auto h = bh::histogram(v.begin(), v.end()); // do something with h std::cout << "you created the following histogram:\n" << h << std::endl; diff --git a/examples/example_2d.cpp b/examples/example_2d.cpp deleted file mode 100644 index dbc8dc34..00000000 --- a/examples/example_2d.cpp +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2015-2016 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) - -#include -#include -#include -#include - -namespace br = boost::random; -namespace bh = boost::histogram; - -int main() { - using namespace bh::literals; // for _c - br::mt19937 gen; - br::normal_distribution<> norm; - auto h = bh::make_static_histogram( - bh::axis::regular<>(5, -5, 5, "x"), - bh::axis::regular<>(5, -5, 5, "y") - ); - - // fill histogram - for (int i = 0; i < 1000; ++i) - h.fill(norm(gen), norm(gen)); - - // show histogram - for (const auto& ybin : h.axis(1_c)) { // vertical - for (const auto& xbin : h.axis(0_c)) { // horizontal - std::printf("%3.0f ", h.value(xbin.first, ybin.first)); - } - std::printf("\n"); - } -} diff --git a/examples/getting_started_listing_1.cpp b/examples/getting_started_listing_1.cpp index 3beb9081..fb821ba6 100644 --- a/examples/getting_started_listing_1.cpp +++ b/examples/getting_started_listing_1.cpp @@ -5,9 +5,11 @@ int main(int, char**) { namespace bh = boost::histogram; using namespace bh::literals; // enables _c suffix - // create 1d-histogram with 10 equidistant bins from -1.0 to 2.0, + // create static 1d-histogram with 10 equidistant bins from -1.0 to 2.0, // with axis of histogram labeled as "x" - auto h = bh::make_static_histogram(bh::axis::regular<>(10, -1.0, 2.0, "x")); + auto h = bh::make_static_histogram( + bh::axis::regular<>(10, -1.0, 2.0, "x") + ); // fill histogram with data h.fill(-1.5); // put in underflow bin diff --git a/examples/getting_started_listing_2.cpp b/examples/getting_started_listing_2.cpp new file mode 100644 index 00000000..f53d6397 --- /dev/null +++ b/examples/getting_started_listing_2.cpp @@ -0,0 +1,37 @@ +#include +#include +#include +#include + +namespace br = boost::random; +namespace bh = boost::histogram; + +int main() { + /* + create dynamic histogram using `make_dynamic_histogram` + - axis can be passed directly, just like for `make_static_histogram` + - in addition, also accepts iterators over a sequence of axes + */ + std::vector> axes = {bh::axis::regular<>(5, -5, 5, "x"), + bh::axis::regular<>(5, -5, 5, "y")}; + auto h = bh::make_dynamic_histogram(axes.begin(), axes.end()); + + // fill histogram, random numbers are generated on the fly + br::mt19937 gen; + br::normal_distribution<> norm; + for (int i = 0; i < 1000; ++i) + h.fill(norm(gen), norm(gen)); + + /* + print histogram + - in opposition to the static case, we need to cast axis to correct + type since dynamic histogram cannot do this automatically + - + */ + for (const auto& ybin : h.axis(1)) { + for (const auto& xbin : h.axis(0)) { + std::printf("%3.0f ", h.value(xbin.first, ybin.first)); + } + std::printf("\n"); + } +} diff --git a/examples/getting_started_listing_3.py b/examples/getting_started_listing_3.py new file mode 100644 index 00000000..4d26e5b8 --- /dev/null +++ b/examples/getting_started_listing_3.py @@ -0,0 +1,37 @@ +import histogram as hg +import numpy as np + +# create 2d-histogram with two axes with 10 equidistant bins from -3 to 3 +h = hg.histogram(hg.axis.regular(10, -3, 3, "x"), + hg.axis.regular(10, -3, 3, "y")) + +# generate some numpy arrays with data to fill into histogram, +# in this case normal distributed random numbers in x and y +x = np.random.randn(1000) +y = 0.5 * np.random.randn(1000) + +# fill histogram with numpy arrays, this is very fast +h.fill(x, y) + +# get representations of the bin edges as Numpy arrays, this representation +# differs from `list(h.axis(0))`, because it is optimised for compatibility +# with existing Numpy code, i.e. to replace numpy.histogram +x = np.array(h.axis(0)) +y = np.array(h.axis(1)) + +# creates a view of the counts (no copy involved) +count_matrix = np.asarray(h) + +# cut off the under- and overflow bins (no copy involved) +reduced_count_matrix = count_matrix[:-2,:-2] + +try: + # draw the count matrix + import matplotlib.pyplot as plt + plt.pcolor(x, y, reduced_count_matrix.T) + plt.xlabel(h.axis(0).label) + plt.ylabel(h.axis(1).label) + plt.savefig("example_2d_python.png") +except ImportError: + # ok, no matplotlib, then just print it + print count_matrix diff --git a/examples/guide_listing_5.cpp b/examples/guide_listing_5.cpp index a33ebd8b..8f8d11d0 100644 --- a/examples/guide_listing_5.cpp +++ b/examples/guide_listing_5.cpp @@ -5,8 +5,8 @@ namespace bh = boost::histogram; int main() { - using hist_type = bh::histogram; - auto v = std::vector(); + using hist_type = bh::histogram; + auto v = std::vector>(); v.push_back(bh::axis::regular<>(100, -1, 1)); v.push_back(bh::axis::integer<>(1, 7)); auto h = hist_type(v.begin(), v.end()); diff --git a/examples/module_cpp_filler.cpp b/examples/module_cpp_filler.cpp index a57f715f..b7d55054 100644 --- a/examples/module_cpp_filler.cpp +++ b/examples/module_cpp_filler.cpp @@ -13,7 +13,7 @@ namespace br = boost::random; namespace bh = boost::histogram; namespace bp = boost::python; -void process(bh::histogram& h) { +void process(bh::histogram& h) { br::mt19937 gen; br::normal_distribution<> norm; // fill histogram diff --git a/include/boost/histogram/any_axis.hpp b/include/boost/histogram/any_axis.hpp deleted file mode 100644 index 0f76dcb5..00000000 --- a/include/boost/histogram/any_axis.hpp +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright 2015-2016 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_ANY_AXIS_HPP_ -#define _BOOST_HISTOGRAM_ANY_AXIS_HPP_ - -#include -#include -#include -#include -#include - -namespace boost { -namespace histogram { - -/// Polymorphic axis type -template -class any_axis : public make_variant_over::type { -public: - using base_type = typename make_variant_over::type; - any_axis() = default; - any_axis(const any_axis& t) = default; - any_axis(any_axis&& t) = default; - any_axis& operator=(const any_axis& t) = default; - any_axis& operator=(any_axis&& t) = default; - - template ::value - >::type> - any_axis(const T& t) : base_type(t) {} - - template ::value - >::type> - any_axis& operator=(const T& t) { - // ugly workaround for compiler bug - return reinterpret_cast(base_type::operator=(t)); - } - - template ::value - >::type> - any_axis& operator=(T&& t) { - // ugly workaround for compiler bug - return reinterpret_cast(base_type::operator=(std::move(t))); - } - - int size() const { - return apply_visitor(detail::size(), *this); - } - - int shape() const { - return apply_visitor(detail::shape(), *this); - } - - bool uoflow() const { - return apply_visitor(detail::uoflow(), *this); - } - - // note: this only works for axes with compatible value type - int index(const double x) const { - return apply_visitor(detail::index(x), *this); - } - - string_view label() const { - return apply_visitor(detail::get_label(), *this); - } - - void label(const string_view x) { - return apply_visitor(detail::set_label(x), *this); - } - - // note: this only works for axes with compatible bin type - axis::interval operator[](const int i) const { - return apply_visitor(detail::bin(i), *this); - } - - bool operator==(const any_axis& rhs) const { - return base_type::operator==(static_cast(rhs)); - } -}; - -// dynamic casts -template -typename std::add_lvalue_reference::type axis_cast(any_axis& any) { return ::boost::get(any); } - -template -const typename std::add_lvalue_reference::type axis_cast(const any_axis& any) { return ::boost::get(any); } - -template -typename std::add_pointer::type axis_cast(any_axis* any) { return ::boost::get(&any); } - -template -const typename std::add_pointer::type axis_cast(const any_axis* any) { return ::boost::get(&any); } - -// pass-through versions for generic programming, i.e. when you switch to static histogram -template -typename std::add_lvalue_reference::type axis_cast(T& t) { return t; } - -template -const typename std::add_lvalue_reference::type axis_cast(const T& t) { return t; } - -template -typename std::add_pointer::type axis_cast(T* t) { return t; } - -template -const typename std::add_pointer::type axis_cast(const T* t) { return t; } - -} -} - -#endif diff --git a/include/boost/histogram/axis.hpp b/include/boost/histogram/axis.hpp index f3b58b7c..7d4927a0 100644 --- a/include/boost/histogram/axis.hpp +++ b/include/boost/histogram/axis.hpp @@ -9,11 +9,14 @@ #include #include +#include #include #include #include #include #include +#include +#include #include #include #include @@ -238,7 +241,7 @@ struct pow { * The most common binning strategy. * Very fast. Binning is a O(1) operation. */ -template +template class regular : public axis_base_uoflow, Transform { public: using value_type = RealType; @@ -321,7 +324,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; @@ -385,7 +388,7 @@ private: * Binning is a O(log(N)) operation. If speed matters and the problem * domain allows it, prefer a regular axis, possibly with a transform. */ -template class variable : public axis_base_uoflow { +template class variable : public axis_base_uoflow { public: using value_type = RealType; using bin_type = interval; @@ -475,7 +478,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; @@ -544,7 +547,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: @@ -620,16 +623,168 @@ private: template void serialize(Archive &, unsigned); }; +namespace detail { +struct size : public static_visitor { + template int operator()(const A &a) const { return a.size(); } +}; + +struct shape : public static_visitor { + template int operator()(const A &a) const { return a.shape(); } +}; + +struct uoflow : public static_visitor { + template bool operator()(const A &a) const { return a.uoflow(); } +}; + +struct get_label : public static_visitor { + template ::boost::string_view operator()(const A& a) const { return a.label(); } +}; + +struct set_label : public static_visitor { + const ::boost::string_view label; + set_label(const ::boost::string_view x) : label(x) {} + template void operator()(A& a) const { a.label(label); } +}; + +template struct index : public static_visitor { + const T &t; + explicit index(const T &arg) : t(arg) {} + template int operator()(const Axis &a) const { + return impl(std::is_convertible(), a); + } + template int impl(std::true_type, const Axis& a) const { + return a.index(t); + } + template int impl(std::false_type, const Axis&) const { + throw std::runtime_error("index argument not convertible to axis value type"); + } +}; + +struct bin : public static_visitor> { + using double_interval = axis::interval; + const int i; + bin(const int v) : i(v) {} + template double_interval operator()(const A &a) const { + return impl(is_convertible(), + std::forward(a[i])); + } + template double_interval impl(true_type, B &&b) const { + return b; + } + template double_interval impl(false_type, B &&) const { + throw std::runtime_error("cannot convert bin_type to interval"); + } +}; +} // namespace detail + +/// Polymorphic axis type +template +class any : public make_variant_over::type { + using base_type = typename make_variant_over::type; +public: + using types = typename base_type::types; + using value_type = double; + using bin_type = interval; + using const_iterator = axis_iterator; + + any() = default; + any(const any& t) = default; + any(any&& t) = default; + any& operator=(const any& t) = default; + any& operator=(any&& t) = default; + + template ::value + >::type> + any(const T& t) : base_type(t) {} + + template ::value + >::type> + any& operator=(const T& t) { + // ugly workaround for compiler bug + return reinterpret_cast(base_type::operator=(t)); + } + + template ::value + >::type> + any& operator=(T&& t) { + // ugly workaround for compiler bug + return reinterpret_cast(base_type::operator=(std::move(t))); + } + + int size() const { + return apply_visitor(detail::size(), *this); + } + + int shape() const { + return apply_visitor(detail::shape(), *this); + } + + bool uoflow() const { + return apply_visitor(detail::uoflow(), *this); + } + + // note: this only works for axes with compatible value type + int index(const value_type x) const { + return apply_visitor(detail::index(x), *this); + } + + string_view label() const { + return apply_visitor(detail::get_label(), *this); + } + + void label(const string_view x) { + return apply_visitor(detail::set_label(x), *this); + } + + // this only works for axes with compatible bin type + // and will raise an error otherwise + bin_type operator[](const int i) const { + return apply_visitor(detail::bin(i), *this); + } + + bool operator==(const any& rhs) const { + return base_type::operator==(static_cast(rhs)); + } + + const_iterator begin() const { return const_iterator(*this, 0); } + + const_iterator end() const { return const_iterator(*this, size()); } + +private: + friend class ::boost::serialization::access; + template void serialize(Archive&, unsigned); +}; + +// dynamic casts +template +typename std::add_lvalue_reference::type cast(any& any) { return get(any); } + +template +const typename std::add_lvalue_reference::type cast(const any& any) { return get(any); } + +template +typename std::add_pointer::type cast(any* any) { return get(&any); } + +template +const typename std::add_pointer::type cast(const any* any) { return get(&any); } + +// pass-through versions for generic programming, i.e. when you switch to static histogram +template +typename std::add_lvalue_reference::type cast(T& t) { return t; } + +template +const typename std::add_lvalue_reference::type cast(const T& t) { return t; } + +template +typename std::add_pointer::type cast(T* t) { return t; } + +template +const typename std::add_pointer::type cast(const T* t) { return t; } + } // namespace axis - -using builtin_axes = - mpl::vector, axis::regular, - axis::regular, - axis::regular, - axis::regular, axis::circular<>, - axis::variable<>, axis::integer<>, - axis::category<>, axis::category>; - } // namespace histogram } // namespace boost diff --git a/include/boost/histogram/detail/axis_visitor.hpp b/include/boost/histogram/detail/axis_visitor.hpp index 313ce257..bfafc681 100644 --- a/include/boost/histogram/detail/axis_visitor.hpp +++ b/include/boost/histogram/detail/axis_visitor.hpp @@ -26,58 +26,6 @@ namespace boost { namespace histogram { namespace detail { -struct size : public static_visitor { - template int operator()(const A &a) const { return a.size(); } -}; - -struct shape : public static_visitor { - template int operator()(const A &a) const { return a.shape(); } -}; - -struct uoflow : public static_visitor { - template bool operator()(const A &a) const { return a.uoflow(); } -}; - -struct get_label : public static_visitor { - template ::boost::string_view operator()(const A& a) const { return a.label(); } -}; - -struct set_label : public static_visitor { - const ::boost::string_view label; - set_label(const ::boost::string_view x) : label(x) {} - template void operator()(A& a) const { a.label(label); } -}; - -template struct index : public static_visitor { - const T &t; - explicit index(const T &arg) : t(arg) {} - template int operator()(const Axis &a) const { - return impl(std::is_convertible(), a); - } - template int impl(std::true_type, const Axis& a) const { - return a.index(t); - } - template int impl(std::false_type, const Axis&) const { - throw std::runtime_error("index argument not convertible to axis value type"); - } -}; - -struct bin : public static_visitor> { - using double_interval = axis::interval; - const int i; - bin(const int v) : i(v) {} - template double_interval operator()(const A &a) const { - return impl(is_convertible(), - std::forward(a[i])); - } - template double_interval impl(true_type, B &&b) const { - return b; - } - template double_interval impl(false_type, B &&) const { - throw std::runtime_error("cannot convert bin_type to interval"); - } -}; - template struct cmp_axis : public static_visitor { const V &lhs; cmp_axis(const V &v) : lhs(v) {} diff --git a/include/boost/histogram/histogram_fwd.hpp b/include/boost/histogram/histogram_fwd.hpp index 71f36038..5f373ca2 100644 --- a/include/boost/histogram/histogram_fwd.hpp +++ b/include/boost/histogram/histogram_fwd.hpp @@ -20,6 +20,31 @@ using Dynamic = std::integral_constant; class adaptive_storage; +namespace axis { + +namespace transform { + struct identity; + struct log; + struct sqrt; + struct cos; + struct pow; +} + +template class regular; +template class circular; +template class variable; +template class integer; +template class category; + +using builtins = + mpl::vector, axis::regular, + axis::regular, + axis::regular, + axis::regular, axis::circular<>, + axis::variable<>, axis::integer<>, + axis::category<>, axis::category>; +} + template class histogram; diff --git a/include/boost/histogram/histogram_impl_dynamic.hpp b/include/boost/histogram/histogram_impl_dynamic.hpp index cc1a9040..a1e3220f 100644 --- a/include/boost/histogram/histogram_impl_dynamic.hpp +++ b/include/boost/histogram/histogram_impl_dynamic.hpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -48,7 +47,7 @@ template class histogram { static_assert(!mpl::empty::value, "at least one axis required"); public: - using any_axis_type = any_axis; + using any_axis_type = axis::any; using value_type = typename Storage::value_type; private: @@ -407,7 +406,7 @@ private: for (const auto &bi : b) { if (bi) axes.emplace_back(*axes_iter); - *n_iter = apply_visitor(detail::shape(), *axes_iter); + *n_iter = axes_iter->shape(); ++axes_iter; ++n_iter; } @@ -446,23 +445,39 @@ private: }; template -inline histogram>> +histogram>> make_dynamic_histogram(Axes &&... axes) { return histogram>>( + detail::combine_t>>( std::forward(axes)...); } template -inline histogram>, +histogram>, Storage> make_dynamic_histogram_with(Axes &&... axes) { return histogram< - Dynamic, detail::combine_t>, Storage>( + Dynamic, detail::combine_t>, Storage>( std::forward(axes)...); } +template > +histogram> +make_dynamic_histogram(Iterator begin, Iterator end) { + return histogram< + Dynamic, detail::combine_t>( + begin, end); +} + +template > +histogram, Storage> +make_dynamic_histogram_with(Iterator begin, Iterator end) { + return histogram< + Dynamic, detail::combine_t, Storage>( + begin, end); +} + } // namespace histogram } // namespace boost diff --git a/include/boost/histogram/serialization.hpp b/include/boost/histogram/serialization.hpp index ee5759bb..21f2d1ab 100644 --- a/include/boost/histogram/serialization.hpp +++ b/include/boost/histogram/serialization.hpp @@ -182,6 +182,12 @@ void category::serialize(Archive &ar, unsigned /* version */) { ar &map_; } +template +template +void any::serialize(Archive &ar, unsigned /* version */) { + ar &boost::serialization::base_object(*this); +} + } // namespace axis template @@ -192,11 +198,6 @@ void histogram::serialize(Archive &ar, unsigned /* version */) { ar &storage_; } -template -void serialize(Archive &ar, any_axis& a, unsigned /* version */) { - ar &boost::serialization::base_object::base_type>(a); -} - template template void histogram::serialize(Archive &ar, unsigned /* version */) { diff --git a/src/python/histogram.cpp b/src/python/histogram.cpp index 96e447aa..a3e7d0a1 100644 --- a/src/python/histogram.cpp +++ b/src/python/histogram.cpp @@ -28,7 +28,7 @@ namespace np = boost::python::numpy; namespace boost { namespace histogram { -using dynamic_histogram = histogram; +using dynamic_histogram = histogram; } // namespace histogram namespace python { diff --git a/test/axis_size.cpp b/test/axis_size.cpp index a64ab95a..dcd16d1f 100644 --- a/test/axis_size.cpp +++ b/test/axis_size.cpp @@ -10,7 +10,7 @@ namespace boost { namespace histogram { using axis_variant = - typename make_variant_over::type; + typename make_variant_over::type; }} int main() { diff --git a/test/axis_test.cpp b/test/axis_test.cpp index 87e9cdd4..891439f1 100644 --- a/test/axis_test.cpp +++ b/test/axis_test.cpp @@ -43,7 +43,7 @@ void test_axis_iterator(const Axis &a, int begin, int end) { int main() { using namespace boost::histogram; - using axis_t = typename boost::make_variant_over::type; + using any_axis_type = axis::any<>; // bad_ctors { @@ -231,33 +231,33 @@ int main() { test_axis_iterator(axis::category<>({A, B, C}, ""), 0, 3); } - // axis_t_copyable + // any_axis_type_copyable { - axis_t a(axis::regular<>(2, -1, 1)); - axis_t b(a); + any_axis_type a(axis::regular<>(2, -1, 1)); + any_axis_type b(a); BOOST_TEST(a == b); - axis_t c; + any_axis_type c; BOOST_TEST_NOT(a == c); c = a; BOOST_TEST(a == c); } - // axis_t_movable + // any_axis_type_movable { - axis_t a(axis::regular<>(2, -1, 1)); - axis_t r(a); - axis_t b(std::move(a)); - BOOST_TEST(b == r); - axis_t c; + any_axis_type a(axis::regular<>(2, -1, 1)); + any_axis_type r(a); + any_axis_type b(std::move(a)); + BOOST_TEST_EQ(b, r); + any_axis_type c; BOOST_TEST_NOT(a == c); c = std::move(b); BOOST_TEST(c == r); } - // axis_t_streamable + // any_axis_type_streamable { enum { A, B, C }; - std::vector axes; + std::vector axes; axes.push_back(axis::regular<>{2, -1, 1, "regular1"}); axes.push_back(axis::regular{ 2, 1, 10, "regular2", axis::uoflow::off}); @@ -282,21 +282,21 @@ int main() { BOOST_TEST_EQ(os.str(), ref); } - // axis_t_equal_comparable + // any_axis_type_equal_comparable { enum { A, B, C }; - std::vector axes; + std::vector axes; axes.push_back(axis::regular<>{2, -1, 1}); axes.push_back(axis::circular<>{4}); axes.push_back(axis::variable<>{-1, 0, 1}); axes.push_back(axis::category<>{A, B, C}); axes.push_back(axis::integer<>{-1, 1}); for (const auto &a : axes) { - BOOST_TEST(!(a == axis_t())); + BOOST_TEST(!(a == any_axis_type())); BOOST_TEST_EQ(a, a); } - BOOST_TEST_NOT(axes == std::vector()); - BOOST_TEST(axes == std::vector(axes)); + BOOST_TEST_NOT(axes == std::vector()); + BOOST_TEST(axes == std::vector(axes)); } // sequence equality diff --git a/test/histogram_test.cpp b/test/histogram_test.cpp index 183386a7..eaed9b56 100644 --- a/test/histogram_test.cpp +++ b/test/histogram_test.cpp @@ -209,7 +209,7 @@ template void run_tests() { c.axis().label("foo"); BOOST_TEST_EQ(c.axis().label(), "foo"); // need to cast here for this to work with Type == Dynamic - auto ca = axis_cast>(c.axis()); + auto ca = axis::cast>(c.axis()); BOOST_TEST_EQ(ca[0], A); } @@ -778,10 +778,10 @@ int main() { // init { - auto v = std::vector::any_axis_type>(); + auto v = std::vector>(); v.push_back(axis::regular<>(100, -1, 1)); v.push_back(axis::integer<>(1, 7)); - auto h = histogram(v.begin(), v.end()); + auto h = histogram(v.begin(), v.end()); BOOST_TEST_EQ(h.axis(0_c), v[0]); BOOST_TEST_EQ(h.axis(1_c), v[1]); BOOST_TEST_EQ(h.axis(0), v[0]); diff --git a/test/speed_cpp.cpp b/test/speed_cpp.cpp index 43f73cdc..1f3c587f 100644 --- a/test/speed_cpp.cpp +++ b/test/speed_cpp.cpp @@ -115,11 +115,11 @@ int main() { compare_1d>, adaptive_storage>>(6000000, itype)); printf("hd_ss %.3f\n", - compare_1d>>( 6000000, itype)); printf("hd_sd %.3f\n", - compare_1d>( + compare_1d>( 6000000, itype)); } @@ -138,11 +138,11 @@ int main() { mpl::vector, axis::regular<>>, adaptive_storage>>(6000000, itype)); printf("hd_ss %.3f\n", - compare_2d>>( 6000000, itype)); printf("hd_sd %.3f\n", - compare_2d>( + compare_2d>( 6000000, itype)); } @@ -161,11 +161,11 @@ int main() { mpl::vector, axis::regular<>, axis::regular<>>, adaptive_storage>>(6000000, itype)); printf("hd_ss %.3f\n", - compare_3d>>( 6000000, itype)); printf("hd_sd %.3f\n", - compare_3d>( + compare_3d>( 6000000, itype)); } @@ -186,11 +186,11 @@ int main() { axis::regular<>, axis::regular<>, axis::regular<>>, adaptive_storage>>(6000000, itype)); printf("hd_ss %.3f\n", - compare_6d>>( 6000000, itype)); printf("hd_sd %.3f\n", - compare_6d>( + compare_6d>( 6000000, itype)); } }