1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#include "equal.hpp"
#include "pybind11.hpp"
#include <Minuit2/MnUserCovariance.h>
#include <vector>
namespace ROOT {
namespace Minuit2 {
bool operator==(const MnUserCovariance& a, const MnUserCovariance& b) {
return a.Nrow() == b.Nrow() && a.Data() == b.Data();
}
} // namespace Minuit2
} // namespace ROOT
namespace py = pybind11;
using namespace ROOT::Minuit2;
MnUserCovariance init(py::sequence seq, unsigned n) {
return MnUserCovariance{py::cast<std::vector<double>>(seq), n};
}
void bind_usercovariance(py::module m) {
py::class_<MnUserCovariance>(m, "MnUserCovariance")
.def(py::init(&init))
.def("__getitem__",
[](const MnUserCovariance& self, py::object args) {
const auto tup = py::cast<std::pair<int, int>>(args);
return self(tup.first, tup.second);
})
.def_property_readonly("nrow", &MnUserCovariance::Nrow)
.def(py::self == py::self)
.def(py::pickle(
[](const MnUserCovariance& self) {
return py::make_tuple(self.Data(), self.Nrow());
},
[](py::tuple tp) {
return MnUserCovariance(tp[0].cast<std::vector<double>>(),
tp[1].cast<double>());
}))
;
}
|