MCPcopy Create free account
hub / github.com/boostorg/histogram / histogram_getitem

Function histogram_getitem

src/python/histogram.cpp:283–303  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

281}
282
283bp::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
305bp::object histogram_at(bp::tuple args, bp::dict kwargs) {
306 if (kwargs) { throw std::invalid_argument("no keyword arguments allowed"); }

Callers 1

histogram_atFunction · 0.85

Calls 3

catFunction · 0.85
atMethod · 0.80
dimMethod · 0.45

Tested by

no test coverage detected