proxsuite-nlp  0.11.0
A primal-dual augmented Lagrangian-type solver for nonlinear programming on manifolds.
 
Loading...
Searching...
No Matches
expose-function.cpp
1#include "proxsuite-nlp/python/function.hpp"
4
5namespace proxsuite {
6namespace nlp {
7namespace python {
8using context::C1Function;
9using context::C2Function;
10using context::ConstVectorRef;
11using context::Function;
12using context::Manifold;
13using context::Scalar;
14
15void exposeFunctionOps();
16
17void exposeFunctionTypes() {
18
19 bp::class_<FunctionWrap, boost::noncopyable>(
20 "BaseFunction", "Base class for functions.", bp::no_init)
21 .def(bp::init<const Manifold &, const int>(
22 bp::args("self", "manifold", "nr")))
23 .def(bp::init<int, int, int>(bp::args("self", "nx", "ndx", "nr")))
24 .def("__call__", bp::pure_virtual(&Function::operator()),
25 bp::args("self", "x"), "Call the function.")
26 .add_property("nx", &Function::nx, "Input dimension")
27 .add_property("ndx", &Function::ndx, "Input tangent space dimension.")
28 .add_property("nr", &Function::nr, "Function codimension.");
29
30 context::MatFuncType C1Function::*compJac1 = &C1Function::computeJacobian;
31 context::MatFuncRetType C1Function::*compJac2 = &C1Function::computeJacobian;
32
33 bp::class_<C1FunctionWrap, bp::bases<Function>, boost::noncopyable>(
34 "C1Function", "Base class for differentiable functions", bp::no_init)
35 .def(bp::init<const Manifold &, const int>(
36 bp::args("self", "manifold", "nr")))
37 .def(bp::init<int, int, int>(bp::args("self", "nx", "ndx", "nr")))
38 .def("computeJacobian", bp::pure_virtual(compJac1),
39 bp::args("self", "x", "Jout"))
40 .def("getJacobian", compJac2, bp::args("self", "x"),
41 "Compute and return Jacobian.");
42
43 bp::register_ptr_to_python<shared_ptr<C2Function>>();
44 bp::class_<C2FunctionWrap, bp::bases<C1Function>, boost::noncopyable>(
45 "C2Function", "Base class for twice-differentiable functions.",
46 bp::no_init)
47 .def(bp::init<const Manifold &, const int>(
48 bp::args("self", "manifold", "nr")))
49 .def(bp::init<int, int, int>(bp::args("self", "nx", "ndx", "nr")))
50 .def("vectorHessianProduct", &C2Function::vectorHessianProduct,
51 &C2FunctionWrap::default_vhp, bp::args("self", "x", "v", "Hout"))
52 .def("getVHP", &C2FunctionWrap::getVHP, bp::args("self", "x", "v"),
53 "Compute and return the vector-Hessian product.")
54 .def(
55 "__matmul__",
56 +[](shared_ptr<C2Function> const &left,
57 shared_ptr<C2Function> const &right) {
58 return ::proxsuite::nlp::compose<Scalar>(left, right);
59 },
60 "Composition operator. This composes the first argument over the "
61 "second one.");
62
63 exposeFunctionOps();
64}
65
66void exposeFunctionOps() {
67 using ComposeFunction = ComposeFunctionTpl<Scalar>;
68
69 const char *compose_doc = "Composition of two functions. This returns the "
70 "composition of `f` over `g`.";
71 bp::register_ptr_to_python<shared_ptr<ComposeFunction>>();
72 bp::class_<ComposeFunction, bp::bases<C2Function>>("ComposeFunction",
73 compose_doc, bp::no_init)
74 .def(bp::init<const shared_ptr<C2Function> &,
75 const shared_ptr<C2Function> &>(bp::args("self", "f", "g")))
76 .add_property("left",
77 bp::make_function(&ComposeFunction::left,
78 bp::return_internal_reference<>()),
79 "The left-hand side of the composition.")
80 .add_property("right",
81 bp::make_function(&ComposeFunction::right,
82 bp::return_internal_reference<>()),
83 "The right-hand side of the composition.");
84
85 bp::def("compose", &::proxsuite::nlp::compose<context::Scalar>,
86 bp::args("f", "g"), compose_doc);
87}
88
89} // namespace python
90} // namespace nlp
91} // namespace proxsuite
Main package namespace.
Definition bcl-params.hpp:5
virtual void computeJacobian(const ConstVectorRef &x, MatrixRef Jout) const=0
virtual void vectorHessianProduct(const ConstVectorRef &, const ConstVectorRef &, MatrixRef Hout) const