AutoDiffJacobian.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_AUTODIFF_JACOBIAN_H
11 #define EIGEN_AUTODIFF_JACOBIAN_H
12 
13 namespace Eigen
14 {
15 
16 template<typename Functor> class AutoDiffJacobian : public Functor
17 {
18 public:
21 
22  // forward constructors
23 #if EIGEN_HAS_VARIADIC_TEMPLATES
24  template<typename... T>
25  AutoDiffJacobian(const T& ...Values) : Functor(Values...) {}
26 #else
27  template<typename T0>
28  AutoDiffJacobian(const T0& a0) : Functor(a0) {}
29  template<typename T0, typename T1>
30  AutoDiffJacobian(const T0& a0, const T1& a1) : Functor(a0, a1) {}
31  template<typename T0, typename T1, typename T2>
32  AutoDiffJacobian(const T0& a0, const T1& a1, const T2& a2) : Functor(a0, a1, a2) {}
33 #endif
34 
35  typedef typename Functor::InputType InputType;
36  typedef typename Functor::ValueType ValueType;
37  typedef typename ValueType::Scalar Scalar;
38 
39  enum {
40  InputsAtCompileTime = InputType::RowsAtCompileTime,
41  ValuesAtCompileTime = ValueType::RowsAtCompileTime
42  };
43 
45  typedef typename JacobianType::Index Index;
46 
49 
52 
53 #if EIGEN_HAS_VARIADIC_TEMPLATES
54  // Some compilers don't accept variadic parameters after a default parameter,
55  // i.e., we can't just write _jac=0 but we need to overload operator():
57  void operator() (const InputType& x, ValueType* v) const
58  {
59  this->operator()(x, v, 0);
60  }
61  template<typename... ParamsType>
62  void operator() (const InputType& x, ValueType* v, JacobianType* _jac,
63  const ParamsType&... Params) const
64 #else
65  void operator() (const InputType& x, ValueType* v, JacobianType* _jac=0) const
66 #endif
67  {
68  eigen_assert(v!=0);
69 
70  if (!_jac)
71  {
72 #if EIGEN_HAS_VARIADIC_TEMPLATES
73  Functor::operator()(x, v, Params...);
74 #else
75  Functor::operator()(x, v);
76 #endif
77  return;
78  }
79 
80  JacobianType& jac = *_jac;
81 
82  ActiveInput ax = x.template cast<ActiveScalar>();
83  ActiveValue av(jac.rows());
84 
86  for (Index j=0; j<jac.rows(); j++)
87  av[j].derivatives().resize(x.rows());
88 
89  for (Index i=0; i<jac.cols(); i++)
90  ax[i].derivatives() = DerivativeType::Unit(x.rows(),i);
91 
92 #if EIGEN_HAS_VARIADIC_TEMPLATES
93  Functor::operator()(ax, &av, Params...);
94 #else
95  Functor::operator()(ax, &av);
96 #endif
97 
98  for (Index i=0; i<jac.rows(); i++)
99  {
100  (*v)[i] = av[i].value();
101  jac.row(i) = av[i].derivatives();
102  }
103  }
104 };
105 
106 }
107 
108 #endif // EIGEN_AUTODIFF_JACOBIAN_H
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index cols() const
AutoDiffJacobian(const T0 &a0)
#define EIGEN_STRONG_INLINE
Definition: Macros.h:493
JacobianType::Index Index
Matrix< ActiveScalar, ValuesAtCompileTime, 1 > ActiveValue
A scalar type replacement with automatic differentation capability.
AutoDiffJacobian(const Functor &f)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rows() const
static int f(const TensorMap< Tensor< int, 3 > > &tensor)
Definition: LDLT.h:16
ValueType::Scalar Scalar
Matrix< Scalar, InputsAtCompileTime, 1 > DerivativeType
Matrix< Scalar, InputsAtCompileTime, 1 > InputType
AutoDiffScalar< DerivativeType > ActiveScalar
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index rows, Index cols)
Matrix< Scalar, ValuesAtCompileTime, 1 > ValueType
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Matrix< ActiveScalar, InputsAtCompileTime, 1 > ActiveInput
#define eigen_assert(x)
Definition: Macros.h:577
Functor::InputType InputType
AutoDiffJacobian(const T0 &a0, const T1 &a1, const T2 &a2)
Functor::ValueType ValueType
void operator()(const InputType &x, ValueType *v, JacobianType *_jac=0) const
AutoDiffJacobian(const T0 &a0, const T1 &a1)
const int Dynamic
Definition: Constants.h:21
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:178
Matrix< Scalar, ValuesAtCompileTime, InputsAtCompileTime > JacobianType


hebiros
Author(s): Xavier Artache , Matthew Tesch
autogenerated on Thu Sep 3 2020 04:08:01