codegen/cppadcg.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2018-2023 CNRS INRIA
3 //
4 
5 #ifndef __pinocchio_codegen_ccpadcg_hpp__
6 #define __pinocchio_codegen_ccpadcg_hpp__
7 
8 #define PINOCCHIO_WITH_CPPADCG_SUPPORT
9 
10 #include "pinocchio/math/fwd.hpp"
11 
12 #include <cmath>
13 #include <boost/mpl/int.hpp>
14 #include <cppad/cg/support/cppadcg_eigen.hpp>
15 
17 
18 namespace boost
19 {
20  namespace math
21  {
22  namespace constants
23  {
24  namespace detail
25  {
26  template<typename Scalar>
27  struct constant_pi<CppAD::cg::CG<Scalar>> : constant_pi<Scalar>
28  {
29  typedef CppAD::cg::CG<Scalar> CGScalar;
30 
31  template<int N>
32  static inline CGScalar get(const mpl::int_<N> & n)
33  {
34  return CGScalar(constant_pi<Scalar>::get(n));
35  }
36 
37 #if BOOST_VERSION >= 107700
38  template<class T, T value>
39  static inline CGScalar get(const std::integral_constant<T, value> & n)
40  {
41  return CGScalar(constant_pi<Scalar>::get(n));
42  }
43 #else
44  template<class T, T value>
45  static inline CGScalar get(const boost::integral_constant<T, value> & n)
46  {
47  return CGScalar(constant_pi<Scalar>::get(n));
48  }
49 #endif
50  };
51  } // namespace detail
52  } // namespace constants
53  } // namespace math
54 } // namespace boost
55 
56 namespace Eigen
57 {
58  namespace internal
59  {
60  // Specialization of Eigen::internal::cast_impl for CppAD input types
61  template<typename Scalar>
62  struct cast_impl<CppAD::cg::CG<Scalar>, Scalar>
63  {
64 #if EIGEN_VERSION_AT_LEAST(3, 2, 90)
66 #endif
67  static inline Scalar run(const CppAD::cg::CG<Scalar> & x)
68  {
69  return x.getValue();
70  }
71  };
72 
73  // Specialization of Eigen::internal::cast_impl for CppAD input types
74  template<typename Scalar>
75  struct cast_impl<CppAD::AD<CppAD::cg::CG<Scalar>>, Scalar>
76  {
77 #if EIGEN_VERSION_AT_LEAST(3, 2, 90)
79 #endif
80  static inline Scalar run(const CppAD::AD<CppAD::cg::CG<Scalar>> & x)
81  {
82  return CppAD::Value(x).getValue();
83  }
84  };
85 
86  } // namespace internal
87 } // namespace Eigen
88 
89 namespace CppAD
90 {
91  namespace cg
92  {
93  template<class Scalar>
94  bool isfinite(const CG<Scalar> & x)
95  {
96  return std::isfinite(x.getValue());
97  }
98  } // namespace cg
99 } // namespace CppAD
100 
101 namespace pinocchio
102 {
103  template<typename Scalar>
104  struct TaylorSeriesExpansion<CppAD::cg::CG<Scalar>>
105  {
107  typedef CppAD::cg::CG<Scalar> CGScalar;
108 
109  template<int degree>
111  {
112  return CGScalar(Base::template precision<degree>());
113  }
114  };
115 
116  template<typename NewScalar, typename Scalar>
117  struct ScalarCast<NewScalar, CppAD::cg::CG<Scalar>>
118  {
119  static NewScalar cast(const CppAD::cg::CG<Scalar> & cg_value)
120  {
121  return static_cast<NewScalar>(cg_value.getValue());
122  }
123  };
124 
125 } // namespace pinocchio
126 
127 #endif // #ifndef __pinocchio_codegen_ccpadcg_hpp__
Eigen
CGScalar
CppAD::cg::CG< Scalar > CGScalar
Definition: timings-cppad-jit.cpp:39
pinocchio::TaylorSeriesExpansion< CppAD::cg::CG< Scalar > >::precision
static CGScalar precision()
Definition: codegen/cppadcg.hpp:110
pinocchio::ScalarCast< NewScalar, CppAD::cg::CG< Scalar > >::cast
static NewScalar cast(const CppAD::cg::CG< Scalar > &cg_value)
Definition: codegen/cppadcg.hpp:119
pinocchio::TaylorSeriesExpansion< CppAD::cg::CG< Scalar > >::CGScalar
CppAD::cg::CG< Scalar > CGScalar
Definition: codegen/cppadcg.hpp:107
pinocchio::TaylorSeriesExpansion< CppAD::cg::CG< Scalar > >::Base
TaylorSeriesExpansion< Scalar > Base
Definition: codegen/cppadcg.hpp:106
boost
CppAD
Definition: autodiff/cppad.hpp:146
boost::math::constants::detail::constant_pi< CppAD::cg::CG< Scalar > >::get
static CGScalar get(const mpl::int_< N > &n)
Definition: codegen/cppadcg.hpp:32
Eigen::internal::cast_impl< CppAD::cg::CG< Scalar >, Scalar >::run
static Scalar run(const CppAD::cg::CG< Scalar > &x)
Definition: codegen/cppadcg.hpp:67
fwd.hpp
x
x
pinocchio::TaylorSeriesExpansion
&#160;
Definition: math/fwd.hpp:34
boost::math::constants::detail::constant_pi< CppAD::cg::CG< Scalar > >::CGScalar
CppAD::cg::CG< Scalar > CGScalar
Definition: codegen/cppadcg.hpp:29
cppad.hpp
Eigen::internal::cast_impl< CppAD::AD< CppAD::cg::CG< Scalar > >, Scalar >::run
static Scalar run(const CppAD::AD< CppAD::cg::CG< Scalar >> &x)
Definition: codegen/cppadcg.hpp:80
CppAD::cg::isfinite
bool isfinite(const CG< Scalar > &x)
Definition: codegen/cppadcg.hpp:94
Scalar
double Scalar
Definition: timings-cppad-jit.cpp:37
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:33
boost::math::constants::detail::constant_pi< CppAD::cg::CG< Scalar > >::get
static CGScalar get(const boost::integral_constant< T, value > &n)
Definition: codegen/cppadcg.hpp:45


pinocchio
Author(s):
autogenerated on Sat Apr 19 2025 02:41:32