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