25 #include <pybind11/pybind11.h>
27 #include <pybind11/stl.h>
33 using namespace pybind11::literals;
41 template <
typename ReturnT>
43 auto const name =
"Function" + suffix;
46 [](
auto &mod,
auto &cls) {
47 cls.def(py::init<unsigned int>(),
"nParams"_a);
48 cls.def(py::init<std::vector<double> const &>(),
"params"_a);
50 table::io::python::addPersistableMethods<Function<ReturnT>>(cls);
52 cls.def(
"getNParameters", &Function<ReturnT>::getNParameters);
53 cls.def(
"getParameters", &Function<ReturnT>::getParameters, py::return_value_policy::copy);
54 cls.def(
"getParameter", &Function<ReturnT>::getParameter,
"index"_a);
55 cls.def(
"isLinearCombination", &Function<ReturnT>::isLinearCombination);
56 cls.def(
"setParameter", &Function<ReturnT>::setParameter,
"index"_a,
"value"_a);
57 cls.def(
"setParameters", &Function<ReturnT>::setParameters);
58 cls.def(
"toString", &Function<ReturnT>::toString,
"prefix"_a =
"");
62 template <
typename ReturnT>
64 auto const name =
"Function1" + suffix;
67 table::io::python::addPersistableMethods<Function1<ReturnT>>(cls);
69 cls.def(
"clone", &Function1<ReturnT>::clone);
70 cls.def(
"__call__", &Function1<ReturnT>::operator(),
"x"_a);
71 cls.def(
"toString", &Function1<ReturnT>::toString,
"prefix"_a =
"");
72 cls.def(
"computeCache", &Function1<ReturnT>::computeCache,
"n"_a);
76 template <
typename ReturnT>
78 auto const name =
"Function2" + suffix;
81 table::io::python::addPersistableMethods<Function2<ReturnT>>(cls);
83 cls.def(
"clone", &Function2<ReturnT>::clone);
84 cls.def(
"__call__", &Function2<ReturnT>::operator(),
"x"_a,
"y"_a);
85 cls.def(
"toString", &Function2<ReturnT>::toString,
"prefix"_a =
"");
86 cls.def(
"getDFuncDParameters", &Function2<ReturnT>::getDFuncDParameters,
"x"_a,
"y"_a);
90 template <
typename ReturnT>
91 void declareBasePolynomialFunction2(lsst ::utils::python::WrapperCollection &wrappers,
93 auto const name =
"BasePolynomialFunction2" + suffix;
94 using PyClass = py::class_<BasePolynomialFunction2<ReturnT>,
96 wrappers.wrapType(
PyClass(wrappers.module,
name.c_str()), [](
auto &mod,
auto &cls) {
97 cls.def(
"getOrder", &BasePolynomialFunction2<ReturnT>::getOrder);
98 cls.def(
"isLinearCombination", &BasePolynomialFunction2<ReturnT>::isLinearCombination);
99 cls.def_static(
"nParametersFromOrder", &BasePolynomialFunction2<ReturnT>::nParametersFromOrder,
101 cls.def_static(
"orderFromNParameters", &BasePolynomialFunction2<ReturnT>::orderFromNParameters,
103 cls.def(
"getDFuncDParameters", &BasePolynomialFunction2<ReturnT>::getDFuncDParameters,
"x"_a,
"y"_a);
107 template <
typename ReturnT>
109 auto const name =
"NullFunction1" + suffix;
113 cls.def(py::init<>());
115 cls.def(
"clone", &NullFunction1<ReturnT>::clone);
119 template <
typename ReturnT>
121 auto const name =
"NullFunction2" + suffix;
125 cls.def(py::init<>());
126 cls.def(
"clone", &NullFunction2<ReturnT>::clone);
130 template <
typename ReturnT>
132 declareFunction<ReturnT>(wrappers, suffix);
133 declareFunction1<ReturnT>(wrappers, suffix);
134 declareFunction2<ReturnT>(wrappers, suffix);
135 declareBasePolynomialFunction2<ReturnT>(wrappers, suffix);
136 declareNullFunction1<ReturnT>(wrappers, suffix);
137 declareNullFunction2<ReturnT>(wrappers, suffix);
144 declareAllFunctions<float>(wrappers,
"F");
145 declareAllFunctions<double>(wrappers,
"D");
table::Key< std::string > name
A helper class for subdividing pybind11 module across multiple translation units (i....
pybind11::module module
The module object passed to the PYBIND11_MODULE block that contains this WrapperCollection.
PyType wrapType(PyType cls, ClassWrapperCallback function, bool setModuleName=true)
Add a type (class or enum) wrapper, deferring method and other attribute definitions until finish() i...
void addSignatureDependency(std::string const &name)
Indicate an external module that provides a type used in function/method signatures.
void wrapFunction(lsst::utils::python::WrapperCollection &wrappers)
py::class_< PixelAreaBoundedField, std::shared_ptr< PixelAreaBoundedField >, BoundedField > PyClass
A base class for image defects.