boostmultiprec.cpp
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2016 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #include <sstream>
11 
12 #ifdef EIGEN_TEST_MAX_SIZE
13 #undef EIGEN_TEST_MAX_SIZE
14 #endif
15 
16 #define EIGEN_TEST_MAX_SIZE 50
17 
18 #ifdef EIGEN_TEST_PART_1
19 #include "cholesky.cpp"
20 #endif
21 
22 #ifdef EIGEN_TEST_PART_2
23 #include "lu.cpp"
24 #endif
25 
26 #ifdef EIGEN_TEST_PART_3
27 #include "qr.cpp"
28 #endif
29 
30 #ifdef EIGEN_TEST_PART_4
31 #include "qr_colpivoting.cpp"
32 #endif
33 
34 #ifdef EIGEN_TEST_PART_5
35 #include "qr_fullpivoting.cpp"
36 #endif
37 
38 #ifdef EIGEN_TEST_PART_6
40 #endif
41 
42 #ifdef EIGEN_TEST_PART_7
43 #include "eigensolver_generic.cpp"
44 #endif
45 
46 #ifdef EIGEN_TEST_PART_8
48 #endif
49 
50 #ifdef EIGEN_TEST_PART_9
51 #include "jacobisvd.cpp"
52 #endif
53 
54 #ifdef EIGEN_TEST_PART_10
55 #include "bdcsvd.cpp"
56 #endif
57 
58 #ifdef EIGEN_TEST_PART_11
59 #include "simplicial_cholesky.cpp"
60 #endif
61 
62 #include <Eigen/Dense>
63 
64 #undef min
65 #undef max
66 #undef isnan
67 #undef isinf
68 #undef isfinite
69 #undef I
70 
71 #include <boost/serialization/nvp.hpp>
72 #include <boost/multiprecision/cpp_dec_float.hpp>
73 #include <boost/multiprecision/number.hpp>
74 #include <boost/math/special_functions.hpp>
75 #include <boost/math/complex.hpp>
76 
77 namespace mp = boost::multiprecision;
78 typedef mp::number<mp::cpp_dec_float<100>, mp::et_on> Real;
79 
80 namespace Eigen {
81  template<> struct NumTraits<Real> : GenericNumTraits<Real> {
82  static inline Real dummy_precision() { return 1e-50; }
83  };
84 
85  template<typename T1,typename T2,typename T3,typename T4,typename T5>
86  struct NumTraits<boost::multiprecision::detail::expression<T1,T2,T3,T4,T5> > : NumTraits<Real> {};
87 
88  template<>
89  Real test_precision<Real>() { return 1e-50; }
90 
91  // needed in C++93 mode where number does not support explicit cast.
92  namespace internal {
93  template<typename NewType>
94  struct cast_impl<Real,NewType> {
95  static inline NewType run(const Real& x) {
96  return x.template convert_to<NewType>();
97  }
98  };
99 
100  template<>
101  struct cast_impl<Real,std::complex<Real> > {
102  static inline std::complex<Real> run(const Real& x) {
103  return std::complex<Real>(x);
104  }
105  };
106  }
107 }
108 
109 namespace boost {
110 namespace multiprecision {
111  // to make ADL works as expected:
112  using boost::math::isfinite;
113  using boost::math::isnan;
114  using boost::math::isinf;
115  using boost::math::copysign;
116  using boost::math::hypot;
117 
118  // The following is needed for std::complex<Real>:
119  Real fabs(const Real& a) { return abs EIGEN_NOT_A_MACRO (a); }
120  Real fmax(const Real& a, const Real& b) { using std::max; return max(a,b); }
121 
122  // some specialization for the unit tests:
123  inline bool test_isMuchSmallerThan(const Real& a, const Real& b) {
125  }
126 
127  inline bool test_isApprox(const Real& a, const Real& b) {
129  }
130 
131  inline bool test_isApproxOrLessThan(const Real& a, const Real& b) {
133  }
134 
136  return test_precision<Real>();
137  }
138 
139  Real test_relative_error(const Real &a, const Real &b) {
140  using Eigen::numext::abs2;
141  return sqrt(abs2<Real>(a-b)/Eigen::numext::mini<Real>(abs2(a),abs2(b)));
142  }
143 }
144 }
145 
146 namespace Eigen {
147 
148 }
149 
150 EIGEN_DECLARE_TEST(boostmultiprec)
151 {
152  typedef Matrix<Real,Dynamic,Dynamic> Mat;
153  typedef Matrix<std::complex<Real>,Dynamic,Dynamic> MatC;
154 
155  std::cout << "NumTraits<Real>::epsilon() = " << NumTraits<Real>::epsilon() << std::endl;
156  std::cout << "NumTraits<Real>::dummy_precision() = " << NumTraits<Real>::dummy_precision() << std::endl;
157  std::cout << "NumTraits<Real>::lowest() = " << NumTraits<Real>::lowest() << std::endl;
158  std::cout << "NumTraits<Real>::highest() = " << NumTraits<Real>::highest() << std::endl;
159  std::cout << "NumTraits<Real>::digits10() = " << NumTraits<Real>::digits10() << std::endl;
160 
161  // check stream output
162  {
163  Mat A(10,10);
164  A.setRandom();
165  std::stringstream ss;
166  ss << A;
167  }
168  {
169  MatC A(10,10);
170  A.setRandom();
171  std::stringstream ss;
172  ss << A;
173  }
174 
175  for(int i = 0; i < g_repeat; i++) {
176  int s = internal::random<int>(1,EIGEN_TEST_MAX_SIZE);
177 
179 
180  CALL_SUBTEST_2( lu_non_invertible<Mat>() );
181  CALL_SUBTEST_2( lu_invertible<Mat>() );
182  CALL_SUBTEST_2( lu_non_invertible<MatC>() );
183  CALL_SUBTEST_2( lu_invertible<MatC>() );
184 
185  CALL_SUBTEST_3( qr(Mat(internal::random<int>(1,EIGEN_TEST_MAX_SIZE),internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
186  CALL_SUBTEST_3( qr_invertible<Mat>() );
187 
188  CALL_SUBTEST_4( qr<Mat>() );
189  CALL_SUBTEST_4( cod<Mat>() );
190  CALL_SUBTEST_4( qr_invertible<Mat>() );
191 
192  CALL_SUBTEST_5( qr<Mat>() );
193  CALL_SUBTEST_5( qr_invertible<Mat>() );
194 
196 
198 
200 
202  }
203 
204  CALL_SUBTEST_9(( jacobisvd(Mat(internal::random<int>(EIGEN_TEST_MAX_SIZE/4, EIGEN_TEST_MAX_SIZE), internal::random<int>(EIGEN_TEST_MAX_SIZE/4, EIGEN_TEST_MAX_SIZE/2))) ));
205  CALL_SUBTEST_10(( bdcsvd(Mat(internal::random<int>(EIGEN_TEST_MAX_SIZE/4, EIGEN_TEST_MAX_SIZE), internal::random<int>(EIGEN_TEST_MAX_SIZE/4, EIGEN_TEST_MAX_SIZE/2))) ));
206 
207  CALL_SUBTEST_11(( test_simplicial_cholesky_T<Real,int,ColMajor>() ));
208 }
Eigen::internal::cast_impl
Definition: Eigen/src/Core/MathFunctions.h:431
jacobisvd.cpp
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
boost::multiprecision::test_relative_error
Real test_relative_error(const Real &a, const Real &b)
Definition: boostmultiprec.cpp:139
s
RealScalar s
Definition: level1_cplx_impl.h:126
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Eigen::internal::isApproxOrLessThan
EIGEN_DEVICE_FUNC bool isApproxOrLessThan(const Scalar &x, const Scalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())
Definition: Eigen/src/Core/MathFunctions.h:1954
eigensolver_generalized_real.cpp
eigensolver_generic.cpp
b
Scalar * b
Definition: benchVecAdd.cpp:17
x
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition: gnuplot_common_settings.hh:12
selfadjointeigensolver
void selfadjointeigensolver(const MatrixType &m)
Definition: eigensolver_selfadjoint.cpp:69
boost::multiprecision::fmax
Real fmax(const Real &a, const Real &b)
Definition: boostmultiprec.cpp:120
Eigen::internal::isApprox
EIGEN_DEVICE_FUNC bool isApprox(const Scalar &x, const Scalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())
Definition: Eigen/src/Core/MathFunctions.h:1947
abs2
EIGEN_DEVICE_FUNC const EIGEN_STRONG_INLINE Abs2ReturnType abs2() const
Definition: ArrayCwiseUnaryOps.h:80
isnan
#define isnan(X)
Definition: main.h:93
boost
Definition: boostmultiprec.cpp:109
Eigen::internal::isMuchSmallerThan
EIGEN_DEVICE_FUNC bool isMuchSmallerThan(const Scalar &x, const OtherScalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())
Definition: Eigen/src/Core/MathFunctions.h:1940
qr_fullpivoting.cpp
CALL_SUBTEST_11
#define CALL_SUBTEST_11(FUNC)
Definition: split_test_helper.h:64
CALL_SUBTEST_9
#define CALL_SUBTEST_9(FUNC)
Definition: split_test_helper.h:52
boost::multiprecision::test_isApproxOrLessThan
bool test_isApproxOrLessThan(const Real &a, const Real &b)
Definition: boostmultiprec.cpp:131
A
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:48
ss
static std::stringstream ss
Definition: testBTree.cpp:31
boost::multiprecision::fabs
Real fabs(const Real &a)
Definition: boostmultiprec.cpp:119
CALL_SUBTEST_4
#define CALL_SUBTEST_4(FUNC)
Definition: split_test_helper.h:22
Eigen::GenericNumTraits
Definition: NumTraits.h:152
epsilon
static double epsilon
Definition: testRot3.cpp:37
CALL_SUBTEST_3
#define CALL_SUBTEST_3(FUNC)
Definition: split_test_helper.h:16
CALL_SUBTEST_1
#define CALL_SUBTEST_1(FUNC)
Definition: split_test_helper.h:4
A
Definition: test_numpy_dtypes.cpp:298
boost::multiprecision
Definition: boostmultiprec.cpp:110
Eigen::Dynamic
const int Dynamic
Definition: Constants.h:22
CALL_SUBTEST_10
#define CALL_SUBTEST_10(FUNC)
Definition: split_test_helper.h:58
boost::multiprecision::test_isApprox
bool test_isApprox(const Real &a, const Real &b)
Definition: boostmultiprec.cpp:127
generalized_eigensolver_real
void generalized_eigensolver_real(const MatrixType &m)
Definition: eigensolver_generalized_real.cpp:16
isfinite
#define isfinite(X)
Definition: main.h:95
CALL_SUBTEST_5
#define CALL_SUBTEST_5(FUNC)
Definition: split_test_helper.h:28
Eigen::g_repeat
static int g_repeat
Definition: main.h:169
Mat
Matrix< Scalar, Dynamic, Dynamic > Mat
Definition: gemm_common.h:15
boost::multiprecision::test_isMuchSmallerThan
bool test_isMuchSmallerThan(const Real &a, const Real &b)
Definition: boostmultiprec.cpp:123
Eigen::NumTraits< Real >::dummy_precision
static Real dummy_precision()
Definition: boostmultiprec.cpp:82
simplicial_cholesky.cpp
bdcsvd.cpp
CALL_SUBTEST_6
#define CALL_SUBTEST_6(FUNC)
Definition: split_test_helper.h:34
CALL_SUBTEST_2
#define CALL_SUBTEST_2(FUNC)
Definition: split_test_helper.h:10
jacobisvd
void jacobisvd(const MatrixType &a=MatrixType(), bool pickrandom=true)
Definition: jacobisvd.cpp:23
Eigen::internal::cast_impl< Real, NewType >::run
static NewType run(const Real &x)
Definition: boostmultiprec.cpp:95
Eigen::test_precision< Real >
Real test_precision< Real >()
Definition: boostmultiprec.cpp:89
qr_colpivoting.cpp
cholesky
void cholesky(const MatrixType &m)
Definition: 3rdparty/Eigen/test/cholesky.cpp:56
boost::multiprecision::get_test_precision
Real get_test_precision(const Real &)
Definition: boostmultiprec.cpp:135
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1
Eigen::numext::abs2
EIGEN_DEVICE_FUNC bool abs2(bool x)
Definition: Eigen/src/Core/MathFunctions.h:1294
qr
HouseholderQR< MatrixXf > qr(A)
EIGEN_NOT_A_MACRO
#define EIGEN_NOT_A_MACRO
Definition: Macros.h:896
std
Definition: BFloat16.h:88
EIGEN_TEST_MAX_SIZE
#define EIGEN_TEST_MAX_SIZE
Definition: boostmultiprec.cpp:16
eigensolver
void eigensolver(const MatrixType &m)
Definition: eigensolver_complex.cpp:72
Eigen::internal::cast_impl< Real, std::complex< Real > >::run
static std::complex< Real > run(const Real &x)
Definition: boostmultiprec.cpp:102
Real
mp::number< mp::cpp_dec_float< 100 >, mp::et_on > Real
Definition: boostmultiprec.cpp:78
qr.cpp
Eigen::Matrix< Scalar, Dynamic, Dynamic >
abs
#define abs(x)
Definition: datatypes.h:17
eigensolver_selfadjoint.cpp
internal
Definition: BandTriangularSolver.h:13
bdcsvd
void bdcsvd(const MatrixType &a=MatrixType(), bool pickrandom=true)
Definition: bdcsvd.cpp:29
CALL_SUBTEST_7
#define CALL_SUBTEST_7(FUNC)
Definition: split_test_helper.h:40
CALL_SUBTEST_8
#define CALL_SUBTEST_8(FUNC)
Definition: split_test_helper.h:46
max
#define max(a, b)
Definition: datatypes.h:20
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(boostmultiprec)
Definition: boostmultiprec.cpp:150
Eigen::NumTraits
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:232
ceres::sqrt
Jet< T, N > sqrt(const Jet< T, N > &f)
Definition: jet.h:418
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
TEST_SET_BUT_UNUSED_VARIABLE
#define TEST_SET_BUT_UNUSED_VARIABLE(X)
Definition: main.h:121
Eigen::GenericNumTraits< Real >::Real
Real Real
Definition: NumTraits.h:164
complex
Definition: datatypes.h:12
isinf
#define isinf(X)
Definition: main.h:94


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:01:56