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

Function histogram_call

src/python/histogram.cpp:212–281  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

210};
211
212bp::object histogram_call(bp::tuple args, bp::dict kwargs) {
213 const auto nargs = bp::len(args);
214 pyhistogram& self = bp::extract<pyhistogram&>(args[0]);
215
216 const unsigned dim = nargs - 1;
217 if (dim != self.dim()) {
218 throw std::invalid_argument("number of arguments and dimension do not match");
219 }
220
221 if (dim > BOOST_HISTOGRAM_AXIS_LIMIT) {
222 throw std::invalid_argument(
223 bh::detail::cat("too many arguments, maximum is ", BOOST_HISTOGRAM_AXIS_LIMIT)
224 .c_str());
225 }
226
227 fetcher<double> fetch[BOOST_HISTOGRAM_AXIS_LIMIT];
228 long n = 0;
229 for (auto d = 0u; d < dim; ++d) {
230 fetch[d].assign(args[1 + d]);
231 if (fetch[d].n > 0) {
232 if (n > 0 && fetch[d].n != n) {
233 throw std::invalid_argument("lengths of sequences do not match");
234 }
235 n = fetch[d].n;
236 }
237 }
238
239 fetcher<double> fetch_weight;
240 const auto nkwargs = bp::len(kwargs);
241 if (nkwargs > 0) {
242 const bool use_weight = kwargs.has_key("weight");
243 if (nkwargs > use_weight) { // only one keyword allowed: weight
244 throw std::invalid_argument("only keyword weight allowed");
245 }
246
247 if (use_weight) {
248 fetch_weight.assign(kwargs.get("weight"));
249 if (fetch_weight.n > 0) {
250 if (n > 0 && fetch_weight.n != n) {
251 throw std::invalid_argument("length of weight sequence does not match");
252 }
253 n = fetch_weight.n;
254 }
255 }
256 }
257
258 if (!n) ++n;
259 if (dim == 1) {
260 if (fetch_weight.n >= 0) {
261 for (auto i = 0l; i < n; ++i) self(bh::weight(fetch_weight[i]), fetch[0][i]);
262 } else {
263 for (auto i = 0l; i < n; ++i) self(fetch[0][i]);
264 }
265 } else {
266 double v[BOOST_HISTOGRAM_AXIS_LIMIT];
267 if (fetch_weight.n >= 0) {
268 for (auto i = 0l; i < n; ++i) {
269 for (auto d = 0u; d < dim; ++d) v[d] = fetch[d][i];

Callers

nothing calls this directly

Calls 5

catFunction · 0.85
weightFunction · 0.85
assignMethod · 0.80
getMethod · 0.80
dimMethod · 0.45

Tested by

no test coverage detected