autodiff/cppad.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2018-2020 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  };
41  }
42  }
43  }
44 }
45 
46 namespace Eigen
47 {
48  namespace internal
49  {
50  // Specialization of Eigen::internal::cast_impl for CppAD input types
51  template<typename Scalar>
52  struct cast_impl<CppAD::AD<Scalar>,Scalar>
53  {
54 #if EIGEN_VERSION_AT_LEAST(3,2,90)
56 #endif
57  static inline Scalar run(const CppAD::AD<Scalar> & x)
58  {
59  return CppAD::Value(x);
60  }
61  };
62  }
63 } //namespace Eigen
64 
65 // Source from #include <cppad/example/cppad_eigen.hpp>
66 namespace Eigen
67 {
68  template <class Base> struct NumTraits< CppAD::AD<Base> >
69  { // type that corresponds to the real part of an AD<Base> value
70  typedef CppAD::AD<Base> Real;
71  // type for AD<Base> operations that result in non-integer values
72  typedef CppAD::AD<Base> NonInteger;
73  // type to use for numeric literals such as "2" or "0.5".
74  typedef CppAD::AD<Base> Literal;
75  // type for nested value inside an AD<Base> expression tree
76  typedef CppAD::AD<Base> Nested;
77 
78  enum {
79  // does not support complex Base types
80  IsComplex = 0 ,
81  // does not support integer Base types
82  IsInteger = 0 ,
83  // only support signed Base types
84  IsSigned = 1 ,
85  // must initialize an AD<Base> object
86  RequireInitialization = 1 ,
87  // computational cost of the corresponding operations
88  ReadCost = 1 ,
89  AddCost = 2 ,
90  MulCost = 2
91  };
92 
93  // machine epsilon with type of real part of x
94  // (use assumption that Base is not complex)
95  static CppAD::AD<Base> epsilon(void)
96  { return CppAD::numeric_limits< CppAD::AD<Base> >::epsilon(); }
97 
98  // relaxed version of machine epsilon for comparison of different
99  // operations that should result in the same value
100  static CppAD::AD<Base> dummy_precision(void)
101  { return 100. *
102  CppAD::numeric_limits< CppAD::AD<Base> >::epsilon();
103  }
104 
105  // minimum normalized positive value
106  static CppAD::AD<Base> lowest(void)
107  { return CppAD::numeric_limits< CppAD::AD<Base> >::min(); }
108 
109  // maximum finite value
110  static CppAD::AD<Base> highest(void)
111  { return CppAD::numeric_limits< CppAD::AD<Base> >::max(); }
112 
113  // number of decimal digits that can be represented without change.
114  static int digits10(void)
115  { return CppAD::numeric_limits< CppAD::AD<Base> >::digits10; }
116  };
117 } // namespace Eigen
118 
119 // Source from #include <cppad/example/cppad_eigen.hpp>
120 #include "pinocchio/utils/static-if.hpp"
121 
122 
123 namespace CppAD
124 {
125  // functions that return references
126  template <class Base> const AD<Base>& conj(const AD<Base>& x)
127  { return x; }
128  template <class Base> const AD<Base>& real(const AD<Base>& x)
129  { return x; }
130 
131  // functions that return values (note abs is defined by cppad.hpp)
132  template <class Base> AD<Base> imag(const AD<Base>& /*x*/)
133  { return CppAD::AD<Base>(0.); }
134  template <class Base> AD<Base> abs2(const AD<Base>& x)
135  { return x * x; }
136 
137  template<typename Scalar>
138  AD<Scalar> min(const AD<Scalar>& x, const AD<Scalar>& y)
139  {
142  return if_then_else(LT, y, x, y, x);
143  }
144 
145  template<typename Scalar>
146  AD<Scalar> max(const AD<Scalar>& x, const AD<Scalar>& y)
147  {
150  return if_then_else(LT, x, y, y, x);
151  }
152 
153 } // namespace CppAD
154 
155 #include "pinocchio/utils/static-if.hpp"
156 
157 namespace pinocchio
158 {
159  template<typename Scalar>
160  struct TaylorSeriesExpansion< CppAD::AD<Scalar> > : TaylorSeriesExpansion<Scalar>
161  {
163  typedef CppAD::AD<Scalar> ADScalar;
164 
165  template<int degree>
166  static ADScalar precision()
167  {
168  return ADScalar(Base::template precision<degree>());
169  }
170 
171  };
172 
173 } // namespace pinocchio
174 
175 #include "pinocchio/autodiff/cppad/spatial/se3-tpl.hpp"
176 #include "pinocchio/autodiff/cppad/spatial/log.hxx"
177 #include "pinocchio/autodiff/cppad/utils/static-if.hpp"
178 #include "pinocchio/autodiff/cppad/math/quaternion.hpp"
179 #include "pinocchio/autodiff/cppad/algorithm/aba.hpp"
180 
181 
182 #endif // #ifndef __pinocchio_autodiff_cppad_hpp__
const AD< Base > & conj(const AD< Base > &x)
Eigen::Matrix< typename ComplexMatrix::RealScalar, ComplexMatrix::RowsAtCompileTime, ComplexMatrix::ColsAtCompileTime, ComplexMatrix::Options > imag(const Eigen::MatrixBase< ComplexMatrix > &complex_mat)
static CppAD::AD< Base > highest(void)
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)
Eigen::Matrix< typename ComplexMatrix::RealScalar, ComplexMatrix::RowsAtCompileTime, ComplexMatrix::ColsAtCompileTime, ComplexMatrix::Options > real(const Eigen::MatrixBase< ComplexMatrix > &complex_mat)
Main pinocchio namespace.
Definition: timings.cpp:30
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)
x
— Training
Definition: continuous.py:157
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 Tue Jun 1 2021 02:45:02