| 281 | } |
| 282 | |
| 283 | bp::object histogram_getitem(const pyhistogram& self, bp::object args) { |
| 284 | bp::extract<int> get_int(args); |
| 285 | if (get_int.check()) { |
| 286 | if (self.dim() == 1) { return bp::object(self[get_int()]); } |
| 287 | throw std::invalid_argument("wrong number of arguments"); |
| 288 | } |
| 289 | |
| 290 | const unsigned dim = bp::len(args); |
| 291 | if (self.dim() != dim) { throw std::invalid_argument("wrong number of arguments"); } |
| 292 | |
| 293 | if (dim > BOOST_HISTOGRAM_AXIS_LIMIT) { |
| 294 | throw std::invalid_argument( |
| 295 | bh::detail::cat("too many arguments, maximum is ", BOOST_HISTOGRAM_AXIS_LIMIT) |
| 296 | .c_str()); |
| 297 | } |
| 298 | |
| 299 | int idx[BOOST_HISTOGRAM_AXIS_LIMIT]; |
| 300 | for (std::size_t i = 0; i < dim; ++i) idx[i] = bp::extract<int>(args[i]); |
| 301 | |
| 302 | return bp::object(self.at(span<int>{idx, self.dim()})); |
| 303 | } |
| 304 | |
| 305 | bp::object histogram_at(bp::tuple args, bp::dict kwargs) { |
| 306 | if (kwargs) { throw std::invalid_argument("no keyword arguments allowed"); } |
no test coverage detected