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);
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_