From ef4898ddc2d65ed4656ad1e713316ea2925e2e05 Mon Sep 17 00:00:00 2001 From: Hans Dembinski Date: Sun, 4 Jun 2017 11:53:15 +0200 Subject: [PATCH] put axis in extra namespace, put python axis objects in axis submodule --- examples/dynamic_axes.cpp | 4 +- examples/example_1d.cpp | 2 +- examples/example_1d.py | 2 +- examples/example_2d.cpp | 4 +- examples/example_2d.py | 4 +- include/boost/histogram/axis.hpp | 121 +++--- .../histogram/axis_ostream_operators.hpp | 23 +- include/boost/histogram/serialization.hpp | 14 +- src/python/axis.cpp | 52 +-- src/python/histogram.cpp | 12 +- src/python/module.cpp | 13 +- test/axis_size.cpp | 10 +- test/axis_test.cpp | 184 +++++----- test/histogram_test.cpp | 158 ++++---- test/python_suite_test.py.in | 346 +++++++++--------- 15 files changed, 486 insertions(+), 463 deletions(-) diff --git a/examples/dynamic_axes.cpp b/examples/dynamic_axes.cpp index fe8a298f..49127ba4 100644 --- a/examples/dynamic_axes.cpp +++ b/examples/dynamic_axes.cpp @@ -6,8 +6,8 @@ namespace bh = boost::histogram; int main() { using dhist = decltype(bh::make_dynamic_histogram()); auto v = std::vector(); - v.push_back(bh::regular_axis<>(100, -1, 1)); - v.push_back(bh::integer_axis(1, 6)); + v.push_back(bh::axis::regular<>(100, -1, 1)); + v.push_back(bh::axis::integer(1, 6)); auto h = dhist(v.begin(), v.end()); // do something with h } diff --git a/examples/example_1d.cpp b/examples/example_1d.cpp index 2ddbbe8b..a7e887d1 100644 --- a/examples/example_1d.cpp +++ b/examples/example_1d.cpp @@ -8,7 +8,7 @@ int main(int, char**) { // create 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::regular_axis<>(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/example_1d.py b/examples/example_1d.py index 38ec73e6..11d49667 100644 --- a/examples/example_1d.py +++ b/examples/example_1d.py @@ -2,7 +2,7 @@ import histogram as hg import numpy as np import matplotlib.pyplot as plt -h = hg.histogram(hg.regular_axis(10, -3, 3)) +h = hg.histogram(hg.axis.regular(10, -3, 3)) h.fill(np.random.randn(1000)) bins = h.axis(0).bins diff --git a/examples/example_2d.cpp b/examples/example_2d.cpp index b28d1e12..7ff1e4ae 100644 --- a/examples/example_2d.cpp +++ b/examples/example_2d.cpp @@ -7,8 +7,8 @@ int main() { random::mt19937 gen; random::normal_distribution<> norm; auto h = histogram::make_static_histogram( - histogram::regular_axis<>(100, -5, 5, "x"), - histogram::regular_axis<>(100, -5, 5, "y") + histogram::axis::regular<>(100, -5, 5, "x"), + histogram::axis::regular<>(100, -5, 5, "y") ); for (int i = 0; i < 1000; ++i) h.fill(norm(gen), norm(gen)); diff --git a/examples/example_2d.py b/examples/example_2d.py index b2e98e1b..b11691c6 100644 --- a/examples/example_2d.py +++ b/examples/example_2d.py @@ -2,8 +2,8 @@ import histogram as hg import numpy as np import matplotlib.pyplot as plt -h = hg.histogram(hg.regular_axis(10, -3, 3, uoflow=False), - hg.regular_axis(10, -3, 3, uoflow=False)) +h = hg.histogram(hg.axis.regular(10, -3, 3, uoflow=False), + hg.axis.regular(10, -3, 3, uoflow=False)) xy = np.random.randn(2000).reshape((1000, 2)) xy[:,1] *= 0.5 h.fill(xy) diff --git a/include/boost/histogram/axis.hpp b/include/boost/histogram/axis.hpp index f326ac56..c534f3fa 100644 --- a/include/boost/histogram/axis.hpp +++ b/include/boost/histogram/axis.hpp @@ -36,6 +36,7 @@ class access; namespace boost { namespace histogram { +namespace axis { template struct bin { int idx; @@ -220,11 +221,11 @@ template struct sqrt { */ template class Transform = transform::identity> -class regular_axis : public axis_base, - boost::operators> { +class regular : public axis_base, + boost::operators> { public: using value_type = RealType; - using const_iterator = axis_iterator; + using const_iterator = axis_iterator; /** Construct axis with n bins over range [min, max). * @@ -234,7 +235,7 @@ public: * \param label description of the axis. * \param uoflow whether to add under-/overflow bins. */ - regular_axis(unsigned n, value_type min, value_type max, + regular(unsigned n, value_type min, value_type max, const std::string &label = std::string(), bool uoflow = true) : axis_base(n, label, uoflow), min_(Transform::forward(min)), @@ -244,11 +245,11 @@ public: } } - regular_axis() = default; - regular_axis(const regular_axis &) = default; - regular_axis &operator=(const regular_axis &) = default; - regular_axis(regular_axis &&) = default; - regular_axis &operator=(regular_axis &&) = default; + regular() = default; + regular(const regular &) = default; + regular &operator=(const regular &) = default; + regular(regular &&) = default; + regular &operator=(regular &&) = default; /// Returns the bin index for the passed argument. inline int index(value_type x) const noexcept { @@ -272,7 +273,7 @@ public: z * (min_ + delta_ * bins())); } - bool operator==(const regular_axis &o) const { + bool operator==(const regular &o) const { return axis_base::operator==(o) && min_ == o.min_ && delta_ == o.delta_; } @@ -299,11 +300,11 @@ private: * bins for this axis. Binning is a O(1) operation. */ template -class circular_axis : public axis_base, - boost::operators> { +class circular : public axis_base, + boost::operators> { public: using value_type = RealType; - using const_iterator = axis_iterator; + using const_iterator = axis_iterator; /** Constructor for n bins with an optional offset. * @@ -312,16 +313,16 @@ public: * \param perimeter range after which value wraps around. * \param label description of the axis. */ - explicit circular_axis(unsigned n, value_type phase = 0.0, + explicit circular(unsigned n, value_type phase = 0.0, value_type perimeter = math::double_constants::two_pi, const std::string &label = std::string()) : axis_base(n, label), phase_(phase), perimeter_(perimeter) {} - circular_axis() = default; - circular_axis(const circular_axis &) = default; - circular_axis &operator=(const circular_axis &) = default; - circular_axis(circular_axis &&) = default; - circular_axis &operator=(circular_axis &&) = default; + circular() = default; + circular(const circular &) = default; + circular &operator=(const circular &) = default; + circular(circular &&) = default; + circular &operator=(circular &&) = default; /// Returns the bin index for the passed argument. inline int index(value_type x) const noexcept { @@ -336,7 +337,7 @@ public: return z * perimeter_ + phase_; } - bool operator==(const circular_axis &o) const { + bool operator==(const circular &o) const { return axis_base::operator==(o) && phase_ == o.phase_ && perimeter_ == o.perimeter_; } @@ -358,14 +359,14 @@ private: /** An axis for real-valued data and bins of varying width. * * Binning is a O(log(N)) operation. If speed matters - * and the problem domain allows it, prefer a regular_axis. + * and the problem domain allows it, prefer a regular. */ template -class variable_axis : public axis_base, - boost::operators> { +class variable : public axis_base, + boost::operators> { public: using value_type = RealType; - using const_iterator = axis_iterator; + using const_iterator = axis_iterator; /** Construct an axis from bin edges. * @@ -373,7 +374,7 @@ public: * \param label description of the axis. * \param uoflow whether to add under-/overflow bins. */ - variable_axis(const std::initializer_list &x, + variable(const std::initializer_list &x, const std::string &label = std::string(), bool uoflow = true) : axis_base(x.size() - 1, label, uoflow), x_(new value_type[x.size()]) { @@ -385,7 +386,7 @@ public: } template - variable_axis(Iterator begin, Iterator end, + variable(Iterator begin, Iterator end, const std::string &label = std::string(), bool uoflow = true) : axis_base(std::distance(begin, end) - 1, label, uoflow), x_(new value_type[std::distance(begin, end)]) { @@ -393,12 +394,12 @@ public: std::sort(x_.get(), x_.get() + bins() + 1); } - variable_axis() = default; - variable_axis(const variable_axis &o) + variable() = default; + variable(const variable &o) : axis_base(o), x_(new value_type[bins() + 1]) { std::copy(o.x_.get(), o.x_.get() + bins() + 1, x_.get()); } - variable_axis &operator=(const variable_axis &o) { + variable &operator=(const variable &o) { if (this != &o) { axis_base::operator=(o); x_.reset(new value_type[bins() + 1]); @@ -406,8 +407,8 @@ public: } return *this; } - variable_axis(variable_axis &&) = default; - variable_axis &operator=(variable_axis &&) = default; + variable(variable &&) = default; + variable &operator=(variable &&) = default; /// Returns the bin index for the passed argument. inline int index(value_type x) const noexcept { @@ -425,7 +426,7 @@ public: return x_[idx]; } - bool operator==(const variable_axis &o) const { + bool operator==(const variable &o) const { if (!axis_base::operator==(o)) { return false; } @@ -450,19 +451,19 @@ private: /** An axis for a contiguous range of integers. * * Binning is a O(1) operation. This axis operates - * faster than a regular_axis. + * faster than a regular. */ -class integer_axis : public axis_base, boost::operators { +class integer : public axis_base, boost::operators { public: using value_type = int; - using const_iterator = axis_iterator; + using const_iterator = axis_iterator; /** Construct axis over integer range [min, max]. * * \param min smallest integer of the covered range. * \param max largest integer of the covered range. */ - integer_axis(value_type min, value_type max, + integer(value_type min, value_type max, const std::string &label = std::string(), bool uoflow = true) : axis_base(max + 1 - min, label, uoflow), min_(min) { if (min > max) { @@ -470,11 +471,11 @@ public: } } - integer_axis() = default; - integer_axis(const integer_axis &) = default; - integer_axis &operator=(const integer_axis &) = default; - integer_axis(integer_axis &&) = default; - integer_axis &operator=(integer_axis &&) = default; + integer() = default; + integer(const integer &) = default; + integer &operator=(const integer &) = default; + integer(integer &&) = default; + integer &operator=(integer &&) = default; /// Returns the bin index for the passed argument. inline int index(value_type x) const noexcept { @@ -485,7 +486,7 @@ public: /// Returns the integer that is mapped to the bin index. value_type operator[](int idx) const { return min_ + idx; } - bool operator==(const integer_axis &o) const { + bool operator==(const integer &o) const { return axis_base::operator==(o) && min_ == o.min_; } @@ -511,13 +512,13 @@ private: * There are no underflow/overflow bins for this axis. * Binning is a O(1) operation. */ -class category_axis : public axis_base, boost::operators { +class category : public axis_base, boost::operators { public: using value_type = BOOST_HISTOGRAM_STRING_VIEW; - using const_iterator = axis_iterator; + using const_iterator = axis_iterator; template - category_axis(Iterator begin, Iterator end, + category(Iterator begin, Iterator end, const std::string &label = std::string()) : axis_base(std::distance(begin, end), label), ptr_(new std::string[bins()]) { @@ -528,16 +529,16 @@ public: * * \param categories sequence of labeled categories. */ - category_axis(const std::initializer_list &categories, + category(const std::initializer_list &categories, const std::string &label = std::string()) - : category_axis(categories.begin(), categories.end(), label) {} + : category(categories.begin(), categories.end(), label) {} - category_axis() = default; + category() = default; - category_axis(const category_axis &other) - : category_axis(other.ptr_.get(), other.ptr_.get() + other.bins(), + category(const category &other) + : category(other.ptr_.get(), other.ptr_.get() + other.bins(), other.label()) {} - category_axis &operator=(const category_axis &other) { + category &operator=(const category &other) { if (this != &other) { axis_base::operator=(other); ptr_.reset(new std::string[other.bins()]); @@ -546,10 +547,10 @@ public: return *this; } - category_axis(category_axis &&other) + category(category &&other) : axis_base(std::move(other)), ptr_(std::move(other.ptr_)) {} - category_axis &operator=(category_axis &&other) { + category &operator=(category &&other) { if (this != &other) { axis_base::operator=(std::move(other)); ptr_ = std::move(other.ptr_); @@ -571,7 +572,7 @@ public: return ptr_.get()[idx]; } - bool operator==(const category_axis &other) const { + bool operator==(const category &other) const { return axis_base::operator==(other) && std::equal(ptr_.get(), ptr_.get() + bins(), other.ptr_.get()); } @@ -587,10 +588,14 @@ private: template void serialize(Archive &, unsigned); }; -using builtin_axes = mpl::vector, regular_axis, - circular_axis, circular_axis, - variable_axis, variable_axis, - integer_axis, category_axis>::type; +} // namespace axis + +using builtin_axes = mpl::vector, + axis::circular, + axis::variable, + axis::integer, + axis::category>; + } // namespace histogram } // namespace boost diff --git a/include/boost/histogram/axis_ostream_operators.hpp b/include/boost/histogram/axis_ostream_operators.hpp index da9addf8..15322335 100644 --- a/include/boost/histogram/axis_ostream_operators.hpp +++ b/include/boost/histogram/axis_ostream_operators.hpp @@ -14,11 +14,12 @@ namespace boost { namespace histogram { +namespace axis { template inline std::ostream &operator<<(std::ostream &os, - const regular_axis &a) { - os << "regular_axis(" << a.bins() << ", " << a[0] << ", " << a[a.bins()]; + const regular &a) { + os << "regular(" << a.bins() << ", " << a[0] << ", " << a[a.bins()]; if (!a.label().empty()) { os << ", label="; detail::escape(os, a.label()); @@ -32,8 +33,8 @@ inline std::ostream &operator<<(std::ostream &os, template inline std::ostream &operator<<(std::ostream &os, - const circular_axis &a) { - os << "circular_axis(" << a.bins(); + const circular &a) { + os << "circular(" << a.bins(); if (a.phase() != 0.0) { os << ", phase=" << a.phase(); } @@ -50,8 +51,8 @@ inline std::ostream &operator<<(std::ostream &os, template inline std::ostream &operator<<(std::ostream &os, - const variable_axis &a) { - os << "variable_axis(" << a[0]; + const variable &a) { + os << "variable(" << a[0]; for (int i = 1; i <= a.bins(); ++i) { os << ", " << a[i]; } @@ -66,8 +67,8 @@ inline std::ostream &operator<<(std::ostream &os, return os; } -inline std::ostream &operator<<(std::ostream &os, const integer_axis &a) { - os << "integer_axis(" << a[0] << ", " << a[a.bins() - 1]; +inline std::ostream &operator<<(std::ostream &os, const integer &a) { + os << "integer(" << a[0] << ", " << a[a.bins() - 1]; if (!a.label().empty()) { os << ", label="; detail::escape(os, a.label()); @@ -79,8 +80,8 @@ inline std::ostream &operator<<(std::ostream &os, const integer_axis &a) { return os; } -inline std::ostream &operator<<(std::ostream &os, const category_axis &a) { - os << "category_axis("; +inline std::ostream &operator<<(std::ostream &os, const category &a) { + os << "category("; for (int i = 0; i < a.bins(); ++i) { detail::escape(os, a[i]); os << (i == (a.bins() - 1) ? "" : ", "); @@ -92,6 +93,8 @@ inline std::ostream &operator<<(std::ostream &os, const category_axis &a) { os << ")"; return os; } + +} // namespace axis } // namespace histogram } // namespace boost diff --git a/include/boost/histogram/serialization.hpp b/include/boost/histogram/serialization.hpp index 3711fc2e..868754d7 100644 --- a/include/boost/histogram/serialization.hpp +++ b/include/boost/histogram/serialization.hpp @@ -117,6 +117,8 @@ void adaptive_storage::serialize(Archive &ar, } } +namespace axis { + template void axis_base::serialize(Archive &ar, unsigned /* version */) { ar &size_; @@ -132,7 +134,7 @@ void axis_base::serialize(Archive &ar, unsigned /* version */) { template class Transform> template -void regular_axis::serialize(Archive &ar, +void regular::serialize(Archive &ar, unsigned /* version */) { ar &boost::serialization::base_object>(*this); ar &min_; @@ -141,7 +143,7 @@ void regular_axis::serialize(Archive &ar, template template -void circular_axis::serialize(Archive &ar, unsigned /* version */) { +void circular::serialize(Archive &ar, unsigned /* version */) { ar &boost::serialization::base_object>(*this); ar &phase_; ar &perimeter_; @@ -149,7 +151,7 @@ void circular_axis::serialize(Archive &ar, unsigned /* version */) { template template -void variable_axis::serialize(Archive &ar, unsigned /* version */) { +void variable::serialize(Archive &ar, unsigned /* version */) { ar &boost::serialization::base_object>(*this); if (Archive::is_loading::value) { x_.reset(new RealType[bins() + 1]); @@ -158,13 +160,13 @@ void variable_axis::serialize(Archive &ar, unsigned /* version */) { } template -void integer_axis::serialize(Archive &ar, unsigned /* version */) { +void integer::serialize(Archive &ar, unsigned /* version */) { ar &boost::serialization::base_object>(*this); ar &min_; } template -void category_axis::serialize(Archive &ar, unsigned /* version */) { +void category::serialize(Archive &ar, unsigned /* version */) { ar &boost::serialization::base_object>(*this); if (Archive::is_loading::value) { ptr_.reset(new std::string[bins()]); @@ -172,6 +174,8 @@ void category_axis::serialize(Archive &ar, unsigned /* version */) { ar &boost::serialization::make_array(ptr_.get(), bins()); } +} // namespace axis + template template void histogram::serialize(Archive &ar, unsigned /* version */) { diff --git a/src/python/axis.cpp b/src/python/axis.cpp index 7bdab51a..2d1a9380 100644 --- a/src/python/axis.cpp +++ b/src/python/axis.cpp @@ -20,7 +20,7 @@ namespace histogram { namespace { -python::object variable_axis_init(python::tuple args, python::dict kwargs) { +python::object variable_init(python::tuple args, python::dict kwargs) { using namespace python; object self = args[0]; @@ -54,10 +54,10 @@ python::object variable_axis_init(python::tuple args, python::dict kwargs) { } return self.attr("__init__")( - variable_axis<>(v.begin(), v.end(), label, uoflow)); + axis::variable<>(v.begin(), v.end(), label, uoflow)); } -python::object category_axis_init(python::tuple args, python::dict kwargs) { +python::object category_init(python::tuple args, python::dict kwargs) { using namespace python; object self = args[0]; @@ -86,7 +86,7 @@ python::object category_axis_init(python::tuple args, python::dict kwargs) { for (int i = 1, n = len(args); i < n; ++i) c.push_back(extract(args[i])); - return self.attr("__init__")(category_axis(c.begin(), c.end(), label)); + return self.attr("__init__")(axis::category(c.begin(), c.end(), label)); } template int axis_len(const T &t) { @@ -101,12 +101,12 @@ template python::object axis_getitem(const T &t, int i) { return python::object(t[i]); } -template <> python::object axis_getitem(const category_axis &t, int i) { - if (i == axis_len(t)) { +template <> python::object axis_getitem(const axis::category &a, int i) { + if (i == axis_len(a)) { PyErr_SetString(PyExc_StopIteration, "no more"); python::throw_error_already_set(); } - return python::object(t[i].data()); + return python::object(a[i].data()); } template std::string axis_repr(const T &t) { @@ -135,9 +135,9 @@ struct axis_suite : public python::def_visitor> { cl.def("__len__", axis_len, ":returns: number of bins for this axis", python::arg("self")); cl.def("__getitem__", axis_getitem, - is_same::value + is_same::value ? ":returns: integer mapped to passed bin index" - : is_same::value + : is_same::value ? ":returns: category mapped to passed bin index" : ":returns: low edge of the bin", python::args("self", "index")); @@ -154,17 +154,17 @@ void register_axis_types() { using python::arg; docstring_options dopt(true, true, false); - class_>("regular_axis", + class_>("regular", "An axis for real-valued data and bins of equal width." "\nBinning is a O(1) operation.", no_init) .def(init( (arg("self"), arg("bin"), arg("min"), arg("max"), arg("label") = std::string(), arg("uoflow") = true))) - .def(axis_suite>()); + .def(axis_suite>()); - class_>( - "circular_axis", + class_>( + "circular", "An axis for real-valued angles." "\nThere are no overflow/underflow bins for this axis," "\nsince the axis is circular and wraps around after reaching" @@ -174,19 +174,19 @@ void register_axis_types() { (arg("self"), arg("bin"), arg("phase") = 0.0, arg("perimeter") = math::double_constants::two_pi, arg("label") = std::string()))) - .def(axis_suite>()); + .def(axis_suite>()); - class_>( - "variable_axis", + class_>( + "variable", "An axis for real-valued data and bins of varying width." "\nBinning is a O(log(N)) operation. If speed matters and" - "\nthe problem domain allows it, prefer a regular_axis<>.", + "\nthe problem domain allows it, prefer a regular.", no_init) - .def("__init__", raw_function(variable_axis_init)) - .def(init &>()) - .def(axis_suite>()); + .def("__init__", raw_function(variable_init)) + .def(init &>()) + .def(axis_suite>()); - class_("integer_axis", + class_("integer", "An axis for a contiguous range of integers." "\nThere are no underflow/overflow bins for this axis." "\nBinning is a O(1) operation.", @@ -194,18 +194,18 @@ void register_axis_types() { .def(init( (arg("self"), arg("min"), arg("max"), arg("label") = std::string(), arg("uoflow") = true))) - .def(axis_suite()); + .def(axis_suite()); - class_("category_axis", + class_("category", "An axis for enumerated categories. The axis stores the" "\ncategory labels, and expects that they are addressed" "\nusing an integer from 0 to n-1. There are no" "\nunderflow/overflow bins for this axis." "\nBinning is a O(1) operation.", no_init) - .def("__init__", raw_function(category_axis_init)) - .def(init()) - .def(axis_suite()); + .def("__init__", raw_function(category_init)) + .def(init()) + .def(axis_suite()); } } } diff --git a/src/python/histogram.cpp b/src/python/histogram.cpp index de1730ac..7effac5e 100644 --- a/src/python/histogram.cpp +++ b/src/python/histogram.cpp @@ -137,7 +137,7 @@ public: shapes.append(2); } for (unsigned i = 0; i < self.dim(); ++i) { - const auto s = shape(self.axis(i)); + const auto s = histogram::shape(self.axis(i)); shapes.append(s); strides.append(stride); stride *= s; @@ -191,27 +191,27 @@ python::object histogram_init(python::tuple args, python::dict kwargs) { std::vector axes; for (unsigned i = 0; i < dim; ++i) { python::object pa = args[i + 1]; - python::extract> er(pa); + python::extract> er(pa); if (er.check()) { axes.push_back(er()); continue; } - python::extract> ep(pa); + python::extract> ep(pa); if (ep.check()) { axes.push_back(ep()); continue; } - python::extract> ev(pa); + python::extract> ev(pa); if (ev.check()) { axes.push_back(ev()); continue; } - python::extract ei(pa); + python::extract ei(pa); if (ei.check()) { axes.push_back(ei()); continue; } - python::extract ec(pa); + python::extract ec(pa); if (ec.check()) { axes.push_back(ec()); continue; diff --git a/src/python/module.cpp b/src/python/module.cpp index a62b08a4..69068b5e 100644 --- a/src/python/module.cpp +++ b/src/python/module.cpp @@ -5,6 +5,8 @@ // or copy at http://www.boost.org/LICENSE_1_0.txt) #include +#include +#include #ifdef HAVE_NUMPY #define PY_ARRAY_UNIQUE_SYMBOL boost_histogram_ARRAY_API #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION @@ -32,6 +34,15 @@ BOOST_PYTHON_MODULE(histogram) { #ifdef HAVE_NUMPY init_numpy(); #endif - boost::histogram::register_axis_types(); + using namespace boost::python; + scope current; + object axis_module = object( + borrowed(PyImport_AddModule("histogram.axis")) + ); + current.attr("axis") = axis_module; + { + scope scope = axis_module; + boost::histogram::register_axis_types(); + } boost::histogram::register_histogram(); } diff --git a/test/axis_size.cpp b/test/axis_size.cpp index 7fec1b3d..4b7c5596 100644 --- a/test/axis_size.cpp +++ b/test/axis_size.cpp @@ -11,9 +11,9 @@ int main() { #define SIZEOF(axis) \ std::cout << #axis << " " << sizeof(boost::histogram::axis) << std::endl - SIZEOF(regular_axis<>); - SIZEOF(circular_axis<>); - SIZEOF(variable_axis<>); - SIZEOF(integer_axis); - SIZEOF(category_axis); + SIZEOF(axis::regular<>); + SIZEOF(axis::circular<>); + SIZEOF(axis::variable<>); + SIZEOF(axis::integer); + SIZEOF(axis::category); } diff --git a/test/axis_test.cpp b/test/axis_test.cpp index c214177b..b14dee2d 100644 --- a/test/axis_test.cpp +++ b/test/axis_test.cpp @@ -24,8 +24,8 @@ template void test_real_axis_iterator(Axis &&a, int begin, int end) { for (const auto &bin : a) { BOOST_TEST_EQ(bin.idx, begin); - BOOST_TEST_EQ(bin.left, left(a, begin)); - BOOST_TEST_EQ(bin.right, right(a, begin)); + BOOST_TEST_EQ(bin.left, boost::histogram::left(a, begin)); + BOOST_TEST_EQ(bin.right, boost::histogram::right(a, begin)); ++begin; } BOOST_TEST_EQ(begin, end); @@ -47,30 +47,30 @@ int main() { // bad_ctors { - BOOST_TEST_THROWS(regular_axis<>(0, 0, 1), std::logic_error); - BOOST_TEST_THROWS(regular_axis<>(1, 1, -1), std::logic_error); - BOOST_TEST_THROWS(circular_axis<>(0), std::logic_error); - BOOST_TEST_THROWS(variable_axis<>({}), std::logic_error); - BOOST_TEST_THROWS(variable_axis<>({1.0}), std::logic_error); - BOOST_TEST_THROWS(integer_axis(1, -1), std::logic_error); - BOOST_TEST_THROWS(category_axis({}), std::logic_error); + BOOST_TEST_THROWS(axis::regular<>(0, 0, 1), std::logic_error); + BOOST_TEST_THROWS(axis::regular<>(1, 1, -1), std::logic_error); + BOOST_TEST_THROWS(axis::circular<>(0), std::logic_error); + BOOST_TEST_THROWS(axis::variable<>({}), std::logic_error); + BOOST_TEST_THROWS(axis::variable<>({1.0}), std::logic_error); + BOOST_TEST_THROWS(axis::integer(1, -1), std::logic_error); + BOOST_TEST_THROWS(axis::category({}), std::logic_error); } - // regular_axis + // axis::regular { - regular_axis<> a{4, -2, 2}; + axis::regular<> a{4, -2, 2}; BOOST_TEST_EQ(a[-1], -std::numeric_limits::infinity()); BOOST_TEST_EQ(a[a.bins() + 1], std::numeric_limits::infinity()); - regular_axis<> b; + axis::regular<> b; BOOST_TEST_NOT(a == b); b = a; BOOST_TEST_EQ(a, b); b = b; BOOST_TEST_EQ(a, b); - regular_axis<> c = std::move(b); + axis::regular<> c = std::move(b); BOOST_TEST(c == a); BOOST_TEST_NOT(b == a); - regular_axis<> d; + axis::regular<> d; BOOST_TEST_NOT(c == d); d = std::move(c); BOOST_TEST_EQ(d, a); @@ -87,9 +87,9 @@ int main() { BOOST_TEST_EQ(a.index(std::numeric_limits::quiet_NaN()), -1); } - // regular_axis with transform + // axis::regular with transform { - regular_axis b{2, 1e0, 1e2}; + axis::regular b{2, 1e0, 1e2}; BOOST_TEST_EQ(b[-1], 0.0); BOOST_TEST_IS_CLOSE(b[0], 1.0, 1e-9); BOOST_TEST_IS_CLOSE(b[1], 10.0, 1e-9); @@ -106,20 +106,20 @@ int main() { BOOST_TEST_EQ(b.index(std::numeric_limits::infinity()), 2); } - // circular_axis + // axis::circular { - circular_axis<> a{4}; + axis::circular<> a{4}; BOOST_TEST_EQ(a[-1], a[a.bins() - 1] - a.perimeter()); - circular_axis<> b; + axis::circular<> b; BOOST_TEST_NOT(a == b); b = a; BOOST_TEST_EQ(a, b); b = b; BOOST_TEST_EQ(a, b); - circular_axis<> c = std::move(b); + axis::circular<> c = std::move(b); BOOST_TEST(c == a); BOOST_TEST_NOT(b == a); - circular_axis<> d; + axis::circular<> d; BOOST_TEST_NOT(c == d); d = std::move(c); BOOST_TEST_EQ(d, a); @@ -134,25 +134,25 @@ int main() { BOOST_TEST_EQ(a.index(std::numeric_limits::quiet_NaN()), 0); } - // variable_axis + // axis::variable { - variable_axis<> a{-1, 0, 1}; + axis::variable<> a{-1, 0, 1}; BOOST_TEST_EQ(a[-1], -std::numeric_limits::infinity()); BOOST_TEST_EQ(a[a.bins() + 1], std::numeric_limits::infinity()); - variable_axis<> b; + axis::variable<> b; BOOST_TEST_NOT(a == b); b = a; BOOST_TEST_EQ(a, b); b = b; BOOST_TEST_EQ(a, b); - variable_axis<> c = std::move(b); + axis::variable<> c = std::move(b); BOOST_TEST(c == a); BOOST_TEST_NOT(b == a); - variable_axis<> d; + axis::variable<> d; BOOST_TEST_NOT(c == d); d = std::move(c); BOOST_TEST_EQ(d, a); - variable_axis<> e{-2, 0, 2}; + axis::variable<> e{-2, 0, 2}; BOOST_TEST_NOT(a == e); BOOST_TEST_EQ(a.index(-10.), -1); BOOST_TEST_EQ(a.index(-1.), 0); @@ -164,19 +164,19 @@ int main() { BOOST_TEST_EQ(a.index(std::numeric_limits::quiet_NaN()), 2); } - // integer_axis + // axis::integer { - integer_axis a{-1, 1}; - integer_axis b; + axis::integer a{-1, 1}; + axis::integer b; BOOST_TEST_NOT(a == b); b = a; BOOST_TEST_EQ(a, b); b = b; BOOST_TEST_EQ(a, b); - integer_axis c = std::move(b); + axis::integer c = std::move(b); BOOST_TEST(c == a); BOOST_TEST_NOT(b == a); - integer_axis d; + axis::integer d; BOOST_TEST_NOT(c == d); d = std::move(c); BOOST_TEST_EQ(d, a); @@ -189,19 +189,19 @@ int main() { BOOST_TEST_EQ(a.index(10), 3); } - // category_axis + // axis::category { - category_axis a{{"A", "B", "C"}}; - category_axis b; + axis::category a{{"A", "B", "C"}}; + axis::category b; BOOST_TEST_NOT(a == b); b = a; BOOST_TEST_EQ(a, b); b = b; BOOST_TEST_EQ(a, b); - category_axis c = std::move(b); + axis::category c = std::move(b); BOOST_TEST(c == a); BOOST_TEST_NOT(b == a); - category_axis d; + axis::category d; BOOST_TEST_NOT(c == d); d = std::move(c); BOOST_TEST_EQ(d, a); @@ -212,19 +212,19 @@ int main() { // iterators { - test_real_axis_iterator(regular_axis<>(5, 0, 1, "", false), 0, 5); - test_real_axis_iterator(regular_axis<>(5, 0, 1, "", true), -1, 6); - test_real_axis_iterator(circular_axis<>(5, 0, 1, ""), 0, 5); - test_real_axis_iterator(variable_axis<>({1, 2, 3}, "", false), 0, 2); - test_real_axis_iterator(variable_axis<>({1, 2, 3}, "", true), -1, 3); - test_axis_iterator(integer_axis(0, 4, "", false), 0, 5); - test_axis_iterator(integer_axis(0, 4, "", true), -1, 6); - test_axis_iterator(category_axis({"A", "B", "C"}), 0, 3); + test_real_axis_iterator(axis::regular<>(5, 0, 1, "", false), 0, 5); + test_real_axis_iterator(axis::regular<>(5, 0, 1, "", true), -1, 6); + test_real_axis_iterator(axis::circular<>(5, 0, 1, ""), 0, 5); + test_real_axis_iterator(axis::variable<>({1, 2, 3}, "", false), 0, 2); + test_real_axis_iterator(axis::variable<>({1, 2, 3}, "", true), -1, 3); + test_axis_iterator(axis::integer(0, 4, "", false), 0, 5); + test_axis_iterator(axis::integer(0, 4, "", true), -1, 6); + test_axis_iterator(axis::category({"A", "B", "C"}), 0, 3); } // axis_t_copyable { - axis_t a(regular_axis<>(2, -1, 1)); + axis_t a(axis::regular<>(2, -1, 1)); axis_t b(a); BOOST_TEST(a == b); axis_t c; @@ -235,7 +235,7 @@ int main() { // axis_t_movable { - axis_t a(regular_axis<>(2, -1, 1)); + axis_t a(axis::regular<>(2, -1, 1)); axis_t r(a); axis_t b(std::move(a)); BOOST_TEST(b == r); @@ -248,32 +248,32 @@ int main() { // axis_t_streamable { std::vector axes; - axes.push_back(regular_axis<>{2, -1, 1, "regular", false}); - axes.push_back(circular_axis<>{4, 0.1, 1.0, "polar"}); - axes.push_back(variable_axis<>{{-1, 0, 1}, "variable", false}); - axes.push_back(category_axis{{"A", "B", "C"}, "category"}); - axes.push_back(integer_axis{-1, 1, "integer", false}); + axes.push_back(axis::regular<>{2, -1, 1, "regular", false}); + axes.push_back(axis::circular<>{4, 0.1, 1.0, "polar"}); + axes.push_back(axis::variable<>{{-1, 0, 1}, "variable", false}); + axes.push_back(axis::category{{"A", "B", "C"}, "category"}); + axes.push_back(axis::integer{-1, 1, "integer", false}); std::ostringstream os; for (const auto &a : axes) { os << a; } const std::string ref = - "regular_axis(2, -1, 1, label='regular', uoflow=False)" - "circular_axis(4, phase=0.1, perimeter=1, label='polar')" - "variable_axis(-1, 0, 1, label='variable', uoflow=False)" - "category_axis('A', 'B', 'C', label='category')" - "integer_axis(-1, 1, label='integer', uoflow=False)"; + "regular(2, -1, 1, label='regular', uoflow=False)" + "circular(4, phase=0.1, perimeter=1, label='polar')" + "variable(-1, 0, 1, label='variable', uoflow=False)" + "category('A', 'B', 'C', label='category')" + "integer(-1, 1, label='integer', uoflow=False)"; BOOST_TEST_EQ(os.str(), ref); } // axis_t_equal_comparable { std::vector axes; - axes.push_back(regular_axis<>{2, -1, 1}); - axes.push_back(circular_axis<>{4}); - axes.push_back(variable_axis<>{-1, 0, 1}); - axes.push_back(category_axis{"A", "B", "C"}); - axes.push_back(integer_axis{-1, 1}); + 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_EQ(a, a); @@ -284,35 +284,35 @@ int main() { // sequence equality { - std::vector, variable_axis<>, category_axis, - integer_axis>> - std_vector1 = {regular_axis<>{2, -1, 1}, variable_axis<>{-1, 0, 1}, - category_axis{"A", "B", "C"}}; + std::vector, axis::variable<>, axis::category, + axis::integer>> + std_vector1 = {axis::regular<>{2, -1, 1}, axis::variable<>{-1, 0, 1}, + axis::category{"A", "B", "C"}}; - std::vector, variable_axis<>, category_axis>> - std_vector2 = {regular_axis<>{2, -1, 1}, variable_axis<>{-1, 0, 1}, - category_axis{"A", "B", "C"}}; + std::vector, axis::variable<>, axis::category>> + std_vector2 = {axis::regular<>{2, -1, 1}, axis::variable<>{-1, 0, 1}, + axis::category{"A", "B", "C"}}; - std::vector, variable_axis<>>> std_vector3 = { - variable_axis<>{-1, 0, 1}, regular_axis<>{2, -1, 1}}; + std::vector, axis::variable<>>> std_vector3 = { + axis::variable<>{-1, 0, 1}, axis::regular<>{2, -1, 1}}; - std::vector, regular_axis<>>> std_vector4 = { - regular_axis<>{2, -1, 1}, variable_axis<>{-1, 0, 1}}; + std::vector, axis::regular<>>> std_vector4 = { + axis::regular<>{2, -1, 1}, axis::variable<>{-1, 0, 1}}; BOOST_TEST(detail::axes_equal(std_vector1, std_vector2)); BOOST_TEST_NOT(detail::axes_equal(std_vector2, std_vector3)); BOOST_TEST_NOT(detail::axes_equal(std_vector3, std_vector4)); auto fusion_vector1 = boost::fusion::make_vector( - regular_axis<>{2, -1, 1}, variable_axis<>{-1, 0, 1}, - category_axis{"A", "B", "C"}); + axis::regular<>{2, -1, 1}, axis::variable<>{-1, 0, 1}, + axis::category{"A", "B", "C"}); - auto fusion_vector2 = boost::fusion::make_vector(regular_axis<>{2, -1, 1}, - variable_axis<>{-1, 0, 1}, - category_axis{"A", "B"}); + auto fusion_vector2 = boost::fusion::make_vector(axis::regular<>{2, -1, 1}, + axis::variable<>{-1, 0, 1}, + axis::category{"A", "B"}); - auto fusion_vector3 = boost::fusion::make_vector(regular_axis<>{2, -1, 1}, - variable_axis<>{-1, 0, 1}); + auto fusion_vector3 = boost::fusion::make_vector(axis::regular<>{2, -1, 1}, + axis::variable<>{-1, 0, 1}); BOOST_TEST(detail::axes_equal(std_vector1, fusion_vector1)); BOOST_TEST(detail::axes_equal(fusion_vector1, std_vector1)); @@ -323,21 +323,21 @@ int main() { // sequence assign { - std::vector, variable_axis<>, category_axis, - integer_axis>> - std_vector1 = {regular_axis<>{2, -1, 1}, variable_axis<>{-1, 0, 1}, - category_axis{"A", "B", "C"}}; + std::vector, axis::variable<>, axis::category, + axis::integer>> + std_vector1 = {axis::regular<>{2, -1, 1}, axis::variable<>{-1, 0, 1}, + axis::category{"A", "B", "C"}}; - std::vector, variable_axis<>, category_axis>> - std_vector2 = {regular_axis<>{2, -2, 2}, variable_axis<>{-2, 0, 2}, - category_axis{"A", "B"}}; + std::vector, axis::variable<>, axis::category>> + std_vector2 = {axis::regular<>{2, -2, 2}, axis::variable<>{-2, 0, 2}, + axis::category{"A", "B"}}; detail::axes_assign(std_vector2, std_vector1); BOOST_TEST(detail::axes_equal(std_vector2, std_vector1)); auto fusion_vector1 = boost::fusion::make_vector( - regular_axis<>{2, -3, 3}, variable_axis<>{-3, 0, 3}, - category_axis{"A", "B", "C", "D"}); + axis::regular<>{2, -3, 3}, axis::variable<>{-3, 0, 3}, + axis::category{"A", "B", "C", "D"}); detail::axes_assign(fusion_vector1, std_vector1); BOOST_TEST(detail::axes_equal(fusion_vector1, std_vector1)); @@ -347,9 +347,9 @@ int main() { detail::axes_assign(std_vector3, fusion_vector1); BOOST_TEST(detail::axes_equal(std_vector3, fusion_vector1)); - auto fusion_vector2 = boost::fusion::make_vector(regular_axis<>{2, -1, 1}, - variable_axis<>{-1, 0, 1}, - category_axis{"A", "B"}); + auto fusion_vector2 = boost::fusion::make_vector(axis::regular<>{2, -1, 1}, + axis::variable<>{-1, 0, 1}, + axis::category{"A", "B"}); detail::axes_assign(fusion_vector2, fusion_vector1); BOOST_TEST(detail::axes_equal(fusion_vector2, fusion_vector1)); diff --git a/test/histogram_test.cpp b/test/histogram_test.cpp index 179d12e0..0e384b81 100644 --- a/test/histogram_test.cpp +++ b/test/histogram_test.cpp @@ -39,100 +39,100 @@ template void run_tests() { // init_0 { - auto h = histogram, adaptive_storage<>>(); + auto h = histogram, adaptive_storage<>>(); BOOST_TEST_EQ(h.dim(), 1); BOOST_TEST_EQ(h.size(), 0); - auto h2 = histogram, + auto h2 = histogram, container_storage>>(); BOOST_TEST(h2 == h); auto h3 = - histogram>, adaptive_storage<>>(); + histogram>, adaptive_storage<>>(); BOOST_TEST(h3 != h); } // init_1 { auto h = - make_histogram>(Type(), regular_axis<>{3, -1, 1}); + make_histogram>(Type(), axis::regular<>{3, -1, 1}); BOOST_TEST_EQ(h.dim(), 1); BOOST_TEST_EQ(h.size(), 5); BOOST_TEST_EQ(shape(h.axis(0_c)), 5); BOOST_TEST_EQ(shape(h.axis()), 5); auto h2 = make_histogram>>( - Type(), regular_axis<>{3, -1, 1}); + Type(), axis::regular<>{3, -1, 1}); BOOST_TEST(h2 == h); } // init_2 { auto h = make_histogram>( - Type(), regular_axis<>{3, -1, 1}, integer_axis{-1, 1}); + Type(), axis::regular<>{3, -1, 1}, axis::integer{-1, 1}); BOOST_TEST_EQ(h.dim(), 2); BOOST_TEST_EQ(h.size(), 25); BOOST_TEST_EQ(shape(h.axis(0_c)), 5); BOOST_TEST_EQ(shape(h.axis(1_c)), 5); auto h2 = make_histogram>>( - Type(), regular_axis<>{3, -1, 1}, integer_axis{-1, 1}); + Type(), axis::regular<>{3, -1, 1}, axis::integer{-1, 1}); BOOST_TEST(h2 == h); } // init_3 { auto h = make_histogram>( - Type(), regular_axis<>{3, -1, 1}, integer_axis{-1, 1}, - circular_axis<>{3}); + Type(), axis::regular<>{3, -1, 1}, axis::integer{-1, 1}, + axis::circular<>{3}); BOOST_TEST_EQ(h.dim(), 3); BOOST_TEST_EQ(h.size(), 75); auto h2 = make_histogram>>( - Type(), regular_axis<>{3, -1, 1}, integer_axis{-1, 1}, - circular_axis<>{3}); + Type(), axis::regular<>{3, -1, 1}, axis::integer{-1, 1}, + axis::circular<>{3}); BOOST_TEST(h2 == h); } // init_4 { auto h = make_histogram>( - Type(), regular_axis<>{3, -1, 1}, integer_axis{-1, 1}, - circular_axis<>{3}, variable_axis<>{-1, 0, 1}); + Type(), axis::regular<>{3, -1, 1}, axis::integer{-1, 1}, + axis::circular<>{3}, axis::variable<>{-1, 0, 1}); BOOST_TEST_EQ(h.dim(), 4); BOOST_TEST_EQ(h.size(), 300); auto h2 = make_histogram>>( - Type(), regular_axis<>{3, -1, 1}, integer_axis{-1, 1}, - circular_axis<>{3}, variable_axis<>{-1, 0, 1}); + Type(), axis::regular<>{3, -1, 1}, axis::integer{-1, 1}, + axis::circular<>{3}, axis::variable<>{-1, 0, 1}); BOOST_TEST(h2 == h); } // init_5 { auto h = make_histogram>( - Type(), regular_axis<>{3, -1, 1}, integer_axis{-1, 1}, - circular_axis<>{3}, variable_axis<>{-1, 0, 1}, - category_axis{"A", "B", "C"}); + Type(), axis::regular<>{3, -1, 1}, axis::integer{-1, 1}, + axis::circular<>{3}, axis::variable<>{-1, 0, 1}, + axis::category{"A", "B", "C"}); BOOST_TEST_EQ(h.dim(), 5); BOOST_TEST_EQ(h.size(), 900); auto h2 = make_histogram>>( - Type(), regular_axis<>{3, -1, 1}, integer_axis{-1, 1}, - circular_axis<>{3}, variable_axis<>{-1, 0, 1}, - category_axis{"A", "B", "C"}); + Type(), axis::regular<>{3, -1, 1}, axis::integer{-1, 1}, + axis::circular<>{3}, axis::variable<>{-1, 0, 1}, + axis::category{"A", "B", "C"}); BOOST_TEST(h2 == h); } // copy_ctor { - auto h = make_histogram>(Type(), integer_axis(0, 1), - integer_axis(0, 2)); + auto h = make_histogram>(Type(), axis::integer(0, 1), + axis::integer(0, 2)); h.fill(0, 0); auto h2 = decltype(h)(h); BOOST_TEST(h2 == h); - auto h3 = histogram, + auto h3 = histogram, container_storage>>(h); BOOST_TEST(h3 == h); } // copy_assign { - auto h = make_histogram>(Type(), integer_axis(0, 1), - integer_axis(0, 2)); + auto h = make_histogram>(Type(), axis::integer(0, 1), + axis::integer(0, 2)); h.fill(0, 0); auto h2 = decltype(h)(); BOOST_TEST(h != h2); @@ -141,7 +141,7 @@ template void run_tests() { // test self-assign h2 = h2; BOOST_TEST(h == h2); - auto h3 = histogram, + auto h3 = histogram, container_storage>>(); h3 = h; BOOST_TEST(h == h3); @@ -149,8 +149,8 @@ template void run_tests() { // move { - auto h = make_histogram>(Type(), integer_axis(0, 1), - integer_axis(0, 2)); + auto h = make_histogram>(Type(), axis::integer(0, 1), + axis::integer(0, 2)); h.fill(0, 0); const auto href = h; decltype(h) h2(std::move(h)); @@ -171,7 +171,7 @@ template void run_tests() { // utility { auto a = - make_histogram>(Type(), regular_axis<>(1, 1, 2)); + make_histogram>(Type(), axis::regular<>(1, 1, 2)); BOOST_TEST_EQ(bins(a.axis()), 1); BOOST_TEST_EQ(shape(a.axis()), 3); BOOST_TEST_EQ(index(a.axis(), 1.0), 0); @@ -179,7 +179,7 @@ template void run_tests() { BOOST_TEST_EQ(right(a.axis(), 0), 2.0); BOOST_TEST_EQ(center(a.axis(), 0), 1.5); - auto b = make_histogram>(Type(), integer_axis(1, 2)); + auto b = make_histogram>(Type(), axis::integer(1, 2)); BOOST_TEST_EQ(bins(a.axis()), 1); BOOST_TEST_EQ(shape(a.axis()), 3); BOOST_TEST_EQ(index(a.axis(), 1.0), 0); @@ -190,18 +190,18 @@ template void run_tests() { // equal_compare { - auto a = make_histogram>(Type(), integer_axis(0, 1)); - auto b = make_histogram>(Type(), integer_axis(0, 1), - integer_axis(0, 2)); + auto a = make_histogram>(Type(), axis::integer(0, 1)); + auto b = make_histogram>(Type(), axis::integer(0, 1), + axis::integer(0, 2)); BOOST_TEST(a != b); BOOST_TEST(b != a); - auto c = make_histogram>(Type(), integer_axis(0, 1)); + auto c = make_histogram>(Type(), axis::integer(0, 1)); BOOST_TEST(b != c); BOOST_TEST(c != b); BOOST_TEST(a == c); BOOST_TEST(c == a); auto d = - make_histogram>(Type(), regular_axis<>(2, 0, 1)); + make_histogram>(Type(), axis::regular<>(2, 0, 1)); BOOST_TEST(c != d); BOOST_TEST(d != c); c.fill(0); @@ -217,7 +217,7 @@ template void run_tests() { // d1 { - auto h = make_histogram>(Type(), integer_axis(0, 1)); + auto h = make_histogram>(Type(), axis::integer(0, 1)); h.fill(0); h.fill(0); h.fill(-1); @@ -246,7 +246,7 @@ template void run_tests() { // d1_2 { auto h = make_histogram>(Type(), - integer_axis(0, 1, "", false)); + axis::integer(0, 1, "", false)); h.fill(0); h.fill(-0); h.fill(-1); @@ -271,7 +271,7 @@ template void run_tests() { // d1w { auto h = - make_histogram>(Type(), regular_axis<>(2, -1, 1)); + make_histogram>(Type(), axis::regular<>(2, -1, 1)); h.fill(0); h.fill(weight(2.0), -1.0); h.fill(-1.0); @@ -294,7 +294,7 @@ template void run_tests() { // d1w2 { auto h = make_histogram>>( - Type(), regular_axis<>(2, -1, 1)); + Type(), axis::regular<>(2, -1, 1)); h.fill(0); h.fill(count(2.0), -1.0); h.fill(-1.0); @@ -312,7 +312,7 @@ template void run_tests() { // d2 { auto h = make_histogram>( - Type(), regular_axis<>(2, -1, 1), integer_axis(-1, 1, "", false)); + Type(), axis::regular<>(2, -1, 1), axis::integer(-1, 1, "", false)); h.fill(-1, -1); h.fill(-1, 0); h.fill(-1, -10); @@ -361,7 +361,7 @@ template void run_tests() { // d2w { auto h = make_histogram>( - Type(), regular_axis<>(2, -1, 1), integer_axis(-1, 1, "", false)); + Type(), axis::regular<>(2, -1, 1), axis::integer(-1, 1, "", false)); h.fill(-1, 0); // -> 0, 1 h.fill(weight(10), -1, -1); // -> 0, 0 h.fill(weight(5), -1, -10); // is ignored @@ -405,7 +405,7 @@ template void run_tests() { // d3w { auto h = make_histogram>( - Type(), integer_axis(0, 3), integer_axis(0, 4), integer_axis(0, 5)); + Type(), axis::integer(0, 3), axis::integer(0, 4), axis::integer(0, 5)); for (auto i = 0; i < bins(h.axis(0_c)); ++i) { for (auto j = 0; j < bins(h.axis(1_c)); ++j) { for (auto k = 0; k < bins(h.axis(2_c)); ++k) { @@ -425,9 +425,9 @@ template void run_tests() { // add_1 { - auto a = make_histogram>(Type(), integer_axis(-1, 1)); + auto a = make_histogram>(Type(), axis::integer(-1, 1)); auto b = make_histogram>>( - Type(), integer_axis(-1, 1)); + Type(), axis::integer(-1, 1)); a.fill(-1); b.fill(1); auto c = a; @@ -448,8 +448,8 @@ template void run_tests() { // add_2 { - auto a = make_histogram>(Type(), integer_axis(0, 1)); - auto b = make_histogram>(Type(), integer_axis(0, 1)); + auto a = make_histogram>(Type(), axis::integer(0, 1)); + auto b = make_histogram>(Type(), axis::integer(0, 1)); a.fill(0); BOOST_TEST_EQ(a.variance(0), 1); @@ -476,9 +476,9 @@ template void run_tests() { // add_3 { auto a = make_histogram>>( - Type(), integer_axis(-1, 1)); + Type(), axis::integer(-1, 1)); auto b = make_histogram>>( - Type(), integer_axis(-1, 1)); + Type(), axis::integer(-1, 1)); a.fill(-1); b.fill(1); auto c = a; @@ -499,14 +499,14 @@ template void run_tests() { // bad_add { - auto a = make_histogram>(Type(), integer_axis(0, 1)); - auto b = make_histogram>(Type(), integer_axis(0, 2)); + auto a = make_histogram>(Type(), axis::integer(0, 1)); + auto b = make_histogram>(Type(), axis::integer(0, 2)); BOOST_TEST_THROWS(a += b, std::logic_error); } // bad_index { - auto a = make_histogram>(Type(), integer_axis(0, 1)); + auto a = make_histogram>(Type(), axis::integer(0, 1)); BOOST_TEST_THROWS(a.value(5), std::out_of_range); BOOST_TEST_THROWS(a.variance(5), std::out_of_range); } @@ -514,7 +514,7 @@ template void run_tests() { // functional programming { auto v = std::vector{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - auto h = make_histogram>(Type(), integer_axis(0, 9)); + auto h = make_histogram>(Type(), axis::integer(0, 9)); std::for_each(v.begin(), v.end(), [&h](int x) { h.fill(weight(2.0), x); }); BOOST_TEST_EQ(h.sum(), 20.0); } @@ -522,11 +522,11 @@ template void run_tests() { // histogram_serialization { auto a = make_histogram>( - Type(), regular_axis<>(3, -1, 1, "r"), - circular_axis<>(4, 0.0, 1.0, "p"), - regular_axis(3, 1, 100, "lr"), - variable_axis<>({0.1, 0.2, 0.3, 0.4, 0.5}, "v"), - category_axis{"A", "B", "C"}, integer_axis(0, 1, "i")); + Type(), axis::regular<>(3, -1, 1, "r"), + axis::circular<>(4, 0.0, 1.0, "p"), + axis::regular(3, 1, 100, "lr"), + axis::variable<>({0.1, 0.2, 0.3, 0.4, 0.5}, "v"), + axis::category{"A", "B", "C"}, axis::integer(0, 1, "i")); a.fill(0.5, 20, 0.1, 0.25, 1, 0); std::string buf; { @@ -548,19 +548,19 @@ template void run_tests() { // histogram_ostream { auto a = make_histogram>( - Type(), regular_axis<>(3, -1, 1, "r"), integer_axis(0, 1, "i")); + Type(), axis::regular<>(3, -1, 1, "r"), axis::integer(0, 1, "i")); std::ostringstream os; os << a; BOOST_TEST_EQ(os.str(), "histogram(" - "\n regular_axis(3, -1, 1, label='r')," - "\n integer_axis(0, 1, label='i')," + "\n regular(3, -1, 1, label='r')," + "\n integer(0, 1, label='i')," "\n)"); } // histogram_reset { auto a = make_histogram>(Type(), - integer_axis(0, 1, "", false)); + axis::integer(0, 1, "", false)); a.fill(0); a.fill(1); BOOST_TEST_EQ(a.value(0), 1); @@ -572,8 +572,8 @@ template void run_tests() { // reduce { - auto h1 = make_histogram>(Type(), integer_axis(0, 1), - integer_axis(2, 3)); + auto h1 = make_histogram>(Type(), axis::integer(0, 1), + axis::integer(2, 3)); h1.fill(0, 2); h1.fill(0, 3); h1.fill(1, 2); @@ -595,25 +595,25 @@ template void run_mixed_tests() { // compare { - auto a = make_histogram>(T1{}, regular_axis<>{3, 0, 3}, - integer_axis(0, 1)); - auto b = make_histogram>(T2{}, regular_axis<>{3, 0, 3}, - integer_axis(0, 1)); + auto a = make_histogram>(T1{}, axis::regular<>{3, 0, 3}, + axis::integer(0, 1)); + auto b = make_histogram>(T2{}, axis::regular<>{3, 0, 3}, + axis::integer(0, 1)); BOOST_TEST_EQ(a, b); - auto b2 = make_histogram>(T2{}, integer_axis{0, 3}, - integer_axis(0, 1)); + auto b2 = make_histogram>(T2{}, axis::integer{0, 3}, + axis::integer(0, 1)); BOOST_TEST_NE(a, b2); - auto b3 = make_histogram>(T2{}, regular_axis<>(3, 0, 4), - integer_axis(0, 1)); + auto b3 = make_histogram>(T2{}, axis::regular<>(3, 0, 4), + axis::integer(0, 1)); BOOST_TEST_NE(a, b3); } // copy_assign { - auto a = make_histogram>(T1{}, regular_axis<>{3, 0, 3}, - integer_axis(0, 1)); - auto b = make_histogram>(T2{}, regular_axis<>{3, 0, 3}, - integer_axis(0, 1)); + auto a = make_histogram>(T1{}, axis::regular<>{3, 0, 3}, + axis::integer(0, 1)); + auto b = make_histogram>(T2{}, axis::regular<>{3, 0, 3}, + axis::integer(0, 1)); a.fill(1, 1); BOOST_TEST_NE(a, b); b = a; @@ -632,8 +632,8 @@ int main() { // init { auto v = std::vector::axis_type>(); - v.push_back(regular_axis<>(100, -1, 1)); - v.push_back(integer_axis(1, 6)); + v.push_back(axis::regular<>(100, -1, 1)); + v.push_back(axis::integer(1, 6)); 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]); @@ -643,7 +643,7 @@ int main() { // utility { - auto c = histogram(category_axis({"A", "B"})); + auto c = histogram(axis::category({"A", "B"})); BOOST_TEST_THROWS(left(c.axis(), 0), std::runtime_error); BOOST_TEST_THROWS(right(c.axis(), 0), std::runtime_error); BOOST_TEST_THROWS(center(c.axis(), 0), std::runtime_error); diff --git a/test/python_suite_test.py.in b/test/python_suite_test.py.in index 97d3a4c7..257f08a0 100755 --- a/test/python_suite_test.py.in +++ b/test/python_suite_test.py.in @@ -9,8 +9,8 @@ import unittest from math import pi -from histogram import histogram, regular_axis, circular_axis, \ - variable_axis, category_axis, integer_axis +from histogram import histogram +from histogram.axis import regular, circular, variable, category, integer import pickle import os if @PYTHON_VERSION_MAJOR@ == 3: @@ -22,63 +22,63 @@ have_numpy = "@HAVE_NUMPY@" if have_numpy: import numpy -class test_regular_axis(unittest.TestCase): +class test_regular(unittest.TestCase): def test_init(self): - regular_axis(1, 1.0, 2.0) - regular_axis(1, 1.0, 2.0, label="ra") - regular_axis(1, 1.0, 2.0, uoflow=False) - regular_axis(1, 1.0, 2.0, label="ra", uoflow=False) + regular(1, 1.0, 2.0) + regular(1, 1.0, 2.0, label="ra") + regular(1, 1.0, 2.0, uoflow=False) + regular(1, 1.0, 2.0, label="ra", uoflow=False) with self.assertRaises(TypeError): - regular_axis() + regular() with self.assertRaises(TypeError): - regular_axis(1) + regular(1) with self.assertRaises(TypeError): - regular_axis(1, 1.0) + regular(1, 1.0) with self.assertRaises(RuntimeError): - regular_axis(0, 1.0, 2.0) + regular(0, 1.0, 2.0) with self.assertRaises(TypeError): - regular_axis("1", 1.0, 2.0) + regular("1", 1.0, 2.0) with self.assertRaises(Exception): - regular_axis(-1, 1.0, 2.0) + regular(-1, 1.0, 2.0) with self.assertRaises(RuntimeError): - regular_axis(1, 2.0, 1.0) + regular(1, 2.0, 1.0) with self.assertRaises(TypeError): - regular_axis(1, 1.0, 2.0, label=0) + regular(1, 1.0, 2.0, label=0) with self.assertRaises(TypeError): - regular_axis(1, 1.0, 2.0, label="ra", uoflow="True") + regular(1, 1.0, 2.0, label="ra", uoflow="True") with self.assertRaises(TypeError): - regular_axis(1, 1.0, 2.0, bad_keyword="ra") - a = regular_axis(4, 1.0, 2.0) - self.assertEqual(a, regular_axis(4, 1.0, 2.0)) - self.assertNotEqual(a, regular_axis(3, 1.0, 2.0)) - self.assertNotEqual(a, regular_axis(4, 1.1, 2.0)) - self.assertNotEqual(a, regular_axis(4, 1.0, 2.1)) + regular(1, 1.0, 2.0, bad_keyword="ra") + a = regular(4, 1.0, 2.0) + self.assertEqual(a, regular(4, 1.0, 2.0)) + self.assertNotEqual(a, regular(3, 1.0, 2.0)) + self.assertNotEqual(a, regular(4, 1.1, 2.0)) + self.assertNotEqual(a, regular(4, 1.0, 2.1)) def test_len(self): - a = regular_axis(4, 1.0, 2.0) + a = regular(4, 1.0, 2.0) self.assertEqual(len(a), 5) def test_repr(self): - for s in ("regular_axis(4, 1.1, 2.2)", - "regular_axis(4, 1.1, 2.2, label='ra')", - "regular_axis(4, 1.1, 2.2, uoflow=False)", - "regular_axis(4, 1.1, 2.2, label='ra', uoflow=False)"): + for s in ("regular(4, 1.1, 2.2)", + "regular(4, 1.1, 2.2, label='ra')", + "regular(4, 1.1, 2.2, uoflow=False)", + "regular(4, 1.1, 2.2, label='ra', uoflow=False)"): self.assertEqual(str(eval(s)), s) def test_getitem(self): v = [1.0, 1.25, 1.5, 1.75, 2.0] - a = regular_axis(4, 1.0, 2.0) + a = regular(4, 1.0, 2.0) for i in range(5): self.assertEqual(a[i], v[i]) def test_iter(self): v = [1.0, 1.25, 1.5, 1.75, 2.0] - a = regular_axis(4, 1.0, 2.0) + a = regular(4, 1.0, 2.0) self.assertEqual([x for x in a], v) def test_index(self): - a = regular_axis(4, 1.0, 2.0) + a = regular(4, 1.0, 2.0) self.assertEqual(a.index(-1), -1) self.assertEqual(a.index(0.99), -1) self.assertEqual(a.index(1.0), 0) @@ -94,53 +94,53 @@ class test_regular_axis(unittest.TestCase): self.assertEqual(a.index(2.1), 4) self.assertEqual(a.index(20), 4) -class test_circular_axis(unittest.TestCase): +class test_circular(unittest.TestCase): def test_init(self): - circular_axis(1) - circular_axis(4, 1.0) - circular_axis(4, 1.0, label="pa") + circular(1) + circular(4, 1.0) + circular(4, 1.0, label="pa") with self.assertRaises(TypeError): - circular_axis() + circular() with self.assertRaises(Exception): - circular_axis(-1) + circular(-1) with self.assertRaises(TypeError): - circular_axis(4, 1.0, uoflow=True) + circular(4, 1.0, uoflow=True) with self.assertRaises(TypeError): - circular_axis(1, 1.0, 2.0, 3.0) + circular(1, 1.0, 2.0, 3.0) with self.assertRaises(TypeError): - circular_axis(1, 1.0, label=1) + circular(1, 1.0, label=1) with self.assertRaises(TypeError): - circular_axis("1") - a = circular_axis(4, 1.0) - self.assertEqual(a, circular_axis(4, 1.0)) - self.assertNotEqual(a, circular_axis(2, 1.0)) - self.assertNotEqual(a, circular_axis(4, 0.0)) + circular("1") + a = circular(4, 1.0) + self.assertEqual(a, circular(4, 1.0)) + self.assertNotEqual(a, circular(2, 1.0)) + self.assertNotEqual(a, circular(4, 0.0)) def test_len(self): - self.assertEqual(len(circular_axis(4)), 5) - self.assertEqual(len(circular_axis(4, 1.0)), 5) + self.assertEqual(len(circular(4)), 5) + self.assertEqual(len(circular(4, 1.0)), 5) def test_repr(self): - for s in ("circular_axis(4)", - "circular_axis(4, phase=1)", - "circular_axis(4, phase=1, label='x')", - "circular_axis(4, label='x')"): + for s in ("circular(4)", + "circular(4, phase=1)", + "circular(4, phase=1, label='x')", + "circular(4, label='x')"): self.assertEqual(str(eval(s)), s) def test_getitem(self): v = [1.0, 1.0 + 0.5 * pi, 1.0 + pi, 1.0 + 1.5 *pi, 1.0 + 2.0 * pi] - a = circular_axis(4, 1.0) + a = circular(4, 1.0) for i in range(5): self.assertEqual(a[i], v[i]) def test_iter(self): - a = circular_axis(4, 1.0) + a = circular(4, 1.0) v = [1.0, 1.0 + 0.5 * pi, 1.0 + pi, 1.0 + 1.5 *pi, 1.0 + 2.0 * pi] self.assertEqual([x for x in a], v) def test_index(self): - a = circular_axis(4, 1.0) + a = circular(4, 1.0) d = 0.5 * pi self.assertEqual(a.index(0.99 - 4*d), 3) self.assertEqual(a.index(0.99 - 3*d), 0) @@ -156,53 +156,53 @@ class test_circular_axis(unittest.TestCase): self.assertEqual(a.index(1.0 + 4*d), 0) self.assertEqual(a.index(1.0 + 5*d), 1) -class test_variable_axis(unittest.TestCase): +class test_variable(unittest.TestCase): def test_init(self): - variable_axis(0, 1) - variable_axis(1, -1) - variable_axis(0, 1, 2, 3, 4) - variable_axis(0, 1, label="va") - variable_axis(0, 1, uoflow=True) - variable_axis(0, 1, label="va", uoflow=True) + variable(0, 1) + variable(1, -1) + variable(0, 1, 2, 3, 4) + variable(0, 1, label="va") + variable(0, 1, uoflow=True) + variable(0, 1, label="va", uoflow=True) with self.assertRaises(TypeError): - variable_axis() + variable() with self.assertRaises(RuntimeError): - variable_axis(1.0) + variable(1.0) with self.assertRaises(TypeError): - variable_axis("1", 2) + variable("1", 2) with self.assertRaises(KeyError): - variable_axis(0.0, 1.0, 2.0, bad_keyword="ra") - a = variable_axis(-0.1, 0.2, 0.3) - self.assertEqual(a, variable_axis(-0.1, 0.2, 0.3)) - self.assertNotEqual(a, variable_axis(0, 0.2, 0.3)) - self.assertNotEqual(a, variable_axis(-0.1, 0.1, 0.3)) - self.assertNotEqual(a, variable_axis(-0.1, 0.1)) + variable(0.0, 1.0, 2.0, bad_keyword="ra") + a = variable(-0.1, 0.2, 0.3) + self.assertEqual(a, variable(-0.1, 0.2, 0.3)) + self.assertNotEqual(a, variable(0, 0.2, 0.3)) + self.assertNotEqual(a, variable(-0.1, 0.1, 0.3)) + self.assertNotEqual(a, variable(-0.1, 0.1)) def test_len(self): - self.assertEqual(len(variable_axis(-0.1, 0.2, 0.3)), 3) + self.assertEqual(len(variable(-0.1, 0.2, 0.3)), 3) def test_repr(self): - for s in ("variable_axis(-0.1, 0.2)", - "variable_axis(-0.1, 0.2, 0.3)", - "variable_axis(-0.1, 0.2, 0.3, label='va')", - "variable_axis(-0.1, 0.2, 0.3, uoflow=False)", - "variable_axis(-0.1, 0.2, 0.3, label='va', uoflow=False)"): + for s in ("variable(-0.1, 0.2)", + "variable(-0.1, 0.2, 0.3)", + "variable(-0.1, 0.2, 0.3, label='va')", + "variable(-0.1, 0.2, 0.3, uoflow=False)", + "variable(-0.1, 0.2, 0.3, label='va', uoflow=False)"): self.assertEqual(str(eval(s)), s) def test_getitem(self): v = [-0.1, 0.2, 0.3] - a = variable_axis(*v) + a = variable(*v) for i in range(3): self.assertEqual(a[i], v[i]) def test_iter(self): v = [-0.1, 0.2, 0.3] - a = variable_axis(*v) + a = variable(*v) self.assertEqual([x for x in a], v) def test_index(self): - a = variable_axis(-0.1, 0.2, 0.3) + a = variable(-0.1, 0.2, 0.3) self.assertEqual(a.index(-10.0), -1) self.assertEqual(a.index(-0.11), -1) self.assertEqual(a.index(-0.1), 0) @@ -215,88 +215,88 @@ class test_variable_axis(unittest.TestCase): self.assertEqual(a.index(0.31), 2) self.assertEqual(a.index(10), 2) -class test_category_axis(unittest.TestCase): +class test_category(unittest.TestCase): def test_init(self): - category_axis("A", "B", "C") - category_axis("A", "B", "C", label="ca") + category("A", "B", "C") + category("A", "B", "C", label="ca") with self.assertRaises(TypeError): - category_axis() + category() with self.assertRaises(TypeError): - category_axis(1) + category(1) with self.assertRaises(TypeError): - category_axis("1", 2) + category("1", 2) with self.assertRaises(TypeError): - category_axis("A", "B", label=1) + category("A", "B", label=1) with self.assertRaises(KeyError): - category_axis("A", "B", "C", uoflow=True) - self.assertEqual(category_axis("A", "B", "C"), - category_axis("A", "B", "C")) + category("A", "B", "C", uoflow=True) + self.assertEqual(category("A", "B", "C"), + category("A", "B", "C")) def test_len(self): - a = category_axis("A", "B", "C") + a = category("A", "B", "C") self.assertEqual(len(a), 3) def test_repr(self): - for s in ("category_axis('A')", - "category_axis('A', 'B')", - "category_axis('A', 'B', 'C')"): + for s in ("category('A')", + "category('A', 'B')", + "category('A', 'B', 'C')"): self.assertEqual(str(eval(s)), s) def test_getitem(self): c = "A", "B", "C" - a = category_axis(*c) + a = category(*c) for i in range(3): self.assertEqual(a[i], c[i]) def test_iter(self): c = ["A", "B", "C"] - self.assertEqual([x for x in category_axis(*c)], c) + self.assertEqual([x for x in category(*c)], c) -class test_integer_axis(unittest.TestCase): +class test_integer(unittest.TestCase): def test_init(self): - integer_axis(-1, 2) + integer(-1, 2) with self.assertRaises(TypeError): - integer_axis() + integer() with self.assertRaises(TypeError): - integer_axis(1) + integer(1) with self.assertRaises(TypeError): - integer_axis("1", 2) + integer("1", 2) with self.assertRaises(RuntimeError): - integer_axis(2, -1) + integer(2, -1) with self.assertRaises(TypeError): - integer_axis(1, 2, 3) - self.assertEqual(integer_axis(-1, 2), integer_axis(-1, 2)) - self.assertNotEqual(integer_axis(-1, 2), integer_axis(-1, 2, label="ia")) - self.assertNotEqual(integer_axis(-1, 2, uoflow=False), - integer_axis(-1, 2, uoflow=True)) + integer(1, 2, 3) + self.assertEqual(integer(-1, 2), integer(-1, 2)) + self.assertNotEqual(integer(-1, 2), integer(-1, 2, label="ia")) + self.assertNotEqual(integer(-1, 2, uoflow=False), + integer(-1, 2, uoflow=True)) def test_len(self): - self.assertEqual(len(integer_axis(-1, 2)), 4) + self.assertEqual(len(integer(-1, 2)), 4) def test_repr(self): - for s in ("integer_axis(-1, 1)", - "integer_axis(-1, 1, label='ia')", - "integer_axis(-1, 1, uoflow=False)", - "integer_axis(-1, 1, label='ia', uoflow=False)"): + for s in ("integer(-1, 1)", + "integer(-1, 1, label='ia')", + "integer(-1, 1, uoflow=False)", + "integer(-1, 1, label='ia', uoflow=False)"): self.assertEqual(str(eval(s)), s) def test_label(self): - self.assertEqual(integer_axis(-1, 2, label="ia").label, "ia") + self.assertEqual(integer(-1, 2, label="ia").label, "ia") def test_getitem(self): v = [-1, 0, 1, 2] - a = integer_axis(-1, 2) + a = integer(-1, 2) for i in range(4): self.assertEqual(a[i], v[i]) def test_iter(self): - v = [x for x in integer_axis(-1, 2)] + v = [x for x in integer(-1, 2)] self.assertEqual(v, [-1, 0, 1, 2]) def test_index(self): - a = integer_axis(-1, 2) + a = integer(-1, 2) self.assertEqual(a.index(-3), -1) self.assertEqual(a.index(-2), -1) self.assertEqual(a.index(-1), 0) @@ -310,7 +310,7 @@ class test_histogram(unittest.TestCase): def test_init(self): histogram() - histogram(integer_axis(-1, 1)) + histogram(integer(-1, 1)) with self.assertRaises(TypeError): histogram(1) with self.assertRaises(TypeError): @@ -318,25 +318,25 @@ class test_histogram(unittest.TestCase): with self.assertRaises(TypeError): histogram([]) with self.assertRaises(TypeError): - histogram(regular_axis) + histogram(regular) with self.assertRaises(TypeError): - histogram(regular_axis()) + histogram(regular()) with self.assertRaises(TypeError): - histogram([integer_axis(-1, 1)]) + histogram([integer(-1, 1)]) with self.assertRaises(RuntimeError): - histogram(integer_axis(-1, 1), unknown_keyword="nh") + histogram(integer(-1, 1), unknown_keyword="nh") - h = histogram(integer_axis(-1, 1)) + h = histogram(integer(-1, 1)) self.assertEqual(len(h), 1) - self.assertEqual(h[0], integer_axis(-1, 1)) + self.assertEqual(h[0], integer(-1, 1)) self.assertEqual(h[0].shape, 5) - self.assertEqual(histogram(integer_axis(-1, 1, uoflow=False))[0].shape, 3) - self.assertNotEqual(h, histogram(regular_axis(1, -1, 1))) - self.assertNotEqual(h, histogram(integer_axis(-1, 2))) - self.assertNotEqual(h, histogram(integer_axis(-1, 1, label="ia"))) + self.assertEqual(histogram(integer(-1, 1, uoflow=False))[0].shape, 3) + self.assertNotEqual(h, histogram(regular(1, -1, 1))) + self.assertNotEqual(h, histogram(integer(-1, 2))) + self.assertNotEqual(h, histogram(integer(-1, 1, label="ia"))) def test_copy(self): - a = histogram(integer_axis(-1, 1)) + a = histogram(integer(-1, 1)) import copy b = copy.copy(a) self.assertEqual(a, b) @@ -346,8 +346,8 @@ class test_histogram(unittest.TestCase): self.assertNotEqual(id(b), id(c)) def test_fill_1d(self): - h0 = histogram(integer_axis(-1, 1, uoflow=False)) - h1 = histogram(integer_axis(-1, 1, uoflow=True)) + h0 = histogram(integer(-1, 1, uoflow=False)) + h1 = histogram(integer(-1, 1, uoflow=True)) for h in (h0, h1): with self.assertRaises(RuntimeError): h.fill() @@ -386,7 +386,7 @@ class test_histogram(unittest.TestCase): self.assertEqual(h1.value(3), 1) def test_growth(self): - h = histogram(integer_axis(-1, 1)) + h = histogram(integer(-1, 1)) h.fill(-1) h.fill(1) h.fill(1) @@ -403,8 +403,8 @@ class test_histogram(unittest.TestCase): def test_fill_2d(self): for uoflow in (False, True): - h = histogram(integer_axis(-1, 1, uoflow=uoflow), - regular_axis(4, -2, 2, uoflow=uoflow)) + h = histogram(integer(-1, 1, uoflow=uoflow), + regular(4, -2, 2, uoflow=uoflow)) h.fill(-1, -2) h.fill(-1, -1) h.fill(0, 0) @@ -428,8 +428,8 @@ class test_histogram(unittest.TestCase): def test_add_2d(self): for uoflow in (False, True): - h = histogram(integer_axis(-1, 1, uoflow=uoflow), - regular_axis(4, -2, 2, uoflow=uoflow)) + h = histogram(integer(-1, 1, uoflow=uoflow), + regular(4, -2, 2, uoflow=uoflow)) h.fill(-1, -2) h.fill(-1, -1) h.fill(0, 0) @@ -452,15 +452,15 @@ class test_histogram(unittest.TestCase): self.assertEqual(h.variance(i, j), 2 * m[i][j]) def test_add_2d_bad(self): - a = histogram(integer_axis(-1, 1)) - b = histogram(regular_axis(3, -1, 1)) + a = histogram(integer(-1, 1)) + b = histogram(regular(3, -1, 1)) with self.assertRaises(RuntimeError): a += b def test_add_2d_w(self): for uoflow in (False, True): - h = histogram(integer_axis(-1, 1, uoflow=uoflow), - regular_axis(4, -2, 2, uoflow=uoflow)) + h = histogram(integer(-1, 1, uoflow=uoflow), + regular(4, -2, 2, uoflow=uoflow)) h.fill(-1, -2) h.fill(-1, -1) h.fill(0, 0) @@ -475,8 +475,8 @@ class test_histogram(unittest.TestCase): [0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]] - h2 = histogram(integer_axis(-1, 1, uoflow=uoflow), - regular_axis(4, -2, 2, uoflow=uoflow)) + h2 = histogram(integer(-1, 1, uoflow=uoflow), + regular(4, -2, 2, uoflow=uoflow)) h2.fill(0, 0, weight=0) h2 += h @@ -490,12 +490,12 @@ class test_histogram(unittest.TestCase): self.assertEqual(h.variance(i, j), 2 * m[i][j]) def test_repr(self): - h = histogram(regular_axis(10, 0, 1), integer_axis(0, 1)) + h = histogram(regular(10, 0, 1), integer(0, 1)) h2 = eval(repr(h)) self.assertEqual(h, h2) - def test_axis(self): - axes = (regular_axis(10, 0, 1), integer_axis(0, 1)) + def test(self): + axes = (regular(10, 0, 1), integer(0, 1)) h = histogram(*axes) for a1, a2 in zip(h, axes): self.assertEqual(a1, a2) @@ -506,8 +506,8 @@ class test_histogram(unittest.TestCase): with self.assertRaises(IndexError): h[-3] - def test_axis_overflow(self): - h = histogram(*[regular_axis(1, 0, 1) for i in range(50)]) + def test_overflow(self): + h = histogram(*[regular(1, 0, 1) for i in range(50)]) with self.assertRaises(RuntimeError): h.fill(*range(50)) @@ -518,7 +518,7 @@ class test_histogram(unittest.TestCase): h.variance(*range(50)) def test_out_of_range(self): - h = histogram(regular_axis(3, 0, 1)) + h = histogram(regular(3, 0, 1)) h.fill(-1) h.fill(2) self.assertEqual(h.value(-1), 1) @@ -533,11 +533,11 @@ class test_histogram(unittest.TestCase): h.variance(4) def test_pickle_0(self): - a = histogram(category_axis('A', 'B', 'C'), - integer_axis(0, 20, label='ia'), - regular_axis(20, 0.0, 20.0, uoflow=False), - variable_axis(0.0, 1.0, 2.0), - circular_axis(4, label='pa')) + a = histogram(category('A', 'B', 'C'), + integer(0, 20, label='ia'), + regular(20, 0.0, 20.0, uoflow=False), + variable(0.0, 1.0, 2.0), + circular(4, label='pa')) for i in range(a[0].bins): a.fill(i, 0, 0, 0, 0) for j in range(a[1].bins): @@ -564,10 +564,10 @@ class test_histogram(unittest.TestCase): self.assertEqual(a, b) def test_pickle_1(self): - a = histogram(category_axis('A', 'B', 'C'), - integer_axis(0, 3, label='ia'), - regular_axis(4, 0.0, 4.0, uoflow=False), - variable_axis(0.0, 1.0, 2.0)) + a = histogram(category('A', 'B', 'C'), + integer(0, 3, label='ia'), + regular(4, 0.0, 4.0, uoflow=False), + variable(0.0, 1.0, 2.0)) for i in range(a[0].bins): a.fill(i, 0, 0, 0, weight=3) for j in range(a[1].bins): @@ -592,7 +592,7 @@ class test_histogram(unittest.TestCase): @unittest.skipUnless(have_numpy, "requires build with numpy-support") def test_numpy_conversion_0(self): - a = histogram(integer_axis(0, 2, uoflow=False)) + a = histogram(integer(0, 2, uoflow=False)) for i in range(100): a.fill(1) c = numpy.array(a) # a copy @@ -617,7 +617,7 @@ class test_histogram(unittest.TestCase): @unittest.skipUnless(have_numpy, "requires build with numpy-support") def test_numpy_conversion_1(self): - a = histogram(integer_axis(0, 2)) + a = histogram(integer(0, 2)) for i in range(10): a.fill(1, weight=3) c = numpy.array(a) # a copy @@ -628,9 +628,9 @@ class test_histogram(unittest.TestCase): @unittest.skipUnless(have_numpy, "requires build with numpy-support") def test_numpy_conversion_2(self): - a = histogram(integer_axis(0, 1, uoflow=False), - integer_axis(0, 2, uoflow=False), - integer_axis(0, 3, uoflow=False)) + a = histogram(integer(0, 1, uoflow=False), + integer(0, 2, uoflow=False), + integer(0, 3, uoflow=False)) r = numpy.zeros((2, 3, 4), dtype=numpy.int8) for i in range(a[0].bins): for j in range(a[1].bins): @@ -653,9 +653,9 @@ class test_histogram(unittest.TestCase): @unittest.skipUnless(have_numpy, "requires build with numpy-support") def test_numpy_conversion_3(self): - a = histogram(integer_axis(0, 1), - integer_axis(0, 2), - integer_axis(0, 3)) + a = histogram(integer(0, 1), + integer(0, 2), + integer(0, 3)) r = numpy.zeros((2, 4, 5, 6)) for i in range(a[0].bins): for j in range(a[1].bins): @@ -679,8 +679,8 @@ class test_histogram(unittest.TestCase): @unittest.skipUnless(have_numpy, "requires build with numpy-support") def test_numpy_conversion_4(self): - a = histogram(integer_axis(0, 1, uoflow=False), - integer_axis(0, 3, uoflow=False)) + a = histogram(integer(0, 1, uoflow=False), + integer(0, 3, uoflow=False)) a1 = numpy.asarray(a) self.assertEqual(a1.dtype, numpy.uint8) self.assertEqual(a1.shape, (2, 4)) @@ -692,7 +692,7 @@ class test_histogram(unittest.TestCase): @unittest.skipUnless(have_numpy, "requires build with numpy-support") def test_numpy_conversion_5(self): - a = histogram(integer_axis(0, 1, uoflow=False)) + a = histogram(integer(0, 1, uoflow=False)) a.fill(0) for i in xrange(80): a += a @@ -704,7 +704,7 @@ class test_histogram(unittest.TestCase): @unittest.skipUnless(have_numpy, "requires build with numpy-support") def test_fill_with_numpy_array_0(self): - a = histogram(integer_axis(0, 2, uoflow=False)) + a = histogram(integer(0, 2, uoflow=False)) a.fill(numpy.array([-1, 0, 1, 2, 1, 4])) a.fill((-1, 0)) a.fill([1, 2]) @@ -721,8 +721,8 @@ class test_histogram(unittest.TestCase): with self.assertRaises(ValueError): a.fill("abc") - a = histogram(integer_axis(0, 1, uoflow=False), - regular_axis(2, 0, 2, uoflow=False)) + a = histogram(integer(0, 1, uoflow=False), + regular(2, 0, 2, uoflow=False)) a.fill(numpy.array([[-1., -1.], [0., 1.], [1., 0.1]])) self.assertEqual(a.value(0, 0), 0) self.assertEqual(a.value(0, 1), 1) @@ -732,7 +732,7 @@ class test_histogram(unittest.TestCase): with self.assertRaises(ValueError): a.fill((1, 2, 3)) - a = histogram(integer_axis(0, 2, uoflow=False)) + a = histogram(integer(0, 2, uoflow=False)) a.fill([0, 0, 1, 2]) a.fill((1, 0, 2, 2)) self.assertEqual(a.value(0), 3) @@ -742,7 +742,7 @@ class test_histogram(unittest.TestCase): @unittest.skipUnless(have_numpy, "requires build with numpy-support") def test_fill_with_numpy_array_1(self): - a = histogram(integer_axis(0, 2, uoflow=True)) + a = histogram(integer(0, 2, uoflow=True)) v = numpy.array([-1, 0, 1, 2, 3, 4]) w = numpy.array([ 2, 3, 4, 5, 6, 7]) a.fill(v, weight=w) @@ -769,14 +769,14 @@ class test_histogram(unittest.TestCase): with self.assertRaises(ValueError): a.fill([1, 2], weight=[[1, 1], [2, 2]]) - a = histogram(integer_axis(0, 1, uoflow=False), - regular_axis(2, 0, 2, uoflow=False)) + a = histogram(integer(0, 1, uoflow=False), + regular(2, 0, 2, uoflow=False)) a.fill(numpy.array([[-1., -1.], [0., 1.], [1., 0.1]])) self.assertEqual(a.value(0, 0), 0) self.assertEqual(a.value(0, 1), 1) self.assertEqual(a.value(1, 0), 1) self.assertEqual(a.value(1, 1), 0) - a = histogram(integer_axis(0, 2, uoflow=False)) + a = histogram(integer(0, 2, uoflow=False)) a.fill([0, 0, 1, 2]) a.fill((1, 0, 2, 2)) self.assertEqual(a.value(0), 3)