aligator  0.14.0
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
expose-cartesian-product.cpp
Go to the documentation of this file.
3
4namespace aligator::python {
5
9using context::ConstVectorRef;
10using context::VectorRef;
11using context::VectorXs;
13
14std::vector<VectorXs> copy_vec_constref(const std::vector<ConstVectorRef> &x) {
15 std::vector<VectorXs> out;
16 for (const auto &c : x)
17 out.push_back(c);
18 return out;
19}
20
22 const std::string split_doc =
23 "Takes an point on the product manifold and splits it up between the two "
24 "base manifolds.";
25 const std::string split_vec_doc =
26 "Takes a tangent vector on the product manifold and splits it up.";
27
28 using MutSplitSig =
29 std::vector<VectorRef> (CartesianProduct::*)(VectorRef) const;
30
31 bp::class_<CartesianProduct, bp::bases<Manifold>>(
32 "CartesianProduct", "Cartesian product of two or more manifolds.",
33 bp::no_init)
34 .def(bp::init<>("self"_a))
35 .def(bp::init<const std::vector<PolymorphicManifold> &>(
36 ("self"_a, "spaces")))
37 .def(bp::init<PolymorphicManifold, PolymorphicManifold>(
38 ("self"_a, "left", "right")))
39 .def(
40 "getComponent",
41 +[](CartesianProduct const &m, std::size_t i) -> const Manifold & {
42 if (i >= m.numComponents()) {
43 PyErr_SetString(PyExc_IndexError, "Index out of bounds.");
44 bp::throw_error_already_set();
45 }
46 return m.getComponent(i);
47 },
48 bp::return_internal_reference<>(), ("self"_a, "i"),
49 "Get the i-th component of the Cartesian product.")
51 ("self"_a, "c"), "Add a component to the Cartesian product.")
52 .add_property("num_components", &CartesianProduct::numComponents,
53 "Get the number of components in the Cartesian product.")
54 .def(
55 "split",
56 +[](CartesianProduct const &m, const ConstVectorRef &x) {
57 return copy_vec_constref(m.split(x));
58 },
59 ("self"_a, "x"), split_doc.c_str())
60 .def<MutSplitSig>(
61 "split", &CartesianProduct::split, ("self"_a, "x"),
62 (split_doc +
63 " This returns a list of mutable references to each component.")
64 .c_str())
65 .def(
66 "split_vector",
67 +[](CartesianProduct const &m, const ConstVectorRef &x) {
69 },
70 ("self"_a, "v"), split_vec_doc.c_str())
71 .def<MutSplitSig>(
72 "split_vector", &CartesianProduct::split_vector, ("self"_a, "v"),
73 (split_vec_doc +
74 " This returns a list of mutable references to each component.")
75 .c_str())
76 .def("merge", &CartesianProduct::merge, ("self"_a, "xs"),
77 "Define a point on the manifold by merging points from each "
78 "component.")
79 .def("merge_vector", &CartesianProduct::merge_vector, ("self"_a, "vs"),
80 "Define a tangent vector on the manifold by merging vectors from "
81 "each component.")
82 .def(
83 "__mul__", +[](const CartesianProduct &a,
84 const CartesianProduct &b) { return a * b; })
86}
87
88} // namespace aligator::python
ManifoldAbstractTpl< Scalar > Manifold
Definition context.hpp:14
The Python bindings.
Definition blk-matrix.hpp:5
std::vector< VectorXs > copy_vec_constref(const std::vector< ConstVectorRef > &x)
CartesianProductTpl< Scalar > CartesianProduct
xyz::polymorphic< Manifold > PolymorphicManifold
The cartesian product of two or more manifolds.
const Base & getComponent(std::size_t i) const
std::vector< VectorRef > split_vector(VectorRef v) const
std::vector< VectorRef > split(VectorRef x) const
VectorXs merge(const std::vector< VectorXs > &xs) const
VectorXs merge_vector(const std::vector< VectorXs > &vs) const