14template <
typename _Scalar>
struct ComposeFunctionTpl : C2FunctionTpl<_Scalar> {
16 using Scalar = _Scalar;
17 using Base = C2FunctionTpl<Scalar>;
23 ComposeFunctionTpl(
const shared_ptr<Base> &left,
24 const shared_ptr<Base> &right)
25 : Base(right->nx(), right->ndx(), left->nr()), left_(left),
27 if (left->nx() != right->nr()) {
28 PROXSUITE_NLP_RUNTIME_ERROR(fmt::format(
29 "Incompatible dimensions ({:d} and {:d}).", left->nx(), right->nr()));
31 assert(left->nx() == right->nr());
35 return left()(right()(x));
39 MatrixXs Jleft = left().computeJacobian(right()(x));
40 Jout.noalias() = Jleft * right().computeJacobian(x);
43 const Base &left()
const {
return *left_; }
44 const Base &right()
const {
return *right_; }
47 shared_ptr<Base> left_;
48 shared_ptr<Base> right_;
55template <
typename Scalar>
58 return std::make_shared<ComposeFunctionTpl<Scalar>>(left, right);
64#ifdef PROXSUITE_NLP_ENABLE_TEMPLATE_INSTANTIATION
65#include "proxsuite-nlp/function-ops.txx"
Base definitions for function classes.
auto compose(const shared_ptr< C2FunctionTpl< Scalar > > &left, const shared_ptr< C2FunctionTpl< Scalar > > &right)
Compose two function objects.
#define PROXSUITE_NLP_DYNAMIC_TYPEDEFS(Scalar)
virtual void computeJacobian(const ConstVectorRef &x, MatrixRef Jout) const=0
Twice-differentiable function, with method Jacobian and vector-hessian product evaluation.
virtual void vectorHessianProduct(const ConstVectorRef &, const ConstVectorRef &, MatrixRef Hout) const
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.