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
74 #else
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
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::AutoDiffJacobian::JacobianType
Matrix< Scalar, ValuesAtCompileTime, InputsAtCompileTime > JacobianType
Definition: AutoDiffJacobian.h:44
Eigen::AutoDiffJacobian
Definition: AutoDiffJacobian.h:16
Eigen::AutoDiffScalar
A scalar type replacement with automatic differentiation capability.
Definition: AutoDiffScalar.h:33
Eigen::AutoDiffJacobian::Scalar
ValueType::Scalar Scalar
Definition: AutoDiffJacobian.h:37
eigen_assert
#define eigen_assert(x)
Definition: Macros.h:1037
x
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition: gnuplot_common_settings.hh:12
Values
Eigen::AutoDiffJacobian::ActiveValue
Matrix< ActiveScalar, ValuesAtCompileTime, 1 > ActiveValue
Definition: AutoDiffJacobian.h:51
Eigen::AutoDiffJacobian::ActiveInput
Matrix< ActiveScalar, InputsAtCompileTime, 1 > ActiveInput
Definition: AutoDiffJacobian.h:50
Eigen::PlainObjectBase::resize
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index rows, Index cols)
Definition: PlainObjectBase.h:271
Eigen::AutoDiffJacobian::DerivativeType
Matrix< Scalar, InputsAtCompileTime, 1 > DerivativeType
Definition: AutoDiffJacobian.h:47
align_3::a1
Point2 a1
Definition: testPose2.cpp:769
Functor
Definition: NonLinearOptimization.cpp:117
Eigen::AutoDiffJacobian::InputsAtCompileTime
@ InputsAtCompileTime
Definition: AutoDiffJacobian.h:40
j
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2
operator()
internal::enable_if< internal::valid_indexed_view_overload< RowIndices, ColIndices >::value &&internal::traits< typename EIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::ReturnAsIndexedView, typename EIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::type operator()(const RowIndices &rowIndices, const ColIndices &colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
Definition: IndexedViewMethods.h:73
Eigen::AutoDiffJacobian::ActiveScalar
AutoDiffScalar< DerivativeType > ActiveScalar
Definition: AutoDiffJacobian.h:48
Eigen::AutoDiffJacobian::AutoDiffJacobian
AutoDiffJacobian(const Functor &f)
Definition: AutoDiffJacobian.h:20
Eigen::Dynamic
const int Dynamic
Definition: Constants.h:22
Eigen::PlainObjectBase::rows
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: PlainObjectBase.h:143
EIGEN_STRONG_INLINE
#define EIGEN_STRONG_INLINE
Definition: Macros.h:917
Eigen::AutoDiffJacobian::AutoDiffJacobian
AutoDiffJacobian(const T0 &a0, const T1 &a1, const T2 &a2)
Definition: AutoDiffJacobian.h:32
T2
static const Pose3 T2(Rot3::Rodrigues(0.3, 0.2, 0.1), P2)
Eigen::Triplet< double >
Eigen::AutoDiffJacobian::ValueType
Functor::ValueType ValueType
Definition: AutoDiffJacobian.h:36
Eigen::AutoDiffJacobian::InputType
Functor::InputType InputType
Definition: AutoDiffJacobian.h:35
Functor::InputType
Matrix< Scalar, InputsAtCompileTime, 1 > InputType
Definition: NonLinearOptimization.cpp:124
tree::f
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Definition: testExpression.cpp:218
Eigen::AutoDiffJacobian::AutoDiffJacobian
AutoDiffJacobian()
Definition: AutoDiffJacobian.h:19
Eigen::PlainObjectBase::cols
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: PlainObjectBase.h:145
Functor::ValueType
Matrix< Scalar, ValuesAtCompileTime, 1 > ValueType
Definition: NonLinearOptimization.cpp:125
Eigen::AutoDiffJacobian::ValuesAtCompileTime
@ ValuesAtCompileTime
Definition: AutoDiffJacobian.h:41
align_3::a2
Point2 a2
Definition: testPose2.cpp:770
v
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition: 3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
T1
static const Similarity3 T1(R, Point3(3.5, -8.2, 4.2), 1)
testing::Params
static std::shared_ptr< PreintegratedCombinedMeasurements::Params > Params(const Matrix3 &biasAccCovariance=Matrix3::Zero(), const Matrix3 &biasOmegaCovariance=Matrix3::Zero(), const Matrix6 &biasAccOmegaInt=Matrix6::Zero())
Definition: testCombinedImuFactor.cpp:39
Eigen::AutoDiffJacobian::AutoDiffJacobian
AutoDiffJacobian(const T0 &a0, const T1 &a1)
Definition: AutoDiffJacobian.h:30
Eigen::AutoDiffJacobian::AutoDiffJacobian
AutoDiffJacobian(const T0 &a0)
Definition: AutoDiffJacobian.h:28
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Eigen::AutoDiffJacobian::operator()
void operator()(const InputType &x, ValueType *v, JacobianType *_jac=0) const
Definition: AutoDiffJacobian.h:65
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Eigen::AutoDiffJacobian::Index
JacobianType::Index Index
Definition: AutoDiffJacobian.h:45


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:31:57