24 #include "pybind11/pybind11.h"
26 #include "numpy/arrayobject.h"
27 #include "ndarray/pybind11.h"
29 #include "lsst/pex/config/python.h"
35 namespace py = pybind11;
36 using namespace pybind11::literals;
44 using PyPrior = py::class_<Prior, std::shared_ptr<Prior>>;
45 PyPrior cls(mod,
"Prior");
46 cls.def(
"getTag", &Prior::getTag);
47 cls.def(
"evaluate", &Prior::evaluate,
"nonlinear"_a,
"amplitudes"_a);
48 cls.def(
"evaluateDerivatives", &Prior::evaluateDerivatives,
"nonlinear"_a,
"amplitudes"_a,
49 "nonlinearGradient"_a,
"amplitudeGradient"_a,
"nonlinearHessian"_a,
"amplitudeHessian"_a,
51 cls.def(
"marginalize", &Prior::marginalize,
"gradient"_a,
"hessian"_a,
"nonlinear"_a);
52 cls.def(
"maximize", &Prior::maximize,
"gradient"_a,
"hessian"_a,
"nonlinear"_a,
"amplitudes"_a);
53 cls.def(
"drawAmplitudes", &Prior::drawAmplitudes,
"gradient"_a,
"hessian"_a,
"nonlinear"_a,
"rng"_a,
54 "amplitudes"_a,
"weights"_a,
"multiplyWeights"_a =
false);
57 static void declareMixturePrior(
py::module &mod) {
58 using Class = MixturePrior;
59 using PyClass = py::class_<Class, std::shared_ptr<Class>, Prior>;
60 PyClass cls(mod,
"MixturePrior");
61 cls.def(py::init<std::shared_ptr<Mixture>, std::string
const &>(),
"mixture"_a,
"tag"_a =
"");
62 cls.def_static(
"getUpdateRestriction", &Class::getUpdateRestriction,
63 py::return_value_policy::reference);
64 cls.def(
"getMixture", &Class::getMixture);
68 static void declareSemiEmpiricalPrior(
py::module &mod) {
69 using Class = SemiEmpiricalPrior;
70 using Control = SemiEmpiricalPriorControl;
71 using PyControl = py::class_<Control, std::shared_ptr<Control>>;
72 using PyClass = py::class_<Class, std::shared_ptr<Class>, Prior>;
74 PyControl clsControl(mod,
"SemiEmpiricalPriorControl");
75 clsControl.def(py::init<>());
76 LSST_DECLARE_CONTROL_FIELD(clsControl,
Control, ellipticitySigma);
77 LSST_DECLARE_CONTROL_FIELD(clsControl,
Control, ellipticityCore);
78 LSST_DECLARE_CONTROL_FIELD(clsControl,
Control, logRadiusMinOuter);
79 LSST_DECLARE_CONTROL_FIELD(clsControl,
Control, logRadiusMinInner);
80 LSST_DECLARE_CONTROL_FIELD(clsControl,
Control, logRadiusMu);
81 LSST_DECLARE_CONTROL_FIELD(clsControl,
Control, logRadiusSigma);
82 LSST_DECLARE_CONTROL_FIELD(clsControl,
Control, logRadiusNu);
83 clsControl.def(
"validate", &Control::validate);
85 PyClass cls(mod,
"SemiEmpiricalPrior");
86 cls.def(py::init<Control>(),
"ctrl"_a);
87 cls.attr(
"Control") = clsControl;
91 static void declareSoftenedLinearPrior(
py::module &mod) {
92 using Class = SoftenedLinearPrior;
93 using Control = SoftenedLinearPriorControl;
94 using PyControl = py::class_<Control, std::shared_ptr<Control>>;
95 using PyClass = py::class_<Class, std::shared_ptr<Class>, Prior>;
97 PyControl clsControl(mod,
"SoftenedLinearPriorControl");
98 clsControl.def(py::init<>());
99 LSST_DECLARE_CONTROL_FIELD(clsControl,
Control, ellipticityMaxOuter);
100 LSST_DECLARE_CONTROL_FIELD(clsControl,
Control, ellipticityMaxInner);
101 LSST_DECLARE_CONTROL_FIELD(clsControl,
Control, logRadiusMinOuter);
102 LSST_DECLARE_CONTROL_FIELD(clsControl,
Control, logRadiusMinInner);
103 LSST_DECLARE_CONTROL_FIELD(clsControl,
Control, logRadiusMaxOuter);
104 LSST_DECLARE_CONTROL_FIELD(clsControl,
Control, logRadiusMaxInner);
105 LSST_DECLARE_CONTROL_FIELD(clsControl,
Control, logRadiusMinMaxRatio);
107 PyClass cls(mod,
"SoftenedLinearPrior");
108 cls.def(py::init<Control>(),
"ctrl"_a);
109 cls.def(
"getControl", &Class::getControl, py::return_value_policy::copy);
110 cls.attr(
"Control") = clsControl;
114 PYBIND11_PLUGIN(priors) {
115 py::module::import(
"lsst.meas.modelfit.mixture");
119 if (_import_array() < 0) {
120 PyErr_SetString(PyExc_ImportError,
"numpy.core.multiarray failed to import");
125 declareMixturePrior(mod);
126 declareSemiEmpiricalPrior(mod);
127 declareSoftenedLinearPrior(mod);