multiprecision.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 INRIA
3 //
4 
5 #ifndef __pinocchio_math_mutliprecision_hpp__
6 #define __pinocchio_math_mutliprecision_hpp__
7 
8 #include "pinocchio/math/fwd.hpp"
9 
10 #ifndef PINOCCHIO_WITH_CXX11_SUPPORT
11  #error C++11 compiler required.
12 #endif
13 
14 #include <boost/multiprecision/number.hpp>
15 #include <boost/random.hpp>
16 #include <Eigen/Dense>
17 
18 namespace pinocchio
19 {
20  // We check std::numeric_limits<_>::has_infinity to exclude integral, rational
21  // and complex types
22  template<typename Backend, boost::multiprecision::expression_template_option ET>
24  : boost::integral_constant<
25  bool,
26  ((!std::numeric_limits<boost::multiprecision::number<Backend, ET>>::is_integer
27  && std::numeric_limits<boost::multiprecision::number<Backend, ET>>::has_infinity))>
28  {
29  };
30 } // namespace pinocchio
31 
32 namespace Eigen
33 {
34  namespace internal
35  {
36  template<
37  class Backend,
38  boost::multiprecision::expression_template_option ExpressionTemplates,
39  typename Scalar>
40  struct cast_impl<boost::multiprecision::number<Backend, ExpressionTemplates>, Scalar>
41  {
42 #if EIGEN_VERSION_AT_LEAST(3, 2, 90)
44 #endif
45  static inline Scalar
46  run(const boost::multiprecision::number<Backend, ExpressionTemplates> & x)
47  {
48  return x.template convert_to<Scalar>();
49  }
50  };
51  } // namespace internal
52 } // namespace Eigen
53 
54 #ifndef BOOST_MP_EIGEN_HPP
55 
56 // Code adapted from <boost/multiprecision/eigen.hpp>
57 // Copyright 2018 John Maddock. Distributed under the Boost
58 // Software License, Version 1.0. (See accompanying file
59 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
60 namespace Eigen
61 {
62  template<class Backend, boost::multiprecision::expression_template_option ExpressionTemplates>
63  struct NumTraits<boost::multiprecision::number<Backend, ExpressionTemplates>>
64  {
65  typedef boost::multiprecision::number<Backend, ExpressionTemplates> self_type;
66  #if BOOST_VERSION / 100 % 1000 >= 68
67  typedef
69  #else
70  typedef self_type Real;
71  #endif
72  typedef self_type NonInteger; // Not correct but we can't do much better??
73  typedef double Literal;
74  typedef self_type Nested;
75  enum
76  {
77  #if BOOST_VERSION / 100 % 1000 >= 68
78  IsComplex = boost::multiprecision::number_category<self_type>::value
79  == boost::multiprecision::number_kind_complex,
80  #else
81  IsComplex = 0,
82  #endif
83  IsInteger = boost::multiprecision::number_category<self_type>::value
84  == boost::multiprecision::number_kind_integer,
85  ReadCost = 1,
86  AddCost = 4,
87  MulCost = 8,
88  IsSigned = std::numeric_limits<self_type>::is_specialized
89  ? std::numeric_limits<self_type>::is_signed
90  : true,
91  RequireInitialization = 1
92  };
93  static Real epsilon()
94  {
95  return std::numeric_limits<Real>::epsilon();
96  }
98  {
99  return 1000 * epsilon();
100  }
101  static Real highest()
102  {
104  }
105  static Real lowest()
106  {
108  }
109  static int digits10_imp(const boost::mpl::true_ &)
110  {
111  return std::numeric_limits<Real>::digits10;
112  }
113  template<bool B>
114  static int digits10_imp(const boost::mpl::bool_<B> &)
115  {
116  return static_cast<int>(Real::default_precision());
117  }
118  static int digits10()
119  {
120  return digits10_imp(
121  boost::mpl::bool_ < std::numeric_limits<Real>::digits10
122  && (std::numeric_limits<Real>::digits10 != INT_MAX)
123  ? true
124  : false > ());
125  }
126 
127  constexpr static inline int digits()
128  {
130  }
131 
132  #if EIGEN_VERSION_AT_LEAST(3, 4, 90)
133  constexpr static inline int max_digits10()
134  {
136  }
137  #endif
138  };
139 
140  template<class tag, class Arg1, class Arg2, class Arg3, class Arg4>
141  struct NumTraits<boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>>
142  : public NumTraits<
143  typename boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>::result_type>
144  {
145  };
146 
147  #if EIGEN_VERSION_AT_LEAST(3, 4, 90)
148  // Fix random generator number in 3.4.90. TODO(jcarpent): Yet, we should wait for Eigen 3.5.0 to
149  // the proper fix in Eigen/src/Core/MathFunctions.h.
150  namespace internal
151  {
152  template<class Backend, boost::multiprecision::expression_template_option ExpressionTemplates>
153  struct random_default_impl<
154  boost::multiprecision::number<Backend, ExpressionTemplates>,
155  false,
156  false>
157  {
158  typedef boost::multiprecision::number<Backend, ExpressionTemplates> Scalar;
159 
160  static inline Scalar run(const Scalar & x, const Scalar & y)
161  {
162  return x + (y - x) * Scalar(std::rand()) / Scalar(RAND_MAX);
163  }
164  static inline Scalar run()
165  {
166  return run(Scalar(NumTraits<Scalar>::IsSigned ? -1 : 0), Scalar(1));
167  }
168  };
169  } // namespace internal
170  #endif
171 
172  #if EIGEN_VERSION_AT_LEAST(3, 2, 93)
173  #define BOOST_MP_EIGEN_SCALAR_TRAITS_DECL(A) \
174  template< \
175  class Backend, boost::multiprecision::expression_template_option ExpressionTemplates, \
176  typename BinaryOp> \
177  struct ScalarBinaryOpTraits< \
178  boost::multiprecision::number<Backend, ExpressionTemplates>, A, BinaryOp> \
179  { \
180  /*static_assert(boost::multiprecision::is_compatible_arithmetic_type<A, \
181  * boost::multiprecision::number<Backend, ExpressionTemplates> >::value, "Interoperability \
182  * with this arithmetic type is not supported.");*/ \
183  typedef boost::multiprecision::number<Backend, ExpressionTemplates> ReturnType; \
184  }; \
185  template< \
186  class Backend, boost::multiprecision::expression_template_option ExpressionTemplates, \
187  typename BinaryOp> \
188  struct ScalarBinaryOpTraits< \
189  A, boost::multiprecision::number<Backend, ExpressionTemplates>, BinaryOp> \
190  { \
191  /*static_assert(boost::multiprecision::is_compatible_arithmetic_type<A, \
192  * boost::multiprecision::number<Backend, ExpressionTemplates> >::value, "Interoperability \
193  * with this arithmetic type is not supported.");*/ \
194  typedef boost::multiprecision::number<Backend, ExpressionTemplates> ReturnType; \
195  };
196 
197  BOOST_MP_EIGEN_SCALAR_TRAITS_DECL(float)
198  BOOST_MP_EIGEN_SCALAR_TRAITS_DECL(double)
199  BOOST_MP_EIGEN_SCALAR_TRAITS_DECL(long double)
200  BOOST_MP_EIGEN_SCALAR_TRAITS_DECL(char)
201  BOOST_MP_EIGEN_SCALAR_TRAITS_DECL(unsigned char)
202  BOOST_MP_EIGEN_SCALAR_TRAITS_DECL(signed char)
203  BOOST_MP_EIGEN_SCALAR_TRAITS_DECL(short)
204  BOOST_MP_EIGEN_SCALAR_TRAITS_DECL(unsigned short)
205  BOOST_MP_EIGEN_SCALAR_TRAITS_DECL(int)
206  BOOST_MP_EIGEN_SCALAR_TRAITS_DECL(unsigned int)
207  BOOST_MP_EIGEN_SCALAR_TRAITS_DECL(long)
208  BOOST_MP_EIGEN_SCALAR_TRAITS_DECL(unsigned long)
209 
210  template<
211  class Backend,
212  boost::multiprecision::expression_template_option ExpressionTemplates,
213  class tag,
214  class Arg1,
215  class Arg2,
216  class Arg3,
217  class Arg4,
218  typename BinaryOp>
219  struct ScalarBinaryOpTraits<
220  boost::multiprecision::number<Backend, ExpressionTemplates>,
221  boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>,
222  BinaryOp>
223  {
224  static_assert(
225  boost::is_convertible<
226  typename boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>::
227  result_type,
228  boost::multiprecision::number<Backend, ExpressionTemplates>>::value,
229  "Interoperability with this arithmetic type is not supported.");
230  typedef boost::multiprecision::number<Backend, ExpressionTemplates> ReturnType;
231  };
232 
233  template<
234  class tag,
235  class Arg1,
236  class Arg2,
237  class Arg3,
238  class Arg4,
239  class Backend,
240  boost::multiprecision::expression_template_option ExpressionTemplates,
241  typename BinaryOp>
242  struct ScalarBinaryOpTraits<
243  boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>,
244  boost::multiprecision::number<Backend, ExpressionTemplates>,
245  BinaryOp>
246  {
247  static_assert(
248  boost::is_convertible<
249  typename boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>::
250  result_type,
251  boost::multiprecision::number<Backend, ExpressionTemplates>>::value,
252  "Interoperability with this arithmetic type is not supported.");
253  typedef boost::multiprecision::number<Backend, ExpressionTemplates> ReturnType;
254  };
255  #endif
256 
257  namespace internal
258  {
259 
260  template<
261  class Backend,
262  boost::multiprecision::expression_template_option ExpressionTemplates,
263  class tag,
264  class Arg1,
265  class Arg2,
266  class Arg3,
267  class Arg4>
268  struct scalar_product_traits<
269  boost::multiprecision::number<Backend, ExpressionTemplates>,
270  boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>>
271  {
272  static_assert(
273  boost::is_convertible<
274  typename boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>::
275  result_type,
276  boost::multiprecision::number<Backend, ExpressionTemplates>>::value,
277  "Interoperability with this arithmetic type is not supported.");
278  typedef boost::multiprecision::number<Backend, ExpressionTemplates> ReturnType;
279  };
280 
281  template<
282  class tag,
283  class Arg1,
284  class Arg2,
285  class Arg3,
286  class Arg4,
287  class Backend,
288  boost::multiprecision::expression_template_option ExpressionTemplates>
289  struct scalar_product_traits<
290  boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>,
291  boost::multiprecision::number<Backend, ExpressionTemplates>>
292  {
293  static_assert(
294  boost::is_convertible<
295  typename boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>::
296  result_type,
297  boost::multiprecision::number<Backend, ExpressionTemplates>>::value,
298  "Interoperability with this arithmetic type is not supported.");
299  typedef boost::multiprecision::number<Backend, ExpressionTemplates> ReturnType;
300  };
301 
302  template<typename Scalar>
303  struct conj_retval;
304 
305  template<typename Scalar, bool IsComplex>
306  #if EIGEN_VERSION_AT_LEAST(3, 3, 9)
307  struct conj_default_impl;
308  #else
309  struct conj_impl;
310  #endif
311 
312  template<class tag, class Arg1, class Arg2, class Arg3, class Arg4>
313  struct conj_retval<boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>>
314  {
315  typedef
316  typename boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>::result_type
318  };
319 
320  template<class tag, class Arg1, class Arg2, class Arg3, class Arg4>
321  #if EIGEN_VERSION_AT_LEAST(3, 3, 9)
322  struct conj_default_impl<
323  boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>,
324  true>
325  #else
326  struct conj_impl<boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>, true>
327  #endif
328  {
329  #if EIGEN_VERSION_AT_LEAST(3, 2, 90)
331  #endif
332  static inline
333  typename boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>::result_type
335  const typename boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4> & x)
336  {
337  return conj(x);
338  }
339  };
340 
341  } // namespace internal
342 
343 } // namespace Eigen
344 
345 #endif // ifndef BOOST_MP_EIGEN_HPP
346 
347 #endif // ifndef __pinocchio_math_mutliprecision_hpp__
common_symbols.type
type
Definition: common_symbols.py:35
Eigen::NumTraits< boost::multiprecision::number< Backend, ExpressionTemplates > >::highest
static Real highest()
Definition: multiprecision.hpp:101
Eigen
Eigen::NumTraits< boost::multiprecision::number< Backend, ExpressionTemplates > >::epsilon
static Real epsilon()
Definition: multiprecision.hpp:93
Eigen::internal::conj_retval
Definition: multiprecision.hpp:303
omniidl_be_python_with_docstring.run
def run(tree, args)
Definition: cmake/hpp/idl/omniidl_be_python_with_docstring.py:140
y
y
Eigen::NumTraits< boost::multiprecision::number< Backend, ExpressionTemplates > >::self_type
boost::multiprecision::number< Backend, ExpressionTemplates > self_type
Definition: multiprecision.hpp:65
pinocchio::python::Scalar
context::Scalar Scalar
Definition: admm-solver.cpp:29
boost
Eigen::NumTraits< boost::multiprecision::number< Backend, ExpressionTemplates > >::NonInteger
self_type NonInteger
Definition: multiprecision.hpp:72
Eigen::NumTraits< boost::multiprecision::number< Backend, ExpressionTemplates > >::digits10
static int digits10()
Definition: multiprecision.hpp:118
Eigen::NumTraits< boost::multiprecision::number< Backend, ExpressionTemplates > >::Real
self_type Real
Definition: multiprecision.hpp:70
pinocchio::cholesky::min
JointCollectionTpl const DataTpl< Scalar, Options, JointCollectionTpl > const Eigen::MatrixBase< Mat > & min
Definition: cholesky.hpp:89
Eigen::internal::conj_impl< boost::multiprecision::detail::expression< tag, Arg1, Arg2, Arg3, Arg4 >, true >::run
static boost::multiprecision::detail::expression< tag, Arg1, Arg2, Arg3, Arg4 >::result_type run(const typename boost::multiprecision::detail::expression< tag, Arg1, Arg2, Arg3, Arg4 > &x)
Definition: multiprecision.hpp:334
pinocchio::is_floating_point
Definition: math/fwd.hpp:17
fwd.hpp
value
float value
x
x
Eigen::internal::cast_impl< boost::multiprecision::number< Backend, ExpressionTemplates >, Scalar >::run
static Scalar run(const boost::multiprecision::number< Backend, ExpressionTemplates > &x)
Definition: multiprecision.hpp:46
Eigen::NumTraits< boost::multiprecision::number< Backend, ExpressionTemplates > >::digits10_imp
static int digits10_imp(const boost::mpl::bool_< B > &)
Definition: multiprecision.hpp:114
CppAD::conj
const AD< Base > & conj(const AD< Base > &x)
Definition: autodiff/cppad.hpp:150
Eigen::NumTraits< boost::multiprecision::number< Backend, ExpressionTemplates > >::Nested
self_type Nested
Definition: multiprecision.hpp:74
Eigen::internal::conj_impl
Definition: multiprecision.hpp:309
Eigen::internal::scalar_product_traits< boost::multiprecision::number< Backend, ExpressionTemplates >, boost::multiprecision::detail::expression< tag, Arg1, Arg2, Arg3, Arg4 > >::ReturnType
boost::multiprecision::number< Backend, ExpressionTemplates > ReturnType
Definition: multiprecision.hpp:277
Eigen::NumTraits< boost::multiprecision::number< Backend, ExpressionTemplates > >::Literal
double Literal
Definition: multiprecision.hpp:73
Eigen::internal::scalar_product_traits< boost::multiprecision::detail::expression< tag, Arg1, Arg2, Arg3, Arg4 >, boost::multiprecision::number< Backend, ExpressionTemplates > >::ReturnType
boost::multiprecision::number< Backend, ExpressionTemplates > ReturnType
Definition: multiprecision.hpp:298
Eigen::NumTraits< boost::multiprecision::number< Backend, ExpressionTemplates > >::digits10_imp
static int digits10_imp(const boost::mpl::true_ &)
Definition: multiprecision.hpp:109
Eigen::NumTraits< boost::multiprecision::number< Backend, ExpressionTemplates > >::dummy_precision
static Real dummy_precision()
Definition: multiprecision.hpp:97
Eigen::NumTraits< boost::multiprecision::number< Backend, ExpressionTemplates > >::lowest
static Real lowest()
Definition: multiprecision.hpp:105
Eigen::NumTraits< boost::multiprecision::number< Backend, ExpressionTemplates > >::digits
constexpr static int digits()
Definition: multiprecision.hpp:127
pinocchio.utils.rand
def rand(n)
Definition: bindings/python/pinocchio/utils.py:41
Eigen::internal::conj_retval< boost::multiprecision::detail::expression< tag, Arg1, Arg2, Arg3, Arg4 > >::type
boost::multiprecision::detail::expression< tag, Arg1, Arg2, Arg3, Arg4 >::result_type type
Definition: multiprecision.hpp:317
CppAD::max
AD< Scalar > max(const AD< Scalar > &x, const AD< Scalar > &y)
Definition: autodiff/cppad.hpp:181
EIGEN_DEVICE_FUNC
#define EIGEN_DEVICE_FUNC
Definition: tensor.hpp:11
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27


pinocchio
Author(s):
autogenerated on Thu Dec 19 2024 03:41:32