aligator  0.16.0
A versatile and efficient C++ library for real-time constrained trajectory optimization.
Loading...
Searching...
No Matches
expose-cartesian-product.cpp
Go to the documentation of this file.
3
4namespace aligator::python {
5
8using PolymorphicManifold = xyz::polymorphic<Manifold>;
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 +[](const CartesianProduct &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.")
50 .def(
51 "addComponent",
52 +[](CartesianProduct &m, const PolymorphicManifold &c) {
53 m.addComponent(c);
54 },
55 ("self"_a, "c"), "Add a component to the Cartesian product.")
56 .add_property("num_components", &CartesianProduct::numComponents,
57 "Get the number of components in the Cartesian product.")
58 .def(
59 "split",
60 +[](CartesianProduct const &m, const ConstVectorRef &x) {
61 return copy_vec_constref(m.split(x));
62 },
63 ("self"_a, "x"), split_doc.c_str())
64 .def<MutSplitSig>(
65 "split", &CartesianProduct::split, ("self"_a, "x"),
66 (split_doc +
67 " This returns a list of mutable references to each component.")
68 .c_str())
69 .def(
70 "split_vector",
71 +[](CartesianProduct const &m, const ConstVectorRef &x) {
73 },
74 ("self"_a, "v"), split_vec_doc.c_str())
75 .def<MutSplitSig>(
76 "split_vector", &CartesianProduct::split_vector, ("self"_a, "v"),
77 (split_vec_doc +
78 " This returns a list of mutable references to each component.")
79 .c_str())
80 .def("merge", &CartesianProduct::merge, ("self"_a, "xs"),
81 "Define a point on the manifold by merging points from each "
82 "component.")
83 .def("merge_vector", &CartesianProduct::merge_vector, ("self"_a, "vs"),
84 "Define a tangent vector on the manifold by merging vectors from "
85 "each component.")
86 .def(
87 "__mul__", +[](const CartesianProduct &a,
88 const CartesianProduct &b) { return a * b; })
90}
91
92} // 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
void addComponent(const Concrete &c)