26template <
typename Scalar>
struct finite_difference_impl {
31 const Scalar fd_eps,
const ConstVectorRef &x,
33 VectorXs ei(func.
ndx());
34 VectorXs xplus = space.
neutral();
35 VectorXs xminus = space.
neutral();
37 for (
int i = 0; i < func.
ndx(); i++) {
41 Jout.col(i) = (func(xplus) - func(xminus)) / (2 * fd_eps);
48 const Scalar fd_eps,
const ConstVectorRef &x,
49 const ConstVectorRef &v, MatrixRef Hout) {
50 VectorXs ei(func.
ndx());
51 VectorXs xplus = space.
neutral();
52 VectorXs xminus = space.
neutral();
53 MatrixXs Jplus(func.
nr(), func.
ndx());
54 MatrixXs Jminus(func.
nr(), func.
ndx());
59 for (
int i = 0; i < func.
ndx(); i++) {
63 func.computeJacobian(xplus, Jplus);
64 func.computeJacobian(xminus, Jminus);
65 Hout.col(i) = ((Jplus - Jminus) / (2 * fd_eps)).transpose() * v;
78template <
typename _Scalar>
90 using Base::computeJacobian;
94 :
Base(space, func.nr()), space(space), func(func), fd_eps(fd_eps) {}
96 VectorXs
operator()(
const ConstVectorRef &x)
const override {
101 return internal::finite_difference_impl<Scalar>::computeJacobian(
102 space, func, fd_eps, x, Jout);
112template <
typename _Scalar>
124 using Base::computeJacobian;
128 :
Base(space, func.nr()), space(space), func(func), fd_eps(fd_eps) {}
130 VectorXs
operator()(
const ConstVectorRef &x)
const override {
139 MatrixRef Hout)
const override {
140 internal::finite_difference_impl<Scalar>::vectorHessianProduct(
141 space, func, fd_eps, x, v, Hout);
Base definitions for function classes.
#define PROXSUITE_NLP_DYNAMIC_TYPEDEFS(Scalar)
@ FORWARD
Forward finite differences .
@ CENTRAL
Central finite differences .
@ BACKWARD
Backward finite differences .
@ TOC2
Cast to a function.
@ TOC1
Cast to a function.
int ndx() const
Get input manifold's tangent space dimension.
int nr() const
Get function codimension.
Differentiable function, with method for the Jacobian.
virtual void computeJacobian(const ConstVectorRef &x, MatrixRef Jout) const =0
Jacobian matrix of the constraint function.
Twice-differentiable function, with method Jacobian and vector-hessian product evaluation.
virtual VectorXs neutral() const
Get the neutral element from the manifold (if this makes sense).
void integrate(const ConstVectorRef &x, const ConstVectorRef &v, VectorRef out) const
Manifold integration operation .
const ManifoldAbstractTpl< Scalar > & space
VectorXs operator()(const ConstVectorRef &x) const override
Evaluate the residual at a given point x.
finite_difference_wrapper(const ManifoldAbstractTpl< Scalar > &space, const FuncType &func, const Scalar fd_eps)
void computeJacobian(const ConstVectorRef &x, MatrixRef Jout) const override
Jacobian matrix of the constraint function.
VectorXs operator()(const ConstVectorRef &x) const override
Evaluate the residual at a given point x.
const ManifoldAbstractTpl< Scalar > & space
void vectorHessianProduct(const ConstVectorRef &x, const ConstVectorRef &v, MatrixRef Hout) const override
Vector-hessian product.
void computeJacobian(const ConstVectorRef &x, MatrixRef Jout) const override
Jacobian matrix of the constraint function.
finite_difference_wrapper(const ManifoldAbstractTpl< Scalar > &space, const FuncType &func, const Scalar fd_eps)