1#include "proxsuite-nlp/modelling/spaces/cartesian-product.hpp"
3#include "proxsuite-nlp/python/fwd.hpp"
4#include "proxsuite-nlp/python/polymorphic.hpp"
10using context::Manifold;
12using PolymorphicManifold = polymorphic<Manifold>;
13using context::ConstVectorRef;
14using context::VectorRef;
15using context::VectorXs;
16using CartesianProduct = CartesianProductTpl<Scalar>;
18std::vector<VectorXs> copy_vec_constref(
const std::vector<ConstVectorRef> &x) {
19 std::vector<VectorXs> out;
20 for (
const auto &c : x)
25void exposeCartesianProduct() {
26 const std::string split_doc =
27 "Takes an point on the product manifold and splits it up between the two "
29 const std::string split_vec_doc =
30 "Takes a tangent vector on the product manifold and splits it up.";
33 std::vector<VectorRef> (CartesianProduct::*)(VectorRef)
const;
35 bp::class_<CartesianProduct, bp::bases<Manifold>>(
36 "CartesianProduct",
"Cartesian product of two or more manifolds.",
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")))
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();
50 return m.getComponent(i);
52 bp::return_internal_reference<>(), (
"self"_a,
"i"),
53 "Get the i-th component of the Cartesian product.")
54 .def(
"addComponent", &CartesianProduct::addComponent<PolymorphicManifold>,
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.")
60 +[](CartesianProduct
const &m,
const ConstVectorRef &x) {
61 return copy_vec_constref(m.split(x));
63 (
"self"_a,
"x"), split_doc.c_str())
65 "split", &CartesianProduct::split, (
"self"_a,
"x"),
67 " This returns a list of mutable references to each component.")
71 +[](CartesianProduct
const &m,
const ConstVectorRef &x) {
72 return copy_vec_constref(m.split_vector(x));
74 (
"self"_a,
"v"), split_vec_doc.c_str())
76 "split_vector", &CartesianProduct::split_vector, (
"self"_a,
"v"),
78 " This returns a list of mutable references to each component.")
80 .def(
"merge", &CartesianProduct::merge, (
"self"_a,
"xs"),
81 "Define a point on the manifold by merging points from each "
83 .def(
"merge_vector", &CartesianProduct::merge_vector, (
"self"_a,
"vs"),
84 "Define a tangent vector on the manifold by merging vectors from "
87 "__mul__", +[](
const CartesianProduct &a,
88 const CartesianProduct &b) {
return a * b; })