diff --git a/python/src/core/domains/ellipsoid/codac2_py_Ellipsoid.cpp b/python/src/core/domains/ellipsoid/codac2_py_Ellipsoid.cpp index e1784a10..404f2034 100644 --- a/python/src/core/domains/ellipsoid/codac2_py_Ellipsoid.cpp +++ b/python/src/core/domains/ellipsoid/codac2_py_Ellipsoid.cpp @@ -13,6 +13,7 @@ #include #include #include "codac2_py_Ellipsoid_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py): +#include "codac2_py_AnalyticFunction.h" using namespace std; using namespace codac2; @@ -80,11 +81,17 @@ void export_Ellipsoid(py::module& m) ELLIPSOID_UNRELIABLE_LINEAR_MAPPING_CONST_ELLIPSOID_REF_CONST_MATRIX_REF_CONST_VECTOR_REF, "e"_a, "A"_a, "b"_a) - .def("nonlinear_mapping_", (Ellipsoid (*)(const Ellipsoid&,const AnalyticFunction&))&codac2::nonlinear_mapping, + .def("nonlinear_mapping", [](const Ellipsoid& e, py::object f) + { + return nonlinear_mapping(e, pyobject_to_AnalyticFunction(f)); + }, ELLIPSOID_NONLINEAR_MAPPING_CONST_ELLIPSOID_REF_CONST_ANALYTICFUNCTION_VECTOROPVALUE_REF, "e"_a, "f"_a) - .def("nonlinear_mapping_", (Ellipsoid (*)(const Ellipsoid&,const AnalyticFunction&,const Vector&,const Vector&))&codac2::nonlinear_mapping, + .def("nonlinear_mapping", [](const Ellipsoid& e, py::object f, const Vector &trig, const Vector &q) + { + return nonlinear_mapping(e, pyobject_to_AnalyticFunction(f), trig, q); + }, ELLIPSOID_NONLINEAR_MAPPING_CONST_ELLIPSOID_REF_CONST_ANALYTICFUNCTION_VECTOROPVALUE_REF_CONST_VECTOR_REF_CONST_VECTOR_REF, "e"_a, "f"_a, "trig"_a, "q"_a) diff --git a/python/src/core/functions/analytic/codac2_py_AnalyticFunction.h b/python/src/core/functions/analytic/codac2_py_AnalyticFunction.h index 9dd8c75b..9647582b 100644 --- a/python/src/core/functions/analytic/codac2_py_AnalyticFunction.h +++ b/python/src/core/functions/analytic/codac2_py_AnalyticFunction.h @@ -25,6 +25,22 @@ using namespace codac2; namespace py = pybind11; using namespace pybind11::literals; +inline AnalyticFunction pyobject_to_AnalyticFunction(py::object f) +{ + if(py::isinstance>(f)) + return f.cast>(); + + else + { + // Trying to extract an AnalyticFunction + // from the python wrapper 'AnalyticFunction' + py::object f_ = f.attr("f"); + if(!py::isinstance>(f_)) + assert_release("invalid argument: AnalyticFunction expected"); + return f_.cast>(); + } +} + #define bind_(exported, op_name, op, doc) \ \ exported \