pinocchio  2.4.5
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
cppadcg.hpp
1 //
2 // Copyright (c) 2018-2020 CNRS INRIA
3 //
4 
5 #ifndef __pinocchio_codegen_ccpadcg_hpp__
6 #define __pinocchio_codegen_ccpadcg_hpp__
7 
8 #include "pinocchio/math/fwd.hpp"
9 
10 #include <cmath>
11 #include <cppad/cg/support/cppadcg_eigen.hpp>
12 
13 #include "pinocchio/autodiff/cppad.hpp"
14 
15 #ifndef PINOCCHIO_WITH_CXX11_SUPPORT
16  #error CppADCodeGen requires C++11 or more
17 #endif
18 
19 namespace boost
20 {
21  namespace math
22  {
23  namespace constants
24  {
25  namespace detail
26  {
27  template<typename Scalar>
28  struct constant_pi< CppAD::cg::CG<Scalar> > : constant_pi<Scalar>
29  {
30  typedef CppAD::cg::CG<Scalar> CGScalar;
31 
32  template <int N>
33  static inline CGScalar get(const mpl::int_<N>& n)
34  {
35  return CGScalar(constant_pi<Scalar>::get(n));
36  }
37  };
38  }
39  }
40  }
41 }
42 
43 namespace Eigen
44 {
45  namespace internal
46  {
47  // Specialization of Eigen::internal::cast_impl for CppAD input types
48  template<typename Scalar>
49  struct cast_impl<CppAD::cg::CG<Scalar>,Scalar>
50  {
51 #if EIGEN_VERSION_AT_LEAST(3,2,90)
52  EIGEN_DEVICE_FUNC
53 #endif
54  static inline Scalar run(const CppAD::cg::CG<Scalar> & x)
55  {
56  return x.getValue();
57  }
58  };
59  }
60 } // namespace Eigen
61 
62 namespace CppAD
63 {
64  template <class Scalar>
65  bool isfinite(const cg::CG<Scalar> & x) { return std::isfinite(x.getValue()); }
66 
67  template <class Scalar>
68  bool isfinite(const AD<Scalar> & x) { return isfinite(Value(x)); }
69 }
70 
71 namespace pinocchio
72 {
73  template<typename Scalar>
74  struct TaylorSeriesExpansion< CppAD::cg::CG<Scalar> >
75  {
77  typedef CppAD::cg::CG<Scalar> CGScalar;
78 
79  template<int degree>
80  static CGScalar precision()
81  {
82  return CGScalar(Base::template precision<degree>());
83  }
84 
85  };
86 } // namespace pinocchio
87 
88 #endif // #ifndef __pinocchio_codegen_ccpadcg_hpp__
Definition: casadi.hpp:13
Definition: casadi.hpp:47
Definition: cppad.hpp:121
Main pinocchio namespace.
Definition: treeview.dox:24