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