proxsuite-nlp  0.10.0
A primal-dual augmented Lagrangian-type solver for nonlinear programming on manifolds.
Loading...
Searching...
No Matches
function-ops.hpp
Go to the documentation of this file.
1
3#pragma once
4
6
7#include <utility>
8
9namespace proxsuite {
10namespace nlp {
11
14template <typename _Scalar> struct ComposeFunctionTpl : C2FunctionTpl<_Scalar> {
15public:
16 using Scalar = _Scalar;
20
22
23 ComposeFunctionTpl(const shared_ptr<Base> &left,
24 const shared_ptr<Base> &right)
25 : Base(right->nx(), right->ndx(), left->nr()), left_(left),
26 right_(right) {
27 if (left->nx() != right->nr()) {
29 "Incompatible dimensions ({:d} and {:d}).", left->nx(), right->nr()));
30 }
31 assert(left->nx() == right->nr());
32 }
33
34 VectorXs operator()(const ConstVectorRef &x) const {
35 return left()(right()(x));
36 }
37
38 void computeJacobian(const ConstVectorRef &x, MatrixRef Jout) const {
39 MatrixXs Jleft = left().computeJacobian(right()(x));
40 Jout.noalias() = Jleft * right().computeJacobian(x);
41 }
42
43 const Base &left() const { return *left_; }
44 const Base &right() const { return *right_; }
45
46private:
47 shared_ptr<Base> left_;
48 shared_ptr<Base> right_;
49};
50
55template <typename Scalar>
56auto compose(const shared_ptr<C2FunctionTpl<Scalar>> &left,
57 const shared_ptr<C2FunctionTpl<Scalar>> &right) {
58 return std::make_shared<ComposeFunctionTpl<Scalar>>(left, right);
59}
60
61} // namespace nlp
62} // namespace proxsuite
63
64#ifdef PROXSUITE_NLP_ENABLE_TEMPLATE_INSTANTIATION
65#include "proxsuite-nlp/function-ops.txx"
66#endif
#define PROXSUITE_NLP_RUNTIME_ERROR(msg)
Definition exceptions.hpp:8
Base definitions for function classes.
#define PROXSUITE_NLP_DYNAMIC_TYPEDEFS(Scalar)
Definition math.hpp:26
auto compose(const shared_ptr< C2FunctionTpl< Scalar > > &left, const shared_ptr< C2FunctionTpl< Scalar > > &right)
Compose two function objects.
Main package namespace.
Definition bcl-params.hpp:5
virtual void computeJacobian(const ConstVectorRef &x, MatrixRef Jout) const=0
Twice-differentiable function, with method Jacobian and vector-hessian product evaluation.
Definition fwd.hpp:76
virtual void vectorHessianProduct(const ConstVectorRef &, const ConstVectorRef &, MatrixRef Hout) const
Vector-hessian product.
ComposeFunctionTpl(const shared_ptr< Base > &left, const shared_ptr< Base > &right)
void computeJacobian(const ConstVectorRef &x, MatrixRef Jout) const
Jacobian matrix of the constraint function.
VectorXs operator()(const ConstVectorRef &x) const
Evaluate the residual at a given point x.