31 #ifndef NUMDIFFDERIVATIVESBASE_HPP_
32 #define NUMDIFFDERIVATIVESBASE_HPP_
34 #include <Eigen/Dense>
35 #include <unsupported/Eigen/NumericalDiff>
37 namespace DirectTrajectoryOptimization {
46 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
55 template<
typename _Scalar,
int NX = Eigen::Dynamic,
int NY = Eigen::Dynamic>
56 struct DynamicSizedFunctor {
58 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
60 typedef _Scalar Scalar;
62 InputsAtCompileTime = NX, ValuesAtCompileTime = NY
64 typedef Eigen::Matrix<Scalar, InputsAtCompileTime, 1> InputType;
65 typedef Eigen::Matrix<Scalar, ValuesAtCompileTime, 1> ValueType;
66 typedef Eigen::Matrix<Scalar, ValuesAtCompileTime, InputsAtCompileTime> JacobianType;
68 int m_inputs, m_values;
70 DynamicSizedFunctor() :
71 m_inputs(InputsAtCompileTime), m_values(ValuesAtCompileTime) {
73 DynamicSizedFunctor(
int inputs,
int values) :
74 m_inputs(inputs), m_values(values) {
86 struct FunctionOperator:DynamicSizedFunctor<double> {
88 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
91 FunctionOperator(
int in_size,
int out_size, std::shared_ptr<NumDiffDerivativesBase> my_owner_pointer) :
92 DynamicSizedFunctor<double>(in_size, out_size),owner_pointer(my_owner_pointer)
95 int operator()(
const Eigen::VectorXd &in_vect,
96 Eigen::VectorXd &fvec)
const {
99 owner_pointer->fx(in_vect, fvec);
103 std::shared_ptr<NumDiffDerivativesBase> owner_pointer;
108 std::shared_ptr<Eigen::NumericalDiff<FunctionOperator> >
numDiff;
109 Eigen::MatrixXd mJacobian;
114 virtual void fx(
const Eigen::VectorXd &, Eigen::VectorXd &) = 0;
std::shared_ptr< Eigen::NumericalDiff< FunctionOperator > > numDiff
Definition: NumDiffDerivativesBase.hpp:108
virtual void initialize_num_diff()=0
Overload this method to define the local pointers.
virtual void fx(const Eigen::VectorXd &, Eigen::VectorXd &)=0
Overload this method in the derived class to obtain numerical approximation of the gradient...
std::shared_ptr< FunctionOperator > numdifoperator
Definition: NumDiffDerivativesBase.hpp:107
This base class provides functionality for numerical differentiation of vector functions.
Definition: NumDiffDerivativesBase.hpp:44