pinocchio  2.3.1-dirty
autodiff/cppad.hpp
1 //
2 // Copyright (c) 2018-2019 CNRS INRIA
3 //
4 
5 #ifndef __pinocchio_autodiff_ccpad_hpp__
6 #define __pinocchio_autodiff_ccpad_hpp__
7 
8 #include "pinocchio/math/fwd.hpp"
9 
10 // Do not include this file directly.
11 // Copy and use directly the intructions from <cppad/example/cppad_eigen.hpp>
12 // to avoid redifinition of EIGEN_MATRIXBASE_PLUGIN for Eigen 3.3.0 and later
13 //#include <cppad/example/cppad_eigen.hpp>
14 
15 #ifdef PINOCCHIO_CPPAD_REQUIRES_MATRIX_BASE_PLUGIN
16  #define EIGEN_MATRIXBASE_PLUGIN <cppad/example/eigen_plugin.hpp>
17 #endif
18 
19 #include <cppad/cppad.hpp>
20 #include <Eigen/Dense>
21 
22 namespace boost
23 {
24  namespace math
25  {
26  namespace constants
27  {
28  namespace detail
29  {
30  template<typename Scalar>
31  struct constant_pi< CppAD::AD<Scalar> > : constant_pi<Scalar> {};
32  }
33  }
34  }
35 }
36 
37 namespace Eigen
38 {
39  namespace internal
40  {
41  // Specialization of Eigen::internal::cast_impl for CppAD input types
42  template<typename Scalar>
43  struct cast_impl<CppAD::AD<Scalar>,Scalar>
44  {
45 #if EIGEN_VERSION_AT_LEAST(3,2,90)
46  EIGEN_DEVICE_FUNC
47 #endif
48  static inline Scalar run(const CppAD::AD<Scalar> & x)
49  {
50  return CppAD::Value(x);
51  }
52  };
53  }
54 } //namespace Eigen
55 
57 namespace Eigen
58 {
59  template <class Base> struct NumTraits< CppAD::AD<Base> >
60  { // type that corresponds to the real part of an AD<Base> value
61  typedef CppAD::AD<Base> Real;
62  // type for AD<Base> operations that result in non-integer values
63  typedef CppAD::AD<Base> NonInteger;
64  // type to use for numeric literals such as "2" or "0.5".
65  typedef CppAD::AD<Base> Literal;
66  // type for nested value inside an AD<Base> expression tree
67  typedef CppAD::AD<Base> Nested;
68 
69  enum {
70  // does not support complex Base types
71  IsComplex = 0 ,
72  // does not support integer Base types
73  IsInteger = 0 ,
74  // only support signed Base types
75  IsSigned = 1 ,
76  // must initialize an AD<Base> object
77  RequireInitialization = 1 ,
78  // computational cost of the corresponding operations
79  ReadCost = 1 ,
80  AddCost = 2 ,
81  MulCost = 2
82  };
83 
84  // machine epsilon with type of real part of x
85  // (use assumption that Base is not complex)
86  static CppAD::AD<Base> epsilon(void)
87  { return CppAD::numeric_limits< CppAD::AD<Base> >::epsilon(); }
88 
89  // relaxed version of machine epsilon for comparison of different
90  // operations that should result in the same value
91  static CppAD::AD<Base> dummy_precision(void)
92  { return 100. *
93  CppAD::numeric_limits< CppAD::AD<Base> >::epsilon();
94  }
95 
96  // minimum normalized positive value
97  static CppAD::AD<Base> lowest(void)
98  { return CppAD::numeric_limits< CppAD::AD<Base> >::min(); }
99 
100  // maximum finite value
101  static CppAD::AD<Base> highest(void)
102  { return CppAD::numeric_limits< CppAD::AD<Base> >::max(); }
103 
104  // number of decimal digits that can be represented without change.
105  static int digits10(void)
106  { return CppAD::numeric_limits< CppAD::AD<Base> >::digits10; }
107  };
108 } // namespace Eigen
109 
111 namespace CppAD
112 {
113  // functions that return references
114  template <class Base> const AD<Base>& conj(const AD<Base>& x)
115  { return x; }
116  template <class Base> const AD<Base>& real(const AD<Base>& x)
117  { return x; }
118 
119  // functions that return values (note abs is defined by cppad.hpp)
120  template <class Base> AD<Base> imag(const AD<Base>& /*x*/)
121  { return CppAD::AD<Base>(0.); }
122  template <class Base> AD<Base> abs2(const AD<Base>& x)
123  { return x * x; }
124 } // namespace CppAD
125 
126 namespace pinocchio
127 {
128  template<typename Scalar>
129  struct TaylorSeriesExpansion< CppAD::AD<Scalar> > : TaylorSeriesExpansion<Scalar>
130  {
132  using Base::precision;
133  };
134 } // namespace pinocchio
135 
136 #endif // #ifndef __pinocchio_autodiff_ccpad_hpp__
Source from #include <cppad/example/cppad_eigen.hpp>
Source from #include <cppad/example/cppad_eigen.hpp>
Main pinocchio namespace.
Definition: treeview.dox:24