aligator  0.9.0
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
expose-function-ops.cpp
Go to the documentation of this file.
1
3
5
8
9namespace aligator {
10namespace python {
11
12using context::MatrixXs;
13using context::Scalar;
17using context::VectorXs;
18
19const PolymorphicMultiBaseVisitor<StageFunction> func_visitor;
21
22template <typename Base> void exposeSliceExpression(const char *name) {
23 // FUNCTION SLICE
24
25 using FunctionSliceXpr = FunctionSliceXprTpl<Scalar, Base>;
26
27 bp::class_<FunctionSliceXpr, bp::bases<Base>>(
28 name,
29 "Represents a slice of an expression according to either a single index "
30 "or an array of indices.",
31 bp::init<xyz::polymorphic<Base>, std::vector<int> const &>(
32 bp::args("self", "func", "indices")))
33 .def(func_visitor)
34 .def(bp::init<xyz::polymorphic<Base>, const int>(
35 "Constructor from a single index.", bp::args("self", "func", "idx")))
36 .def_readonly("func", &FunctionSliceXpr::func, "Underlying function.")
37 .def_readonly("indices", &FunctionSliceXpr::indices,
38 "Indices of the slice.");
39}
40
41template <typename LFC>
43 : bp::def_visitor<LinFunctionCompositionVisitor<LFC>> {
44 using FunType = typename LFC::Base;
45
46 template <class PyClass> void visit(PyClass &cl) const {
47 cl.def(bp::init<xyz::polymorphic<FunType>, const MatrixXs, const VectorXs>(
48 "Construct a composition from the underlying function, weight "
49 "matrix "
50 ":math:`A` and bias :math:`b`.",
51 bp::args("self", "func", "A", "b")))
52 .def(bp::init<xyz::polymorphic<FunType>, const context::MatrixXs>(
53 "Constructor where the bias :math:`b` is assumed to be zero.",
54 bp::args("self", "func", "A")))
55 .def_readonly("func", &LFC::func, "The underlying function.")
56 .def_readonly("A", &LFC::A, "Weight matrix.")
57 .def_readonly("b", &LFC::b, "Bias vector.");
58 bp::class_<typename LFC::Data, bp::bases<StageFunctionData>,
59 boost::noncopyable>("LFC", bp::no_init)
60 .def_readonly("sub_data", &LFC::Data::sub_data);
61
62 bp::def(
63 "linear_compose",
64 +[](xyz::polymorphic<FunType> func, const MatrixXs &A,
65 const VectorXs &b) { return linear_compose(func, A, b); },
66 bp::args("func", "A", "b"));
67 }
68};
69
71
72 exposeSliceExpression<StageFunction>("StageFunctionSliceXpr");
73 exposeSliceExpression<UnaryFunction>("UnaryFunctionSliceXpr");
74
75 using FunctionSliceData = FunctionSliceDataTpl<Scalar>;
76 bp::class_<FunctionSliceData, bp::bases<StageFunctionData>,
77 boost::noncopyable>("FunctionSliceData", bp::no_init)
78 .def_readonly("sub_data", &FunctionSliceData::sub_data,
79 "Underlying function's data.");
80
82
83 using LinearFunctionComposition = LinearFunctionCompositionTpl<Scalar>;
84 using LinearUnaryFunctionComposition =
86
87 bp::class_<LinearFunctionComposition, bp::bases<StageFunction>>(
88 "LinearFunctionComposition",
89 "Function composition :math:`r(x) = Af(x, u, y) + b`.", bp::no_init)
91 .def(func_visitor);
92
93 bp::class_<LinearUnaryFunctionComposition, bp::bases<UnaryFunction>>(
94 "LinearUnaryFunctionComposition",
95 "Function composition for unary functions: :math:`r(x) = Af(x) + b`.",
96 bp::no_init)
98 .def(unary_visitor);
99}
100
101} // namespace python
102} // namespace aligator
StageFunctionTpl< Scalar > StageFunction
Definition context.hpp:16
UnaryFunctionTpl< Scalar > UnaryFunction
Definition context.hpp:17
StageFunctionDataTpl< Scalar > StageFunctionData
Definition context.hpp:18
void exposeSliceExpression(const char *name)
const PolymorphicMultiBaseVisitor< UnaryFunction, StageFunction > unary_visitor
PolymorphicMultiBaseVisitor< StageFunction > func_visitor
Main package namespace.
auto linear_compose(xyz::polymorphic< StageFunctionTpl< Scalar > > func, const typename math_types< Scalar >::ConstMatrixRef A, const typename math_types< Scalar >::ConstVectorRef b)
Create a linear composition of the input function func.
Represents a function of which the output is a subset of another function, for instance where is gi...