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 <boost/mpl/int.hpp>
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  typedef CppAD::AD<Scalar> ADScalar;
34 
35  template<int N>
36  static inline ADScalar get(const mpl::int_<N> & n)
37  {
38  return ADScalar(constant_pi<Scalar>::get(n));
39  }
40 
41 #if BOOST_VERSION >= 107700
42  template<class T, T value>
43  static inline ADScalar get(const std::integral_constant<T, value> & n)
44  {
45  return ADScalar(constant_pi<Scalar>::get(n));
46  }
47 #else
48  template<class T, T value>
49  static inline ADScalar get(const boost::integral_constant<T, value> & n)
50  {
51  return ADScalar(constant_pi<Scalar>::get(n));
52  }
53 #endif
54  };
55  } // namespace detail
56  } // namespace constants
57  } // namespace math
58 } // namespace boost
59 
60 namespace Eigen
61 {
62  namespace internal
63  {
64  // Specialization of Eigen::internal::cast_impl for CppAD input types
65  template<typename Scalar>
66  struct cast_impl<CppAD::AD<Scalar>, Scalar>
67  {
68 #if EIGEN_VERSION_AT_LEAST(3, 2, 90)
70 #endif
71  static inline Scalar run(const CppAD::AD<Scalar> & x)
72  {
73  return CppAD::Value(x);
74  }
75  };
76  } // namespace internal
77 } // namespace Eigen
78 
79 // Source from #include <cppad/example/cppad_eigen.hpp>
80 namespace Eigen
81 {
82  template<class Base>
83  struct NumTraits<CppAD::AD<Base>>
84  { // type that corresponds to the real part of an AD<Base> value
85  typedef CppAD::AD<Base> Real;
86  // type for AD<Base> operations that result in non-integer values
87  typedef CppAD::AD<Base> NonInteger;
88  // type to use for numeric literals such as "2" or "0.5".
89  typedef CppAD::AD<Base> Literal;
90  // type for nested value inside an AD<Base> expression tree
91  typedef CppAD::AD<Base> Nested;
92 
93  enum
94  {
95  // does not support complex Base types
96  IsComplex = 0,
97  // does not support integer Base types
98  IsInteger = 0,
99  // only support signed Base types
100  IsSigned = 1,
101  // must initialize an AD<Base> object
102  RequireInitialization = 1,
103  // computational cost of the corresponding operations
104  ReadCost = 1,
105  AddCost = 2,
106  MulCost = 2
107  };
108 
109  // machine epsilon with type of real part of x
110  // (use assumption that Base is not complex)
111  static CppAD::AD<Base> epsilon(void)
112  {
113  return CppAD::numeric_limits<CppAD::AD<Base>>::epsilon();
114  }
115 
116  // relaxed version of machine epsilon for comparison of different
117  // operations that should result in the same value
118  static CppAD::AD<Base> dummy_precision(void)
119  {
120  return 100. * CppAD::numeric_limits<CppAD::AD<Base>>::epsilon();
121  }
122 
123  // minimum normalized positive value
124  static CppAD::AD<Base> lowest(void)
125  {
126  return CppAD::numeric_limits<CppAD::AD<Base>>::min();
127  }
128 
129  // maximum finite value
130  static CppAD::AD<Base> highest(void)
131  {
132  return CppAD::numeric_limits<CppAD::AD<Base>>::max();
133  }
134 
135  // number of decimal digits that can be represented without change.
136  static int digits10(void)
137  {
138  return CppAD::numeric_limits<CppAD::AD<Base>>::digits10;
139  }
140  };
141 } // namespace Eigen
142 
143 // Source from #include <cppad/example/cppad_eigen.hpp>
145 
146 namespace CppAD
147 {
148  // functions that return references
149  template<class Base>
150  const AD<Base> & conj(const AD<Base> & x)
151  {
152  return x;
153  }
154  template<class Base>
155  const AD<Base> & real(const AD<Base> & x)
156  {
157  return x;
158  }
159 
160  // functions that return values (note abs is defined by cppad.hpp)
161  template<class Base>
162  AD<Base> imag(const AD<Base> & /*x*/)
163  {
164  return CppAD::AD<Base>(0.);
165  }
166  template<class Base>
167  AD<Base> abs2(const AD<Base> & x)
168  {
169  return x * x;
170  }
171 
172  template<typename Scalar>
173  AD<Scalar> min(const AD<Scalar> & x, const AD<Scalar> & y)
174  {
177  return if_then_else(LT, y, x, y, x);
178  }
179 
180  template<typename Scalar>
181  AD<Scalar> max(const AD<Scalar> & x, const AD<Scalar> & y)
182  {
185  return if_then_else(LT, x, y, y, x);
186  }
187 } // namespace CppAD
188 
189 namespace CppAD
190 {
191  template<class Scalar>
192  bool isfinite(const AD<Scalar> & x)
193  {
194  return isfinite(Value(x));
195  }
196 } // namespace CppAD
197 
199 
200 namespace pinocchio
201 {
202  template<typename Scalar>
203  struct TaylorSeriesExpansion<CppAD::AD<Scalar>> : TaylorSeriesExpansion<Scalar>
204  {
206  typedef CppAD::AD<Scalar> ADScalar;
207 
208  template<int degree>
210  {
211  return ADScalar(Base::template precision<degree>());
212  }
213  };
214 
215  template<typename Scalar, typename ADScalar>
216  struct ScalarCast<Scalar, CppAD::AD<ADScalar>>
217  {
218  static Scalar cast(const CppAD::AD<ADScalar> & value)
219  {
220  return scalar_cast<Scalar>(CppAD::Value(value));
221  }
222  };
223 
224 } // namespace pinocchio
225 
227 #include "pinocchio/autodiff/cppad/spatial/log.hxx"
231 
232 #endif // #ifndef __pinocchio_autodiff_cppad_hpp__
pinocchio::TaylorSeriesExpansion< CppAD::AD< Scalar > >::precision
static ADScalar precision()
Definition: autodiff/cppad.hpp:209
Eigen
static-if.hpp
static-if.hpp
CppAD::imag
AD< Base > imag(const AD< Base > &)
Definition: autodiff/cppad.hpp:162
y
y
CppAD::isfinite
bool isfinite(const AD< Scalar > &x)
Definition: autodiff/cppad.hpp:192
pinocchio::python::Scalar
context::Scalar Scalar
Definition: admm-solver.cpp:29
Eigen::NumTraits< CppAD::AD< Base > >::Nested
CppAD::AD< Base > Nested
Definition: autodiff/cppad.hpp:91
Eigen::NumTraits< CppAD::AD< Base > >::lowest
static CppAD::AD< Base > lowest(void)
Definition: autodiff/cppad.hpp:124
boost::math::constants::detail::constant_pi< CppAD::AD< Scalar > >::get
static ADScalar get(const mpl::int_< N > &n)
Definition: autodiff/cppad.hpp:36
boost
pinocchio::internal::if_then_else
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)
Definition: utils/static-if.hpp:89
CppAD
Definition: autodiff/cppad.hpp:146
CppAD::abs2
AD< Base > abs2(const AD< Base > &x)
Definition: autodiff/cppad.hpp:167
pinocchio::ScalarCast< Scalar, CppAD::AD< ADScalar > >::cast
static Scalar cast(const CppAD::AD< ADScalar > &value)
Definition: autodiff/cppad.hpp:218
Eigen::NumTraits< CppAD::AD< Base > >::dummy_precision
static CppAD::AD< Base > dummy_precision(void)
Definition: autodiff/cppad.hpp:118
Eigen::NumTraits< CppAD::AD< Base > >::Real
CppAD::AD< Base > Real
Definition: autodiff/cppad.hpp:85
Eigen::NumTraits< CppAD::AD< Base > >::epsilon
static CppAD::AD< Base > epsilon(void)
Definition: autodiff/cppad.hpp:111
pinocchio::TaylorSeriesExpansion< CppAD::AD< Scalar > >::ADScalar
CppAD::AD< Scalar > ADScalar
Definition: autodiff/cppad.hpp:206
Eigen::NumTraits< CppAD::AD< Base > >::NonInteger
CppAD::AD< Base > NonInteger
Definition: autodiff/cppad.hpp:87
fwd.hpp
se3-tpl.hpp
value
float value
x
x
boost::math::constants::detail::constant_pi< CppAD::AD< Scalar > >::ADScalar
CppAD::AD< Scalar > ADScalar
Definition: autodiff/cppad.hpp:33
Eigen::NumTraits< CppAD::AD< Base > >::digits10
static int digits10(void)
Definition: autodiff/cppad.hpp:136
pinocchio::TaylorSeriesExpansion
&#160;
Definition: math/fwd.hpp:34
Eigen::internal::cast_impl< CppAD::AD< Scalar >, Scalar >::run
static Scalar run(const CppAD::AD< Scalar > &x)
Definition: autodiff/cppad.hpp:71
CppAD::conj
const AD< Base > & conj(const AD< Base > &x)
Definition: autodiff/cppad.hpp:150
CppAD::real
const AD< Base > & real(const AD< Base > &x)
Definition: autodiff/cppad.hpp:155
boost::math::constants::detail::constant_pi< CppAD::AD< Scalar > >::get
static ADScalar get(const boost::integral_constant< T, value > &n)
Definition: autodiff/cppad.hpp:49
pinocchio::internal::LT
@ LT
Definition: utils/static-if.hpp:17
Eigen::NumTraits< CppAD::AD< Base > >::highest
static CppAD::AD< Base > highest(void)
Definition: autodiff/cppad.hpp:130
quaternion.hpp
aba.hpp
CppAD::min
AD< Scalar > min(const AD< Scalar > &x, const AD< Scalar > &y)
Definition: autodiff/cppad.hpp:173
CppAD::max
AD< Scalar > max(const AD< Scalar > &x, const AD< Scalar > &y)
Definition: autodiff/cppad.hpp:181
Eigen::NumTraits< CppAD::AD< Base > >::Literal
CppAD::AD< Base > Literal
Definition: autodiff/cppad.hpp:89
pinocchio::TaylorSeriesExpansion< CppAD::AD< Scalar > >::Base
TaylorSeriesExpansion< Scalar > Base
Definition: autodiff/cppad.hpp:205
EIGEN_DEVICE_FUNC
#define EIGEN_DEVICE_FUNC
Definition: tensor.hpp:11
n
Vec3f n
pinocchio::ScalarCast
Cast scalar type from type FROM to type TO.
Definition: fwd.hpp:105
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27


pinocchio
Author(s):
autogenerated on Fri Nov 1 2024 02:41:43