autodiff/cppad.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2018-2023 CNRS INRIA
3 //
4 
5 #ifndef __pinocchio_autodiff_cppad_hpp__
6 #define __pinocchio_autodiff_cppad_hpp__
7 
8 #include "pinocchio/math/fwd.hpp"
9 #define PINOCCHIO_WITH_CPPAD_SUPPORT
10 
11 // Do not include this file directly.
12 // Copy and use directly the intructions from <cppad/example/cppad_eigen.hpp>
13 // to avoid redifinition of EIGEN_MATRIXBASE_PLUGIN for Eigen 3.3.0 and later
14 //#include <cppad/example/cppad_eigen.hpp>
15 
16 #define EIGEN_MATRIXBASE_PLUGIN <pinocchio/autodiff/cppad/math/eigen_plugin.hpp>
17 
18 #include <cppad/cppad.hpp>
19 #include <Eigen/Dense>
20 
21 namespace boost
22 {
23  namespace math
24  {
25  namespace constants
26  {
27  namespace detail
28  {
29  template<typename Scalar>
30  struct constant_pi< CppAD::AD<Scalar> > : constant_pi<Scalar>
31  {
32  typedef CppAD::AD<Scalar> ADScalar;
33 
34  template <int N>
35  static inline ADScalar get(const mpl::int_<N>& n)
36  {
37  return ADScalar(constant_pi<Scalar>::get(n));
38  }
39 
40  template <class T, T value>
41  static inline ADScalar get(const std::integral_constant<T, value> &n)
42  {
43  return ADScalar(constant_pi<Scalar>::get(n));
44  }
45  };
46  }
47  }
48  }
49 }
50 
51 namespace Eigen
52 {
53  namespace internal
54  {
55  // Specialization of Eigen::internal::cast_impl for CppAD input types
56  template<typename Scalar>
57  struct cast_impl<CppAD::AD<Scalar>,Scalar>
58  {
59 #if EIGEN_VERSION_AT_LEAST(3,2,90)
61 #endif
62  static inline Scalar run(const CppAD::AD<Scalar> & x)
63  {
64  return CppAD::Value(x);
65  }
66  };
67  }
68 } //namespace Eigen
69 
70 // Source from #include <cppad/example/cppad_eigen.hpp>
71 namespace Eigen
72 {
73  template <class Base> struct NumTraits< CppAD::AD<Base> >
74  { // type that corresponds to the real part of an AD<Base> value
75  typedef CppAD::AD<Base> Real;
76  // type for AD<Base> operations that result in non-integer values
77  typedef CppAD::AD<Base> NonInteger;
78  // type to use for numeric literals such as "2" or "0.5".
79  typedef CppAD::AD<Base> Literal;
80  // type for nested value inside an AD<Base> expression tree
81  typedef CppAD::AD<Base> Nested;
82 
83  enum {
84  // does not support complex Base types
85  IsComplex = 0 ,
86  // does not support integer Base types
87  IsInteger = 0 ,
88  // only support signed Base types
89  IsSigned = 1 ,
90  // must initialize an AD<Base> object
91  RequireInitialization = 1 ,
92  // computational cost of the corresponding operations
93  ReadCost = 1 ,
94  AddCost = 2 ,
95  MulCost = 2
96  };
97 
98  // machine epsilon with type of real part of x
99  // (use assumption that Base is not complex)
100  static CppAD::AD<Base> epsilon(void)
101  { return CppAD::numeric_limits< CppAD::AD<Base> >::epsilon(); }
102 
103  // relaxed version of machine epsilon for comparison of different
104  // operations that should result in the same value
105  static CppAD::AD<Base> dummy_precision(void)
106  { return 100. *
107  CppAD::numeric_limits< CppAD::AD<Base> >::epsilon();
108  }
109 
110  // minimum normalized positive value
111  static CppAD::AD<Base> lowest(void)
112  { return CppAD::numeric_limits< CppAD::AD<Base> >::min(); }
113 
114  // maximum finite value
115  static CppAD::AD<Base> highest(void)
116  { return CppAD::numeric_limits< CppAD::AD<Base> >::max(); }
117 
118  // number of decimal digits that can be represented without change.
119  static int digits10(void)
120  { return CppAD::numeric_limits< CppAD::AD<Base> >::digits10; }
121  };
122 } // namespace Eigen
123 
124 // Source from #include <cppad/example/cppad_eigen.hpp>
125 #include "pinocchio/utils/static-if.hpp"
126 
127 
128 namespace CppAD
129 {
130  // functions that return references
131  template <class Base> const AD<Base>& conj(const AD<Base>& x)
132  { return x; }
133  template <class Base> const AD<Base>& real(const AD<Base>& x)
134  { return x; }
135 
136  // functions that return values (note abs is defined by cppad.hpp)
137  template <class Base> AD<Base> imag(const AD<Base>& /*x*/)
138  { return CppAD::AD<Base>(0.); }
139  template <class Base> AD<Base> abs2(const AD<Base>& x)
140  { return x * x; }
141 
142  template<typename Scalar>
143  AD<Scalar> min(const AD<Scalar>& x, const AD<Scalar>& y)
144  {
147  return if_then_else(LT, y, x, y, x);
148  }
149 
150  template<typename Scalar>
151  AD<Scalar> max(const AD<Scalar>& x, const AD<Scalar>& y)
152  {
155  return if_then_else(LT, x, y, y, x);
156  }
157 
158 } // namespace CppAD
159 
160 #include "pinocchio/utils/static-if.hpp"
161 
162 namespace pinocchio
163 {
164  template<typename Scalar>
165  struct TaylorSeriesExpansion< CppAD::AD<Scalar> > : TaylorSeriesExpansion<Scalar>
166  {
168  typedef CppAD::AD<Scalar> ADScalar;
169 
170  template<int degree>
171  static ADScalar precision()
172  {
173  return ADScalar(Base::template precision<degree>());
174  }
175 
176  };
177 
178 } // namespace pinocchio
179 
180 #include "pinocchio/autodiff/cppad/spatial/se3-tpl.hpp"
181 #include "pinocchio/autodiff/cppad/spatial/log.hxx"
182 #include "pinocchio/autodiff/cppad/utils/static-if.hpp"
183 #include "pinocchio/autodiff/cppad/math/quaternion.hpp"
184 #include "pinocchio/autodiff/cppad/algorithm/aba.hpp"
185 
186 
187 #endif // #ifndef __pinocchio_autodiff_cppad_hpp__
const AD< Base > & conj(const AD< Base > &x)
static CppAD::AD< Base > highest(void)
Vec3f n
Eigen::Matrix< typename ComplexMatrix::RealScalar, ComplexMatrix::RowsAtCompileTime, ComplexMatrix::ColsAtCompileTime, ComplexMatrix::Options > imag(const Eigen::MatrixBase< ComplexMatrix > &complex_mat)
AD< Scalar > max(const AD< Scalar > &x, const AD< Scalar > &y)
SE3::Scalar Scalar
Definition: conversions.cpp:13
#define EIGEN_DEVICE_FUNC
Definition: tensor.hpp:11
static Scalar run(const CppAD::AD< Scalar > &x)
static CppAD::AD< Base > epsilon(void)
Main pinocchio namespace.
Definition: timings.cpp:28
Eigen::Matrix< typename ComplexMatrix::RealScalar, ComplexMatrix::RowsAtCompileTime, ComplexMatrix::ColsAtCompileTime, ComplexMatrix::Options > real(const Eigen::MatrixBase< ComplexMatrix > &complex_mat)
if_then_else_impl< LhsType, RhsType, ThenType, ElseType >::ReturnType if_then_else(const ComparisonOperators op, const LhsType &lhs_value, const RhsType &rhs_value, const ThenType &then_value, const ElseType &else_value)
AD< Scalar > min(const AD< Scalar > &x, const AD< Scalar > &y)
static CppAD::AD< Base > dummy_precision(void)
AD< Base > abs2(const AD< Base > &x)
static CppAD::AD< Base > lowest(void)


pinocchio
Author(s):
autogenerated on Fri Jun 23 2023 02:38:29