all tests pass

This commit is contained in:
Hans Dembinski
2018-08-13 01:24:41 +02:00
parent 826dfaddb6
commit d4b1715451
18 changed files with 52 additions and 80 deletions

View File

@@ -146,7 +146,7 @@ bp::str axis_get_label(const T& t) {
template <typename A>
bp::object axis_getitem(const A& a, int i) {
if (i < -1 * a.uoflow() || i >= a.size() + 1 * a.uoflow())
if (i < -(a.uoflow() == 2) || i >= (a.size() + int(a.uoflow() > 0)))
throw std::out_of_range("index out of bounds");
return bp::make_tuple(a.lower(i), a.lower(i + 1));
}

View File

@@ -316,9 +316,6 @@ bp::object histogram_reduce_to(bp::tuple args, bp::dict kwargs) {
const auto nargs = bp::len(args) - 1;
if (nargs == 0) { throw std::invalid_argument("at least one argument required"); }
if (nargs < self.dim()) {
throw std::invalid_argument("fewer arguments than histogram axes required");
}
if (nargs > BOOST_HISTOGRAM_AXIS_LIMIT) {
throw std::invalid_argument(
@@ -327,7 +324,11 @@ bp::object histogram_reduce_to(bp::tuple args, bp::dict kwargs) {
}
int idx[BOOST_HISTOGRAM_AXIS_LIMIT];
for (auto i = 0u; i < nargs; ++i) idx[i] = bp::extract<int>(args[1 + i]);
for (auto i = 0u; i < nargs; ++i) {
idx[i] = bp::extract<int>(args[1 + i]);
if (i > 0 && idx[i] <= idx[i - 1])
throw std::invalid_argument("indices must be strictly ascending");
}
return bp::object(self.reduce_to(idx, idx + nargs));
}

View File

@@ -7,6 +7,7 @@
#include <boost/python/module.hpp>
#include <boost/python/object.hpp>
#include <boost/python/scope.hpp>
#include <stdexcept>
#ifdef HAVE_NUMPY
#include <boost/python/numpy.hpp>
#endif
@@ -16,6 +17,10 @@ void register_histogram();
BOOST_PYTHON_MODULE(histogram) {
using namespace boost::python;
register_exception_translator<std::out_of_range>(
[](const std::out_of_range& e) { PyErr_SetString(PyExc_IndexError, e.what()); });
scope current;
#ifdef HAVE_NUMPY
numpy::initialize();