8#include <boost/core/demangle.hpp>
14template <
typename Scalar>
16 -> shared_ptr<CostFunctionBaseTpl<Scalar>> {
17 if (func->nr() != 1) {
19 "Function cannot be cast to cost (codimension nr != 1).");
21 return std::make_shared<func_to_cost<Scalar>>(func);
29template <
typename _Scalar>
38 :
Base(manifold, 1) {}
45 VectorRef out)
const = 0;
46 virtual void computeHessian(
const ConstVectorRef &x, MatrixRef out)
const = 0;
51 VectorXs out(this->
ndx());
57 MatrixXs out(this->
ndx(), this->
ndx());
71 Eigen::Matrix<
Scalar, 1, -1> gT = Jout.template topRows<1>();
77 MatrixRef Hout)
const {
86 const std::string name = boost::core::demangle(
typeid(cost).name());
92template <
typename _Scalar>
struct func_to_cost : CostFunctionBaseTpl<_Scalar> {
102 :
Base(func->
nx(), func->
ndx()), underlying_(func) {}
104 Scalar call(
const ConstVectorRef &x)
const {
return underlying()(x)(0); }
111 VectorXs v = VectorXs::Ones(1);
116 shared_ptr<C2Function> underlying_;
117 const C2Function &underlying()
const {
return *underlying_; }
123#ifdef PROXSUITE_NLP_ENABLE_TEMPLATE_INSTANTIATION
124#include "proxsuite-nlp/cost-function.txx"
#define PROXSUITE_NLP_RUNTIME_ERROR(msg)
Base definitions for function classes.
#define PROXSUITE_NLP_DYNAMIC_TYPEDEFS(Scalar)
auto downcast_function_to_cost(const shared_ptr< C2FunctionTpl< Scalar > > &func) -> shared_ptr< CostFunctionBaseTpl< Scalar > >
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 void vectorHessianProduct(const ConstVectorRef &, const ConstVectorRef &, MatrixRef Hout) const
Vector-hessian product.
Base class for differentiable cost functions.
void computeJacobian(const ConstVectorRef &x, MatrixRef Jout) const
Jacobian matrix of the constraint function.
virtual void computeHessian(const ConstVectorRef &x, MatrixRef out) const =0
void vectorHessianProduct(const ConstVectorRef &x, const ConstVectorRef &v, MatrixRef Hout) const
Vector-hessian product.
virtual Scalar call(const ConstVectorRef &x) const =0
Evaluate the cost function.
VectorXs computeGradient(const ConstVectorRef &x) const
CostFunctionBaseTpl(const ManifoldAbstractTpl< Scalar > &manifold)
CostFunctionBaseTpl(const int nx, const int ndx)
virtual ~CostFunctionBaseTpl()=default
friend std::ostream & operator<<(std::ostream &ostr, const CostFunctionBaseTpl< Scalar > &cost)
virtual void computeGradient(const ConstVectorRef &x, VectorRef out) const =0
VectorXs operator()(const ConstVectorRef &x) const
Evaluate the residual at a given point x.
MatrixXs computeHessian(const ConstVectorRef &x) const
Scalar call(const ConstVectorRef &x) const
Evaluate the cost function.
func_to_cost(const shared_ptr< C2Function > &func)
Constructor.
void computeGradient(const ConstVectorRef &x, VectorRef out) const
C2FunctionTpl< Scalar > C2Function
void computeHessian(const ConstVectorRef &x, MatrixRef Hout) const