25#include <pybind11/pybind11.h>
27#include <pybind11/stl.h>
33using namespace pybind11::literals;
41template <
typename ReturnT>
42void declareFunction(lsst::utils::python::WrapperCollection &wrappers,
std::string const &suffix) {
43 auto const name =
"Function" + suffix;
45 py::class_<Function<ReturnT>,
std::shared_ptr<Function<ReturnT>>>(wrappers.module,
name.c_str()),
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 =
"");
62template <
typename ReturnT>
63void declareFunction1(lsst::utils::python::WrapperCollection &wrappers,
const std::string &suffix) {
64 auto const name =
"Function1" + suffix;
66 wrappers.wrapType(
PyClass(wrappers.module,
name.c_str()), [](
auto &mod,
auto &cls) {
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);
76template <
typename ReturnT>
77void declareFunction2(lsst::utils::python::WrapperCollection &wrappers,
const std::string &suffix) {
78 auto const name =
"Function2" + suffix;
80 wrappers.wrapType(
PyClass(wrappers.module,
name.c_str()), [](
auto &mod,
auto &cls) {
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);
90template <
typename ReturnT>
91void 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);
107template <
typename ReturnT>
108void declareNullFunction1(lsst::utils::python::WrapperCollection &wrappers,
const std::string &suffix) {
109 auto const name =
"NullFunction1" + suffix;
112 wrappers.wrapType(
PyClass(wrappers.module,
name.c_str()), [](
auto &mod,
auto &cls) {
113 cls.def(py::init<>());
115 cls.def(
"clone", &NullFunction1<ReturnT>::clone);
119template <
typename ReturnT>
120void declareNullFunction2(lsst::utils::python::WrapperCollection &wrappers,
const std::string &suffix) {
121 auto const name =
"NullFunction2" + suffix;
124 wrappers.wrapType(
PyClass(wrappers.module,
name.c_str()), [](
auto &mod,
auto &cls) {
125 cls.def(py::init<>());
126 cls.def(
"clone", &NullFunction2<ReturnT>::clone);
130template <
typename ReturnT>
131void declareAllFunctions(lsst::utils::python::WrapperCollection &wrappers,
const std::string &suffix) {
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);
143 wrappers.addSignatureDependency(
"lsst.afw.table.io");
144 declareAllFunctions<float>(wrappers,
"F");
145 declareAllFunctions<double>(wrappers,
"D");
table::Key< std::string > name
void wrapFunction(lsst::utils::python::WrapperCollection &wrappers)
py::class_< PixelAreaBoundedField, std::shared_ptr< PixelAreaBoundedField >, BoundedField > PyClass