AdaptAutoDiff.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
19 #pragma once
20 
21 #include <gtsam/base/VectorSpace.h>
24 
25 namespace gtsam {
26 
34 template <typename FUNCTOR, int M, int N1, int N2>
38 
42 
43  FUNCTOR f;
44 
45  public:
48  OptionalJacobian<M, N2> H2 = {}) {
50 
51  bool success;
53 
54  if (H1 || H2) {
55  // Get derivatives with AutoDiff
56  const double* parameters[] = {v1.data(), v2.data()};
57  double rowMajor1[M * N1] = {}, rowMajor2[M * N2] = {}; // on the stack
58  double* jacobians[] = {rowMajor1, rowMajor2};
59  success = AutoDiff<FUNCTOR, double, N1, N2>::Differentiate(
60  f, parameters, M, result.data(), jacobians);
61 
62  // Convert from row-major to columnn-major
63  // TODO: if this is a bottleneck (probably not!) fix Autodiff to be
64  // Column-Major
65  if (H1) *H1 = Eigen::Map<RowMajor1>(rowMajor1);
66  if (H2) *H2 = Eigen::Map<RowMajor2>(rowMajor2);
67 
68  } else {
69  // Apply the mapping, to get result
70  success = f(v1.data(), v2.data(), result.data());
71  }
72  if (!success)
73  throw std::runtime_error(
74  "AdaptAutoDiff: function call resulted in failure");
75  return result;
76  }
77 };
78 
79 } // namespace gtsam
gtsam::AdaptAutoDiff::f
FUNCTOR f
Definition: AdaptAutoDiff.h:43
gtsam::AdaptAutoDiff::Vector2
Eigen::Matrix< double, N2, 1 > Vector2
Definition: AdaptAutoDiff.h:41
result
Values result
Definition: OdometryOptimize.cpp:8
autodiff.h
gtsam::AdaptAutoDiff::RowMajor2
Eigen::Matrix< double, M, N2, Eigen::RowMajor > RowMajor2
Definition: AdaptAutoDiff.h:37
gtsam::AdaptAutoDiff::VectorT
Eigen::Matrix< double, M, 1 > VectorT
Definition: AdaptAutoDiff.h:39
gtsam::AdaptAutoDiff
Definition: AdaptAutoDiff.h:35
parameters
static ConjugateGradientParameters parameters
Definition: testIterative.cpp:33
gtsam::AdaptAutoDiff::operator()
VectorT operator()(const Vector1 &v1, const Vector2 &v2, OptionalJacobian< M, N1 > H1={}, OptionalJacobian< M, N2 > H2={})
Definition: AdaptAutoDiff.h:46
OptionalJacobian.h
Special class for optional Jacobian arguments.
Eigen::Map
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:94
gtsam
traits
Definition: SFMdata.h:40
gtsam::OptionalJacobian
Definition: OptionalJacobian.h:38
v2
Vector v2
Definition: testSerializationBase.cpp:39
ceres::internal::AutoDiff
Definition: autodiff.h:209
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition: 3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
VectorSpace.h
gtsam::AdaptAutoDiff::RowMajor1
Eigen::Matrix< double, M, N1, Eigen::RowMajor > RowMajor1
Definition: AdaptAutoDiff.h:36
v1
Vector v1
Definition: testSerializationBase.cpp:38
gtsam::AdaptAutoDiff::Vector1
Eigen::Matrix< double, N1, 1 > Vector1
Definition: AdaptAutoDiff.h:40
M
Matrix< RealScalar, Dynamic, Dynamic > M
Definition: bench_gemm.cpp:51


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:11:05