9 #ifndef EIGEN_AUTODIFF_CHAIN_HESSIAN_H_ 10 #define EIGEN_AUTODIFF_CHAIN_HESSIAN_H_ 18 template <
typename Functor>
25 #if EIGEN_HAS_VARIADIC_TEMPLATES 26 template <
typename... T>
31 template <
typename T0>
35 template <
typename T0,
typename T1>
39 template <
typename T0,
typename T1,
typename T2>
47 typedef typename ValueType::Scalar
Scalar;
56 typedef Matrix<Scalar, ValuesAtCompileTime, JacobianInputsAtCompileTime>
JacobianType;
61 typedef typename JacobianType::Index
Index;
68 typedef Matrix<OuterActiveScalar, InputsAtCompileTime, 1>
ActiveInput;
69 typedef Matrix<OuterActiveScalar, ValuesAtCompileTime, 1>
ActiveValue;
71 #if EIGEN_HAS_VARIADIC_TEMPLATES 75 void operator()(
const InputType &x, ValueType &v)
const 80 template <
typename... ParamsType>
81 void operator()(
const InputType &
x, ValueType &v,
const ParamsType &... Params)
const 86 template <
typename... ParamsType>
87 void operator()(
const InputType &x, ValueType &v, JacobianType &jac,
const ParamsType &... Params)
const 90 autoj(x, v, jac, Params...);
93 template <
typename... ParamsType>
94 void operator()(
const InputType &x, ValueType &v, JacobianType &jac,
const InputJacobianType &ijac,
95 const ParamsType &... Params)
const 98 autoj(x, v, jac, ijac, Params...);
101 template <
typename... ParamsType>
102 void operator()(
const InputType &x, ValueType &v, JacobianType &jac, HessianType &hess,
const ParamsType &... Params)
const 104 this->
operator()(x, v, jac, hess,
nullptr,
nullptr, Params...);
107 template <
typename... ParamsType>
108 void operator()(
const InputType &x, ValueType &v, JacobianType &jac, HessianType &hess,
const InputJacobianType &ijac,
const InputHessianType &ihess,
109 const ParamsType &... Params)
const 111 this->
operator()(x, v, jac, hess, &ijac, &ihess, Params...);
115 template <
typename... ParamsType>
116 void operator()(
const InputType &x, ValueType &v, JacobianType &jac, HessianType &hess,
const InputJacobianType *_ijac = 0,
const InputHessianType *_ihess = 0,
117 const ParamsType &... Params)
const 125 void operator()(
const InputType &x, ValueType &v, JacobianType &jac)
const 131 void operator()(
const InputType &x, ValueType &v, JacobianType &jac,
const InputJacobianType &ijac)
const 134 autoj(x, v, jac, ijac);
137 void operator()(
const InputType &x, ValueType &v, JacobianType &jac, HessianType &hess)
const 139 this->
operator()(x, v, jac, hess,
nullptr,
nullptr);
142 void operator()(
const InputType &x, ValueType &v, JacobianType &jac, HessianType &hess,
const InputJacobianType &ijac,
const InputHessianType &ihess)
const 144 this->
operator()(x, v, jac, hess, &ijac, &ihess);
147 void operator()(
const InputType &x, ValueType &v, JacobianType &jac = 0, HessianType &hess,
const InputJacobianType *_ijac = 0,
const InputHessianType *_ihess = 0) const
150 ActiveInput ax = x.template cast<OuterActiveScalar>();
151 ActiveValue av(jac.rows());
154 eigen_assert((_ijac && _ihess) || (!_ijac && !_ihess));
160 if (InputsAtCompileTime == Dynamic)
161 for (Index j = 0; j < jac.rows(); ++j)
163 av[j].derivatives().resize(x.rows());
164 for (Index k = 0; k < x.rows(); ++k)
165 av[j].derivatives()[k].derivatives().resize(x.rows());
168 for (Index i = 0; i < x.rows(); ++i)
170 ax[i].derivatives() = InnerDerivativeType::Unit(x.rows(), i);
171 ax[i].value().derivatives() = InnerDerivativeType::Unit(x.rows(), i);
172 for (Index k = 0; k < x.rows(); ++k)
174 ax[i].derivatives()(k).derivatives() = InnerDerivativeType::Zero(x.rows());
181 const InputJacobianType &ijac = *_ijac;
182 const InputHessianType &ihess = *_ihess;
184 eigen_assert(x.rows() == ihess.rows());
185 eigen_assert(ijac.cols() == ihess[0].rows() && ijac.cols() == ihess[0].cols());
187 if (InputsAtCompileTime == Dynamic)
188 for (Index j = 0; j < jac.rows(); ++j)
190 av[j].derivatives().resize(ijac.cols());
191 for (Index k = 0; k < ijac.cols(); ++k)
192 av[j].derivatives()[k].derivatives().resize(ijac.cols());
195 for (Index i = 0; i < x.rows(); ++i)
197 ax[i].derivatives() = ijac.row(i);
198 ax[i].value().derivatives() = ijac.row(i);
199 for (Index k = 0; k < ijac.cols(); ++k)
201 ax[i].derivatives()(k).derivatives() = ihess[i].row(k);
206 #if EIGEN_HAS_VARIADIC_TEMPLATES 207 Functor::operator()(ax, av, Params...);
209 Functor::operator()(ax, av);
212 Index cols = _ijac ? _ijac->cols() : x.rows();
215 hess.resize(jac.rows());
216 for (Index i = 0; i < jac.rows(); ++i)
217 hess[i].resize(cols, cols);
220 for (Index i = 0; i < jac.rows(); ++i)
222 v[i] = av[i].value().value();
223 jac.row(i) = av[i].value().derivatives();
224 for (Index j = 0; j < cols; ++j)
225 hess[i].row(j) = av[i].derivatives()[j].derivatives();
232 #endif // EIGEN_AUTODIFF_CHAIN_HESSIAN_H_
void operator()(const InputType &x, ValueType &v, JacobianType &jac=0, HessianType &hess, const InputJacobianType *_ijac=0, const InputHessianType *_ihess=0) const
Array< Matrix< Scalar, JacobianInputsAtCompileTime, JacobianInputsAtCompileTime >, ValuesAtCompileTime, 1 > HessianType
void operator()(const InputType &x, ValueType &v, JacobianType &jac, HessianType &hess) const
Matrix< Scalar, ValuesAtCompileTime, JacobianInputsAtCompileTime > JacobianType
Matrix< Scalar, JacobianInputsAtCompileTime, 1 > InnerDerivativeType
AutoDiffChainHessian(const T0 &a0, const T1 &a1, const T2 &a2)
FunctorBase< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::Dynamic > Functor
AutoDiffScalar< InnerDerivativeType > InnerActiveScalar
Array< Matrix< Scalar, JacobianInputsAtCompileTime, JacobianInputsAtCompileTime >, InputsAtCompileTime, 1 > InputHessianType
AutoDiffScalar< OuterDerivativeType > OuterActiveScalar
Functor::ValueType ValueType
AutoDiffChainHessian(const T0 &a0, const T1 &a1)
Matrix< Scalar, InputsAtCompileTime, JacobianInputsAtCompileTime > InputJacobianType
Matrix< InnerActiveScalar, JacobianInputsAtCompileTime, 1 > OuterDerivativeType
AutoDiffChainHessian(const T0 &a0)
Matrix< OuterActiveScalar, InputsAtCompileTime, 1 > ActiveInput
AutoDiffChainHessian(const Functor &f)
void operator()(const InputType &x, ValueType &v, JacobianType &jac, const InputJacobianType &ijac) const
Matrix< OuterActiveScalar, ValuesAtCompileTime, 1 > ActiveValue
EIGEN_STRONG_INLINE void operator()(const InputType &x, ValueType &v) const
void operator()(const InputType &x, ValueType &v, JacobianType &jac) const
Functor::InputType InputType
JacobianType::Index Index
void operator()(const InputType &x, ValueType &v, JacobianType &jac, HessianType &hess, const InputJacobianType &ijac, const InputHessianType &ihess) const