Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ellips] py binding: C++ cast of AnalyticFunction py objects #162

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions python/src/core/domains/ellipsoid/codac2_py_Ellipsoid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <pybind11/stl.h>
#include <codac2_Ellipsoid.h>
#include "codac2_py_Ellipsoid_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py):
#include "codac2_py_AnalyticFunction.h"

using namespace std;
using namespace codac2;
Expand Down Expand Up @@ -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<VectorOpValue>&))&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<VectorOpValue>&,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)

Expand Down
16 changes: 16 additions & 0 deletions python/src/core/functions/analytic/codac2_py_AnalyticFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ using namespace codac2;
namespace py = pybind11;
using namespace pybind11::literals;

inline AnalyticFunction<VectorOpValue> pyobject_to_AnalyticFunction(py::object f)
{
if(py::isinstance<AnalyticFunction<VectorOpValue>>(f))
return f.cast<AnalyticFunction<VectorOpValue>>();

else
{
// Trying to extract an AnalyticFunction<VectorOpValue>
// from the python wrapper 'AnalyticFunction'
py::object f_ = f.attr("f");
if(!py::isinstance<AnalyticFunction<VectorOpValue>>(f_))
assert_release("invalid argument: AnalyticFunction<VectorOpValue> expected");
return f_.cast<AnalyticFunction<VectorOpValue>>();
}
}

#define bind_(exported, op_name, op, doc) \
\
exported \
Expand Down
Loading