mirror of
https://github.com/boostorg/histogram.git
synced 2026-01-29 19:42:12 +00:00
increase test coverage, simplify testing of python stuff, add support for tests which intentionally trigger an assert
This commit is contained in:
@@ -44,7 +44,7 @@ struct generic_iterator {
|
||||
}
|
||||
return iterable[idx++];
|
||||
}
|
||||
bp::object self() { return bp::object(*this); }
|
||||
generic_iterator& self() { return *this; }
|
||||
bp::object iterable;
|
||||
unsigned idx = 0;
|
||||
unsigned size = 0;
|
||||
@@ -271,7 +271,7 @@ void register_axis_types() {
|
||||
docstring_options dopt(true, true, false);
|
||||
|
||||
class_<generic_iterator>("generic_iterator", init<object>())
|
||||
.def("__iter__", &generic_iterator::self)
|
||||
.def("__iter__", &generic_iterator::self, return_internal_reference<>())
|
||||
.def("__next__", &generic_iterator::next) // Python3
|
||||
.def("next", &generic_iterator::next) // Python2
|
||||
;
|
||||
|
||||
@@ -384,19 +384,7 @@ std::string element_repr(const pyhistogram::element_type& e) {
|
||||
void register_histogram() {
|
||||
bp::docstring_options dopt(true, true, false);
|
||||
|
||||
bp::class_<pyhistogram::element_type>(
|
||||
"element", "Holds value and variance of bin count.", bp::init<double, double>())
|
||||
.add_property("value", element_value)
|
||||
.add_property("variance", element_variance)
|
||||
.def("__getitem__", element_getitem)
|
||||
.def("__len__", element_len)
|
||||
.def(bp::self + bp::self)
|
||||
.def(bp::self += bp::self)
|
||||
.def(bp::self += double())
|
||||
.def("__repr__", element_repr)
|
||||
;
|
||||
|
||||
bp::class_<pyhistogram, boost::shared_ptr<pyhistogram>>(
|
||||
bp::scope s = bp::class_<pyhistogram, boost::shared_ptr<pyhistogram>>(
|
||||
"histogram", "N-dimensional histogram for real-valued data.", bp::no_init)
|
||||
.def("__init__", bp::raw_function(histogram_init),
|
||||
":param axis args: axis objects"
|
||||
@@ -430,6 +418,7 @@ void register_histogram() {
|
||||
.def("__repr__", histogram_repr,
|
||||
":return: string representation of the histogram")
|
||||
.def(bp::self == bp::self)
|
||||
.def(bp::self != bp::self)
|
||||
.def(bp::self += bp::self)
|
||||
.def(bp::self *= double())
|
||||
.def(bp::self * double())
|
||||
@@ -437,4 +426,21 @@ void register_histogram() {
|
||||
.def(bp::self + bp::self)
|
||||
.def_pickle(bh::serialization_suite<pyhistogram>())
|
||||
;
|
||||
|
||||
bp::class_<pyhistogram::element_type>(
|
||||
"element", "Holds value and variance of bin count.",
|
||||
bp::init<double, double>())
|
||||
.add_property("value", element_value)
|
||||
.add_property("variance", element_variance)
|
||||
.def("__getitem__", element_getitem)
|
||||
.def("__len__", element_len)
|
||||
.def(bp::self == bp::self)
|
||||
.def(bp::self != bp::self)
|
||||
.def(bp::self += bp::self)
|
||||
.def(bp::self += double())
|
||||
.def(bp::self + bp::self)
|
||||
.def(bp::self + double())
|
||||
.def(double() + bp::self)
|
||||
.def("__repr__", element_repr)
|
||||
;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <boost/python/scope.hpp>
|
||||
#include <boost/python/object.hpp>
|
||||
#ifdef HAVE_NUMPY
|
||||
#include <boost/python/numpy.hpp>
|
||||
# include <boost/python/numpy.hpp>
|
||||
#endif
|
||||
|
||||
void register_axis_types();
|
||||
@@ -16,10 +16,13 @@ void register_histogram();
|
||||
|
||||
BOOST_PYTHON_MODULE(histogram) {
|
||||
using namespace boost::python;
|
||||
scope current;
|
||||
#ifdef HAVE_NUMPY
|
||||
numpy::initialize();
|
||||
current.attr("HAVE_NUMPY") = true;
|
||||
#else
|
||||
current.attr("HAVE_NUMPY") = false;
|
||||
#endif
|
||||
scope current;
|
||||
object axis_module = object(
|
||||
borrowed(PyImport_AddModule("histogram.axis"))
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user