proxsuite-nlp  0.10.0
A primal-dual augmented Lagrangian-type solver for nonlinear programming on manifolds.
Loading...
Searching...
No Matches
expose-cartesian-product.cpp
Go to the documentation of this file.
2
5
6namespace proxsuite {
7namespace nlp {
8namespace python {
9
11using context::Scalar;
13using context::ConstVectorRef;
14using context::VectorRef;
15using context::VectorXs;
17
18std::vector<VectorXs> copy_vec_constref(const std::vector<ConstVectorRef> &x) {
19 std::vector<VectorXs> out;
20 for (const auto &c : x)
21 out.push_back(c);
22 return out;
23}
24
26 const std::string split_doc =
27 "Takes an point on the product manifold and splits it up between the two "
28 "base manifolds.";
29 const std::string split_vec_doc =
30 "Takes a tangent vector on the product manifold and splits it up.";
31
32 using MutSplitSig =
33 std::vector<VectorRef> (CartesianProduct::*)(VectorRef) const;
34
35 bp::class_<CartesianProduct, bp::bases<Manifold>>(
36 "CartesianProduct", "Cartesian product of two or more manifolds.",
37 bp::no_init)
38 .def(bp::init<>("self"_a))
39 .def(bp::init<const std::vector<PolymorphicManifold> &>(
40 ("self"_a, "spaces")))
41 .def(bp::init<PolymorphicManifold, PolymorphicManifold>(
42 ("self"_a, "left", "right")))
43 .def(
44 "getComponent",
45 +[](CartesianProduct const &m, std::size_t i) -> const Manifold & {
46 if (i >= m.numComponents()) {
47 PyErr_SetString(PyExc_IndexError, "Index out of bounds.");
48 bp::throw_error_already_set();
49 }
50 return m.getComponent(i);
51 },
52 bp::return_internal_reference<>(), ("self"_a, "i"),
53 "Get the i-th component of the Cartesian product.")
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 python
93} // namespace nlp
94} // namespace proxsuite
std::vector< VectorXs > copy_vec_constref(const std::vector< ConstVectorRef > &x)
Main package namespace.
Definition bcl-params.hpp:5
The cartesian product of two or more manifolds.
std::vector< VectorRef > split(VectorRef x) const
VectorXs merge_vector(const std::vector< VectorXs > &vs) const
VectorXs merge(const std::vector< VectorXs > &xs) const
std::vector< VectorRef > split_vector(VectorRef v) const
const Base & getComponent(std::size_t i) const