Go to the documentation of this file.
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
80 template <
typename... ParamsType>
86 template <
typename... ParamsType>
89 AutoDiffChainJacobian<Functor> autoj(*
static_cast<const Functor *
>(
this));
90 autoj(x, v, jac, Params...);
93 template <
typename... ParamsType>
95 const ParamsType &... Params)
const
97 AutoDiffChainJacobian<Functor> autoj(*
static_cast<const Functor *
>(
this));
98 autoj(x, v, jac, ijac, Params...);
101 template <
typename... ParamsType>
104 this->
operator()(x, v, jac, hess,
nullptr,
nullptr, Params...);
107 template <
typename... ParamsType>
109 const ParamsType &... Params)
const
111 this->
operator()(x, v, jac, hess, &ijac, &ihess, Params...);
115 template <
typename... ParamsType>
117 const ParamsType &... Params)
const
134 autoj(x, v, jac, ijac);
139 this->
operator()(x, v, jac, hess,
nullptr,
nullptr);
144 this->
operator()(x, v, jac, hess, &ijac, &ihess);
150 ActiveInput ax = x.template cast<OuterActiveScalar>();
154 eigen_assert((_ijac && _ihess) || (!_ijac && !_ihess));
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());
184 eigen_assert(x.rows() == ihess.rows());
185 eigen_assert(ijac.cols() == ihess[0].rows() && ijac.cols() == ihess[0].cols());
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_
AutoDiffChainHessian(const T0 &a0, const T1 &a1, const T2 &a2)
Definition: autodiff_chain_hessian.h:40
Definition: autodiff_chain_hessian.h:16
Matrix< Scalar, InputsAtCompileTime, JacobianInputsAtCompileTime > InputJacobianType
Definition: autodiff_chain_hessian.h:58
AutoDiffChainHessian(const T0 &a0)
Definition: autodiff_chain_hessian.h:32
Definition: autodiff_chain_jacobian.h:18
Definition: autodiff_scalar.h:48
Matrix< OuterActiveScalar, InputsAtCompileTime, 1 > ActiveInput
Definition: autodiff_chain_hessian.h:68
Matrix< Scalar, JacobianInputsAtCompileTime, 1 > InnerDerivativeType
Definition: autodiff_chain_hessian.h:63
AutoDiffScalar< InnerDerivativeType > InnerActiveScalar
Definition: autodiff_chain_hessian.h:64
Matrix< OuterActiveScalar, ValuesAtCompileTime, 1 > ActiveValue
Definition: autodiff_chain_hessian.h:69
FunctorBase< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::Dynamic > Functor
Definition: functor.h:49
void operator()(const InputType &x, ValueType &v, JacobianType &jac, HessianType &hess, const InputJacobianType &ijac, const InputHessianType &ihess) const
Definition: autodiff_chain_hessian.h:142
EIGEN_STRONG_INLINE void operator()(const InputType &x, ValueType &v) const
Definition: autodiff_chain_hessian.h:120
void operator()(const InputType &x, ValueType &v, JacobianType &jac, HessianType &hess) const
Definition: autodiff_chain_hessian.h:137
void operator()(const InputType &x, ValueType &v, JacobianType &jac=0, HessianType &hess, const InputJacobianType *_ijac=0, const InputHessianType *_ihess=0) const
Definition: autodiff_chain_hessian.h:147
@ ValuesAtCompileTime
Definition: autodiff_chain_hessian.h:52
Array< Matrix< Scalar, JacobianInputsAtCompileTime, JacobianInputsAtCompileTime >, InputsAtCompileTime, 1 > InputHessianType
Definition: autodiff_chain_hessian.h:60
AutoDiffChainHessian()
Definition: autodiff_chain_hessian.h:22
AutoDiffChainHessian(const Functor &f)
Definition: autodiff_chain_hessian.h:23
void operator()(const InputType &x, ValueType &v, JacobianType &jac) const
Definition: autodiff_chain_hessian.h:125
Functor::ValueType ValueType
Definition: autodiff_chain_hessian.h:46
AutoDiffChainHessian(const T0 &a0, const T1 &a1)
Definition: autodiff_chain_hessian.h:36
Matrix< Scalar, ValuesAtCompileTime, JacobianInputsAtCompileTime > JacobianType
Definition: autodiff_chain_hessian.h:56
AutoDiffScalar< OuterDerivativeType > OuterActiveScalar
Definition: autodiff_chain_hessian.h:66
Functor::InputType InputType
Definition: autodiff_chain_hessian.h:45
void operator()(const InputType &x, ValueType &v, JacobianType &jac, const InputJacobianType &ijac) const
Definition: autodiff_chain_hessian.h:131
@ InputsAtCompileTime
Definition: autodiff_chain_hessian.h:51
Definition: autodiff_chain_hessian.h:19
Matrix< InnerActiveScalar, JacobianInputsAtCompileTime, 1 > OuterDerivativeType
Definition: autodiff_chain_hessian.h:65
@ JacobianInputsAtCompileTime
Definition: autodiff_chain_hessian.h:53
JacobianType::Index Index
Definition: autodiff_chain_hessian.h:61
ValueType::Scalar Scalar
Definition: autodiff_chain_hessian.h:47
Array< Matrix< Scalar, JacobianInputsAtCompileTime, JacobianInputsAtCompileTime >, ValuesAtCompileTime, 1 > HessianType
Definition: autodiff_chain_hessian.h:59