| 351 | } |
| 352 | |
| 353 | void register_histogram() { |
| 354 | bp::docstring_options dopt(true, true, false); |
| 355 | |
| 356 | bp::scope s = |
| 357 | bp::class_<pyhistogram, boost::shared_ptr<pyhistogram>>( |
| 358 | "histogram", "N-dimensional histogram for real-valued data.", bp::no_init) |
| 359 | .def("__init__", bp::raw_function(histogram_init), |
| 360 | ":param axis args: axis objects" |
| 361 | "\nPass one or more axis objects to configure the histogram.") |
| 362 | // shadowed C++ ctors |
| 363 | .def(bp::init<const pyhistogram&>()) |
| 364 | // .def(bp::init<pyhistogram &&>()) move-ctor doesn't work with boost.python |
| 365 | #ifdef HAVE_NUMPY |
| 366 | .add_property("__array_interface__", &bh::python_access::array_interface) |
| 367 | #endif |
| 368 | .add_property("dim", &pyhistogram::dim) |
| 369 | .def("axis", histogram_axis, bp::arg("i") = 0, |
| 370 | ":param int i: axis index" |
| 371 | "\n:return: corresponding axis object") |
| 372 | .def("__call__", bp::raw_function(histogram_call), |
| 373 | ":param double args: values (number must match dimension)" |
| 374 | "\n:keyword double weight: optional weight" |
| 375 | "\n" |
| 376 | "\nIf Numpy support is enabled, 1d-arrays can be passed " |
| 377 | "instead of" |
| 378 | "\nvalues, which must be equal in lenght. Arrays and values can" |
| 379 | "\nbe mixed arbitrarily in the same call.") |
| 380 | .def("__len__", &pyhistogram::size, |
| 381 | ":return: total number of bins, including under- and overflow") |
| 382 | .def("at", bp::raw_function(histogram_at), |
| 383 | ":param int args: indices of the bin (number must match " |
| 384 | "dimension)" |
| 385 | "\n:return: bin content") |
| 386 | .def("__getitem__", histogram_getitem, |
| 387 | ":param int args: indices of the bin (number must match " |
| 388 | "dimension)" |
| 389 | "\n:return: bin content") |
| 390 | .def("reduce_to", bp::raw_function(histogram_reduce_to), |
| 391 | ":param int args: indices of the axes in the reduced histogram" |
| 392 | "\n:return: reduced histogram with subset of axes") |
| 393 | .def("__iter__", bp::iterator<const pyhistogram>()) |
| 394 | .def("__repr__", histogram_repr, |
| 395 | ":return: string representation of the histogram") |
| 396 | .def(bp::self == bp::self) |
| 397 | .def(bp::self != bp::self) |
| 398 | .def(bp::self += bp::self) |
| 399 | .def(bp::self *= double()) |
| 400 | .def(bp::self * double()) |
| 401 | .def(double() * bp::self) |
| 402 | .def(bp::self + bp::self) |
| 403 | .def_pickle(bh::serialization_suite<pyhistogram>()); |
| 404 | |
| 405 | bp::class_<pyhistogram::element_type>( |
| 406 | "element", "Holds value and variance of bin count.", bp::init<double, double>()) |
| 407 | .add_property("value", element_value) |
| 408 | .add_property("variance", element_variance) |
| 409 | .def("__getitem__", element_getitem) |
| 410 | .def("__len__", element_len) |
no outgoing calls
no test coverage detected