pinocchio  2.7.1
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
cppad.hpp
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 #if BOOST_VERSION >= 107700
41  template <class T, T value>
42  static inline ADScalar get(const std::integral_constant<T, value> &n)
43  {
44  return ADScalar(constant_pi<Scalar>::get(n));
45  }
46 #else
47  template <class T, T value>
48  static inline ADScalar get(const boost::integral_constant<T, value> &n)
49  {
50  return ADScalar(constant_pi<Scalar>::get(n));
51  }
52 #endif
53  };
54  }
55  }
56  }
57 }
58 
59 namespace Eigen
60 {
61  namespace internal
62  {
63  // Specialization of Eigen::internal::cast_impl for CppAD input types
64  template<typename Scalar>
65  struct cast_impl<CppAD::AD<Scalar>,Scalar>
66  {
67 #if EIGEN_VERSION_AT_LEAST(3,2,90)
68  EIGEN_DEVICE_FUNC
69 #endif
70  static inline Scalar run(const CppAD::AD<Scalar> & x)
71  {
72  return CppAD::Value(x);
73  }
74  };
75  }
76 } //namespace Eigen
77 
78 // Source from #include <cppad/example/cppad_eigen.hpp>
79 namespace Eigen
80 {
81  template <class Base> struct NumTraits< CppAD::AD<Base> >
82  { // type that corresponds to the real part of an AD<Base> value
83  typedef CppAD::AD<Base> Real;
84  // type for AD<Base> operations that result in non-integer values
85  typedef CppAD::AD<Base> NonInteger;
86  // type to use for numeric literals such as "2" or "0.5".
87  typedef CppAD::AD<Base> Literal;
88  // type for nested value inside an AD<Base> expression tree
89  typedef CppAD::AD<Base> Nested;
90 
91  enum {
92  // does not support complex Base types
93  IsComplex = 0 ,
94  // does not support integer Base types
95  IsInteger = 0 ,
96  // only support signed Base types
97  IsSigned = 1 ,
98  // must initialize an AD<Base> object
99  RequireInitialization = 1 ,
100  // computational cost of the corresponding operations
101  ReadCost = 1 ,
102  AddCost = 2 ,
103  MulCost = 2
104  };
105 
106  // machine epsilon with type of real part of x
107  // (use assumption that Base is not complex)
108  static CppAD::AD<Base> epsilon(void)
109  { return CppAD::numeric_limits< CppAD::AD<Base> >::epsilon(); }
110 
111  // relaxed version of machine epsilon for comparison of different
112  // operations that should result in the same value
113  static CppAD::AD<Base> dummy_precision(void)
114  { return 100. *
115  CppAD::numeric_limits< CppAD::AD<Base> >::epsilon();
116  }
117 
118  // minimum normalized positive value
119  static CppAD::AD<Base> lowest(void)
120  { return CppAD::numeric_limits< CppAD::AD<Base> >::min(); }
121 
122  // maximum finite value
123  static CppAD::AD<Base> highest(void)
124  { return CppAD::numeric_limits< CppAD::AD<Base> >::max(); }
125 
126  // number of decimal digits that can be represented without change.
127  static int digits10(void)
128  { return CppAD::numeric_limits< CppAD::AD<Base> >::digits10; }
129  };
130 } // namespace Eigen
131 
132 // Source from #include <cppad/example/cppad_eigen.hpp>
133 #include "pinocchio/utils/static-if.hpp"
134 
135 
136 namespace CppAD
137 {
138  // functions that return references
139  template <class Base> const AD<Base>& conj(const AD<Base>& x)
140  { return x; }
141  template <class Base> const AD<Base>& real(const AD<Base>& x)
142  { return x; }
143 
144  // functions that return values (note abs is defined by cppad.hpp)
145  template <class Base> AD<Base> imag(const AD<Base>& /*x*/)
146  { return CppAD::AD<Base>(0.); }
147  template <class Base> AD<Base> abs2(const AD<Base>& x)
148  { return x * x; }
149 
150  template<typename Scalar>
151  AD<Scalar> min(const AD<Scalar>& x, const AD<Scalar>& y)
152  {
153  using ::pinocchio::internal::if_then_else;
154  using ::pinocchio::internal::LT;
155  return if_then_else(LT, y, x, y, x);
156  }
157 
158  template<typename Scalar>
159  AD<Scalar> max(const AD<Scalar>& x, const AD<Scalar>& y)
160  {
161  using ::pinocchio::internal::if_then_else;
162  using ::pinocchio::internal::LT;
163  return if_then_else(LT, x, y, y, x);
164  }
165 
166 } // namespace CppAD
167 
168 #include "pinocchio/utils/static-if.hpp"
169 
170 namespace pinocchio
171 {
172  template<typename Scalar>
173  struct TaylorSeriesExpansion< CppAD::AD<Scalar> > : TaylorSeriesExpansion<Scalar>
174  {
176  typedef CppAD::AD<Scalar> ADScalar;
177 
178  template<int degree>
179  static ADScalar precision()
180  {
181  return ADScalar(Base::template precision<degree>());
182  }
183 
184  };
185 
186 } // namespace pinocchio
187 
188 #include "pinocchio/autodiff/cppad/spatial/se3-tpl.hpp"
189 #include "pinocchio/autodiff/cppad/spatial/log.hxx"
190 #include "pinocchio/autodiff/cppad/utils/static-if.hpp"
191 #include "pinocchio/autodiff/cppad/math/quaternion.hpp"
192 #include "pinocchio/autodiff/cppad/algorithm/aba.hpp"
193 
194 
195 #endif // #ifndef __pinocchio_autodiff_cppad_hpp__
continuous.x
x
— Training
Definition: continuous.py:157
pinocchio::TaylorSeriesExpansion
&#160;
Definition: fwd.hpp:31
pinocchio::TaylorSeriesExpansion::precision
static Scalar precision()
Computes the expected tolerance of the argument of a Taylor series expansion for a certain degree acc...
Definition: taylor-expansion.hpp:30
pinocchio
Main pinocchio namespace.
Definition: treeview.dox:11