aligator
0.19.0
A versatile and efficient C++ library for real-time constrained trajectory optimization.
Toggle main menu visibility
Loading...
Searching...
No Matches
expose-cartesian-product.cpp
Go to the documentation of this file.
1
#include "
aligator/python/fwd.hpp
"
2
#include "
aligator/modelling/spaces/cartesian-product.hpp
"
3
4
namespace
aligator::python
{
5
6
using
context::Manifold
;
7
using
context::Scalar
;
8
using
PolymorphicManifold
= xyz::polymorphic<Manifold>;
9
using
context::ConstVectorRef;
10
using
context::VectorRef;
11
using
context::VectorXs;
12
using
CartesianProduct
=
CartesianProductTpl<Scalar>
;
13
14
std::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
21
void
exposeCartesianProduct
() {
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) {
72
return
copy_vec_constref
(m.
split_vector
(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; })
89
.def(
PolymorphicVisitor<PolymorphicManifold>
());
90
}
91
92
}
// namespace aligator::python
fwd.hpp
cartesian-product.hpp
aligator::context::Manifold
ManifoldAbstractTpl< Scalar > Manifold
Definition
context.hpp:14
aligator::context::Scalar
double Scalar
Definition
context.hpp:9
aligator::python
The Python bindings.
Definition
blk-matrix.hpp:7
aligator::python::copy_vec_constref
std::vector< VectorXs > copy_vec_constref(const std::vector< ConstVectorRef > &x)
Definition
expose-cartesian-product.cpp:14
aligator::python::CartesianProduct
CartesianProductTpl< Scalar > CartesianProduct
Definition
expose-cartesian-product.cpp:12
aligator::python::exposeCartesianProduct
void exposeCartesianProduct()
Definition
expose-cartesian-product.cpp:21
aligator::python::PolymorphicManifold
xyz::polymorphic< Manifold > PolymorphicManifold
Definition
expose-cartesian-product.cpp:8
aligator::CartesianProductTpl
The cartesian product of two or more manifolds.
Definition
cartesian-product.hpp:13
aligator::CartesianProductTpl::getComponent
const Base & getComponent(std::size_t i) const
Definition
cartesian-product.hpp:22
aligator::CartesianProductTpl::split_vector
std::vector< VectorRef > split_vector(VectorRef v) const
Definition
cartesian-product.hpp:102
aligator::CartesianProductTpl::numComponents
std::size_t numComponents() const
Definition
cartesian-product.hpp:24
aligator::CartesianProductTpl::split
std::vector< VectorRef > split(VectorRef x) const
Definition
cartesian-product.hpp:93
aligator::CartesianProductTpl< Scalar >::merge
VectorXs merge(const std::vector< VectorXs > &xs) const
aligator::CartesianProductTpl< Scalar >::merge_vector
VectorXs merge_vector(const std::vector< VectorXs > &vs) const
aligator::CartesianProductTpl::addComponent
void addComponent(const Concrete &c)
Definition
cartesian-product.hpp:26
aligator::python::PolymorphicVisitor
Definition
polymorphic.hpp:30
bindings
python
src
expose-cartesian-product.cpp
Generated by
1.17.0