| 311 | } |
| 312 | |
| 313 | bp::object histogram_reduce_to(bp::tuple args, bp::dict kwargs) { |
| 314 | if (kwargs) { throw std::invalid_argument("no keyword arguments allowed"); } |
| 315 | const pyhistogram& self = bp::extract<const pyhistogram&>(args[0]); |
| 316 | |
| 317 | const auto nargs = bp::len(args) - 1; |
| 318 | if (nargs == 0) { throw std::invalid_argument("at least one argument required"); } |
| 319 | |
| 320 | if (nargs > BOOST_HISTOGRAM_AXIS_LIMIT) { |
| 321 | throw std::invalid_argument( |
| 322 | bh::detail::cat("too many arguments, maximum is ", BOOST_HISTOGRAM_AXIS_LIMIT) |
| 323 | .c_str()); |
| 324 | } |
| 325 | |
| 326 | int idx[BOOST_HISTOGRAM_AXIS_LIMIT]; |
| 327 | for (auto i = 0u; i < nargs; ++i) { |
| 328 | idx[i] = bp::extract<int>(args[1 + i]); |
| 329 | if (i > 0 && idx[i] <= idx[i - 1]) |
| 330 | throw std::invalid_argument("indices must be strictly ascending"); |
| 331 | } |
| 332 | |
| 333 | return bp::object(self.reduce_to(idx, idx + nargs)); |
| 334 | } |
| 335 | |
| 336 | std::string histogram_repr(const pyhistogram& h) { return bh::detail::cat(h); } |
| 337 | |