proxsuite-nlp  0.11.0
A primal-dual augmented Lagrangian-type solver for nonlinear programming on manifolds.
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Loading...
Searching...
No Matches
cartesian-product.hxx
1#pragma once
2
3#include "proxsuite-nlp/modelling/spaces/cartesian-product.hpp"
4
5namespace proxsuite {
6namespace nlp {
7
8template <typename Scalar>
9auto CartesianProductTpl<Scalar>::neutral() const -> VectorXs {
10 VectorXs out(this->nx());
11 Eigen::Index c = 0;
12 for (std::size_t i = 0; i < numComponents(); i++) {
13 const long n = m_components[i]->nx();
14 out.segment(c, n) = m_components[i]->neutral();
15 c += n;
16 }
17 return out;
18}
19
20template <typename Scalar>
21auto CartesianProductTpl<Scalar>::rand() const -> VectorXs {
22 VectorXs out(this->nx());
23 Eigen::Index c = 0;
24 for (std::size_t i = 0; i < numComponents(); i++) {
25 const long n = m_components[i]->nx();
26 out.segment(c, n) = m_components[i]->rand();
27 c += n;
28 }
29 return out;
30}
31
32template <typename Scalar>
33bool CartesianProductTpl<Scalar>::isNormalized(const ConstVectorRef &x) const {
34 bool res = true;
35 auto xs = this->split(x);
36 for (std::size_t i = 0; i < numComponents(); i++) {
37 res |= m_components[i]->isNormalized(xs[i]);
38 }
39 return res;
40}
41
42template <typename Scalar>
43template <class VectorType, class U>
44std::vector<U> CartesianProductTpl<Scalar>::split_impl(VectorType &x) const {
45 PROXSUITE_NLP_DIM_CHECK(x, this->nx());
46 std::vector<U> out;
47 Eigen::Index c = 0;
48 for (std::size_t i = 0; i < numComponents(); i++) {
49 const long n = m_components[i]->nx();
50 out.push_back(x.segment(c, n));
51 c += n;
52 }
53 return out;
54}
55
56template <typename Scalar>
57template <class VectorType, class U>
58std::vector<U>
59CartesianProductTpl<Scalar>::split_vector_impl(VectorType &v) const {
60 PROXSUITE_NLP_DIM_CHECK(v, this->ndx());
61 std::vector<U> out;
62 Eigen::Index c = 0;
63 for (std::size_t i = 0; i < numComponents(); i++) {
64 const long n = m_components[i]->ndx();
65 out.push_back(v.segment(c, n));
66 c += n;
67 }
68 return out;
69}
70
71template <typename Scalar>
72auto CartesianProductTpl<Scalar>::merge(const std::vector<VectorXs> &xs) const
73 -> VectorXs {
74 VectorXs out(this->nx());
75 Eigen::Index c = 0;
76 for (std::size_t i = 0; i < numComponents(); i++) {
77 const long n = m_components[i]->nx();
78 out.segment(c, n) = xs[i];
79 c += n;
80 }
81 return out;
82}
83
84template <typename Scalar>
85auto CartesianProductTpl<Scalar>::merge_vector(
86 const std::vector<VectorXs> &vs) const -> VectorXs {
87 VectorXs out(this->ndx());
88 Eigen::Index c = 0;
89 for (std::size_t i = 0; i < numComponents(); i++) {
90 const long n = m_components[i]->ndx();
91 out.segment(c, n) = vs[i];
92 c += n;
93 }
94 return out;
95}
96
97template <typename Scalar>
99 const ConstVectorRef &v,
100 VectorRef out) const {
101 assert(nx() == out.size());
102 Eigen::Index cq = 0, cv = 0;
103 for (std::size_t i = 0; i < numComponents(); i++) {
104 const long nq = getComponent(i).nx();
105 const long nv = getComponent(i).ndx();
106 auto sx = x.segment(cq, nq);
107 auto sv = v.segment(cv, nv);
108
109 auto sout = out.segment(cq, nq);
110
111 getComponent(i).integrate(sx, sv, sout);
112 cq += nq;
113 cv += nv;
114 }
115}
116
117template <typename Scalar>
119 const ConstVectorRef &x1,
120 VectorRef out) const {
121 assert(ndx() == out.size());
122 Eigen::Index cq = 0, cv = 0;
123 for (std::size_t i = 0; i < numComponents(); i++) {
124 const long nq = getComponent(i).nx();
125 const long nv = getComponent(i).ndx();
126 auto sx0 = x0.segment(cq, nq);
127 auto sx1 = x1.segment(cq, nq);
128
129 auto sout = out.segment(cv, nv);
130
131 getComponent(i).difference(sx0, sx1, sout);
132 cq += nq;
133 cv += nv;
134 }
135}
136
137template <typename Scalar>
138void CartesianProductTpl<Scalar>::Jintegrate_impl(const ConstVectorRef &x,
139 const ConstVectorRef &v,
140 MatrixRef Jout,
141 int arg) const {
142 assert(ndx() == Jout.rows());
143 Jout.setZero();
144 Eigen::Index cq = 0, cv = 0;
145 for (std::size_t i = 0; i < numComponents(); i++) {
146 const long nq = getComponent(i).nx();
147 const long nv = getComponent(i).ndx();
148 auto sx = x.segment(cq, nq);
149 auto sv = v.segment(cv, nv);
150
151 auto sJout = Jout.block(cv, cv, nv, nv);
152
153 getComponent(i).Jintegrate(sx, sv, sJout, arg);
154 cq += nq;
155 cv += nv;
156 }
157}
158
159template <typename Scalar>
161 const ConstVectorRef &v,
162 MatrixRef Jout,
163 int arg) const {
164 Eigen::Index cq = 0, cv = 0;
165 for (std::size_t i = 0; i < numComponents(); i++) {
166 const long nq = m_components[i]->nx();
167 auto sx = x.segment(cq, nq);
168 cq += nq;
169
170 const long nv = m_components[i]->ndx();
171 auto sv = v.segment(cv, nv);
172 auto sJout = Jout.middleRows(cv, nv);
173 cv += nv;
174
175 getComponent(i).JintegrateTransport(sx, sv, sJout, arg);
176 }
177}
178
179template <typename Scalar>
180void CartesianProductTpl<Scalar>::Jdifference_impl(const ConstVectorRef &x0,
181 const ConstVectorRef &x1,
182 MatrixRef Jout,
183 int arg) const {
184 assert(ndx() == Jout.rows());
185 Jout.setZero();
186 Eigen::Index cq = 0, cv = 0;
187 for (std::size_t i = 0; i < numComponents(); i++) {
188 const long nq = m_components[i]->nx();
189 auto sx0 = x0.segment(cq, nq);
190 auto sx1 = x1.segment(cq, nq);
191 cq += nq;
192
193 const long nv = m_components[i]->ndx();
194 auto sJout = Jout.block(cv, cv, nv, nv);
195 cv += nv;
196
197 getComponent(i).Jdifference(sx0, sx1, sJout, arg);
198 }
199}
200
201} // namespace nlp
202} // namespace proxsuite
Main package namespace.
Definition bcl-params.hpp:5
void difference_impl(const ConstVectorRef &x0, const ConstVectorRef &x1, VectorRef out) const
Implementation of the manifold retraction operation.
VectorXs rand() const
Sample a random point on the manifold.
VectorXs neutral() const
Get the neutral element from the manifold (if this makes sense).
int ndx() const
Get manifold tangent space dimension.
int nx() const
Get manifold representation dimension.
void integrate_impl(const ConstVectorRef &x, const ConstVectorRef &v, VectorRef out) const
Perform the manifold integration operation.
void JintegrateTransport(const ConstVectorRef &x, const ConstVectorRef &v, MatrixRef Jout, int arg) const
Perform the parallel transport operation.
bool isNormalized(const ConstVectorRef &x) const
Check if the input vector x is a viable element of the manifold.