Go to the documentation of this file.
9 #ifndef EIGEN_AUTODIFF_CHAIN_HESSIAN_SPARSE_H_
10 #define EIGEN_AUTODIFF_CHAIN_HESSIAN_SPARSE_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;
61 typedef typename JacobianType::Index
Index;
71 typedef Matrix<OuterActiveScalar, InputsAtCompileTime, 1>
ActiveInput;
72 typedef Matrix<OuterActiveScalar, ValuesAtCompileTime, 1>
ActiveValue;
74 #if EIGEN_HAS_VARIADIC_TEMPLATES
83 template <
typename... ParamsType>
89 template <
typename... ParamsType>
92 AutoDiffChainJacobianSparse<Functor> autoj(*
static_cast<const Functor *
>(
this));
93 autoj(x, v, jac, Params...);
96 template <
typename... ParamsType>
98 const ParamsType &... Params)
const
100 AutoDiffChainJacobianSparse<Functor> autoj(*
static_cast<const Functor *
>(
this));
101 autoj(x, v, jac, ijac, Params...);
104 template <
typename... ParamsType>
107 this->
operator()(x, v, jac, hess,
nullptr,
nullptr, Params...);
110 template <
typename... ParamsType>
112 const ParamsType &... Params)
const
114 this->
operator()(x, v, jac, hess, &ijac, &ihess, Params...);
118 template <
typename... ParamsType>
120 const ParamsType &... Params)
const
137 autoj(x, v, jac, ijac);
142 this->
operator()(x, v, jac, hess,
nullptr,
nullptr);
147 this->
operator()(x, v, jac, hess, &ijac, &ihess);
153 ActiveInput ax = x.template cast<OuterActiveScalar>();
157 eigen_assert((_ijac && _ihess) || (!_ijac && !_ihess));
161 eigen_assert(x.rows() == jac.cols());
163 for (
Index j = 0; j < jac.rows(); ++j)
165 av[j].derivatives().resize(x.rows());
166 av[j].derivatives().reserve(x.rows());
167 for (
Index k = 0; k < x.rows(); ++k)
168 av[j].derivatives().insert(k).derivatives().resize(x.rows());
171 for (
Index i = 0; i < x.rows(); ++i)
173 ax[i].derivatives().resize(x.rows());
174 ax[i].derivatives().insert(i) = 1.0;
175 ax[i].value().derivatives().resize(x.rows());
176 ax[i].value().derivatives().insert(i) = 1.0;
177 ax[i].derivatives().coeffRef(i).derivatives().resize(x.rows());
186 eigen_assert(x.rows() == ihess.rows());
187 eigen_assert(ijac.cols() == ihess[0].rows() && ijac.cols() == ihess[0].cols());
189 for (
Index j = 0; j < jac.rows(); ++j)
191 av[j].derivatives().resize(ijac.cols());
192 av[j].derivatives().reserve(ijac.cols());
193 for (
Index k = 0; k < ijac.cols(); ++k)
194 av[j].derivatives().insert(k).derivatives().resize(ijac.cols());
197 for (
Index i = 0; i < x.rows(); ++i)
199 ax[i].derivatives().resize(ijac.cols());
200 ax[i].derivatives() = ijac.row(i);
201 ax[i].value().derivatives().resize(ijac.cols());
202 ax[i].value().derivatives() = ijac.row(i);
203 for (
Index k = 0; k < ijac.cols(); ++k)
205 ax[i].derivatives().coeffRef(k).derivatives() = ihess[i].row(k);
210 #if EIGEN_HAS_VARIADIC_TEMPLATES
211 Functor::operator()(ax, av, Params...);
213 Functor::operator()(ax, av);
216 Index cols = _ijac ? _ijac->cols() : x.rows();
218 hess.resize(jac.rows());
219 for (
Index i = 0; i < jac.rows(); ++i)
220 hess[i].resize(cols, cols);
223 for (
int i = 0; i < jac.rows(); ++i)
225 v[i] = av[i].value().value();
228 jac.insert(i, it.row()) = av[i].value().derivatives().coeffRef(it.row());
231 hess[i].insert(it.row(), ith.row()) = av[i].derivatives().coeffRef(it.row()).derivatives().coeffRef(ith.row());
240 #endif // EIGEN_AUTODIFF_CHAIN_HESSIAN_SPARSE_H_
void operator()(const InputType &x, ValueType &v, JacobianType &jac, const InputJacobianType &ijac) const
Definition: autodiff_chain_hessian_sparse.h:134
Definition: autodiff_chain_hessian.h:16
Array< SparseMatrix< Scalar >, ValuesAtCompileTime, 1 > HessianType
Definition: autodiff_chain_hessian_sparse.h:59
JacobianType::Index Index
Definition: autodiff_chain_hessian_sparse.h:61
Definition: autodiff_scalar.h:48
@ InputsAtCompileTime
Definition: autodiff_chain_hessian_sparse.h:51
Functor::ValueType ValueType
Definition: autodiff_chain_hessian_sparse.h:46
FunctorBase< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::Dynamic > Functor
Definition: functor.h:49
AutoDiffChainHessianSparse(const T0 &a0)
Definition: autodiff_chain_hessian_sparse.h:32
OuterDerivativeType::InnerIterator JacobianInnerIteratorType
Definition: autodiff_chain_hessian_sparse.h:68
ValueType::Scalar Scalar
Definition: autodiff_chain_hessian_sparse.h:47
EIGEN_STRONG_INLINE void operator()(const InputType &x, ValueType &v) const
Definition: autodiff_chain_hessian_sparse.h:123
Functor::InputType InputType
Definition: autodiff_chain_hessian_sparse.h:45
@ JacobianInputsAtCompileTime
Definition: autodiff_chain_hessian_sparse.h:53
AutoDiffChainHessianSparse(const T0 &a0, const T1 &a1)
Definition: autodiff_chain_hessian_sparse.h:36
SparseMatrix< Scalar > JacobianType
Definition: autodiff_chain_hessian_sparse.h:56
AutoDiffScalar< InnerDerivativeType > InnerActiveScalar
Definition: autodiff_chain_hessian_sparse.h:64
SparseVector< Scalar > InnerDerivativeType
Definition: autodiff_chain_hessian_sparse.h:63
@ ValuesAtCompileTime
Definition: autodiff_chain_hessian_sparse.h:52
AutoDiffScalar< OuterDerivativeType > OuterActiveScalar
Definition: autodiff_chain_hessian_sparse.h:66
Matrix< OuterActiveScalar, ValuesAtCompileTime, 1 > ActiveValue
Definition: autodiff_chain_hessian_sparse.h:72
SparseVector< InnerActiveScalar > OuterDerivativeType
Definition: autodiff_chain_hessian_sparse.h:65
InnerDerivativeType::InnerIterator HessianInnerIteratorType
Definition: autodiff_chain_hessian_sparse.h:69
Array< SparseMatrix< Scalar >, InputsAtCompileTime, 1 > InputHessianType
Definition: autodiff_chain_hessian_sparse.h:60
Definition: autodiff_chain_jacobian_sparse.h:18
AutoDiffChainHessianSparse(const T0 &a0, const T1 &a1, const T2 &a2)
Definition: autodiff_chain_hessian_sparse.h:40
void operator()(const InputType &x, ValueType &v, JacobianType &jac) const
Definition: autodiff_chain_hessian_sparse.h:128
Definition: autodiff_chain_hessian_sparse.h:19
void operator()(const InputType &x, ValueType &v, JacobianType &jac, HessianType &hess, const InputJacobianType &ijac, const InputHessianType &ihess) const
Definition: autodiff_chain_hessian_sparse.h:145
void operator()(const InputType &x, ValueType &v, JacobianType &jac, HessianType &hess) const
Definition: autodiff_chain_hessian_sparse.h:140
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_sparse.h:150
SparseMatrix< Scalar > InputJacobianType
Definition: autodiff_chain_hessian_sparse.h:58
Matrix< OuterActiveScalar, InputsAtCompileTime, 1 > ActiveInput
Definition: autodiff_chain_hessian_sparse.h:71
AutoDiffChainHessianSparse(const Functor &f)
Definition: autodiff_chain_hessian_sparse.h:23
AutoDiffChainHessianSparse()
Definition: autodiff_chain_hessian_sparse.h:22