sincos.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2018-2019 INRIA
3 //
4 
5 #include "pinocchio/fwd.hpp"
7 #include <cstdlib>
8 
9 #include "utils/macros.hpp"
10 
11 #include <boost/test/unit_test.hpp>
12 #include <boost/utility/binary.hpp>
13 
14 namespace
15 {
16  template<typename Scalar>
17  Scalar sinCosTolerance();
18 
19  template<>
20  inline float sinCosTolerance<float>()
21  {
22  // I don't know how tolerance has been calculated.
23  // 1e-7 doesn't work on ARM + Debug architecture.
24  return 1.5e-7f;
25  }
26 
27  template<>
28  inline double sinCosTolerance<double>()
29  {
30  return 1e-15;
31  }
32 
33  template<>
34  inline long double sinCosTolerance<long double>()
35  {
36  return 1e-19;
37  }
38 } // namespace
39 
40 template<typename Scalar>
41 void testSINCOS(int n)
42 {
43  for (int k = 0; k < n; ++k)
44  {
45  Scalar sin_value, cos_value;
46  Scalar alpha = (Scalar)std::rand() / (Scalar)RAND_MAX;
47  pinocchio::SINCOS(alpha, &sin_value, &cos_value);
48 
49  Scalar sin_value_ref = std::sin(alpha), cos_value_ref = std::cos(alpha);
50 
51  BOOST_CHECK_CLOSE_FRACTION(sin_value, sin_value_ref, sinCosTolerance<Scalar>());
52  BOOST_CHECK_CLOSE_FRACTION(cos_value, cos_value_ref, sinCosTolerance<Scalar>());
53  }
54 }
55 
56 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
57 
59 {
60 #ifndef NDEBUG
61  const int n = 1e3;
62 #else
63  const int n = 1e6;
64 #endif
65  testSINCOS<float>(n);
66  testSINCOS<double>(n);
67  testSINCOS<long double>(n);
68 }
69 
70 BOOST_AUTO_TEST_SUITE_END()
sincos.hpp
fwd.hpp
pinocchio::python::Scalar
context::Scalar Scalar
Definition: admm-solver.cpp:29
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(test_sincos)
Definition: sincos.cpp:58
pinocchio::SINCOS
void SINCOS(const S1 &a, S2 *sa, S3 *ca)
Computes sin/cos values of a given input scalar.
Definition: sincos.hpp:27
autodiff-rnea.f
f
Definition: autodiff-rnea.py:24
reachable-workspace-with-collisions.alpha
float alpha
Definition: reachable-workspace-with-collisions.py:162
testSINCOS
void testSINCOS(int n)
Definition: sincos.cpp:41
pinocchio.utils.rand
def rand(n)
Definition: bindings/python/pinocchio/utils.py:41
n
Vec3f n


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