mirror of
https://github.com/boostorg/histogram.git
synced 2026-02-21 03:02:11 +00:00
all tests pass
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user