mpreal_support.cpp
Go to the documentation of this file.
1 #include "main.h"
2 #include <Eigen/MPRealSupport>
3 #include <Eigen/LU>
4 #include <Eigen/Eigenvalues>
5 #include <sstream>
6 
7 using namespace mpfr;
8 using namespace Eigen;
9 
11 {
12  // set precision to 256 bits (double has only 53 bits)
15  typedef Matrix<std::complex<mpreal>,Eigen::Dynamic,Eigen::Dynamic> MatrixXcmp;
16 
17  std::cerr << "epsilon = " << NumTraits<mpreal>::epsilon() << "\n";
18  std::cerr << "dummy_precision = " << NumTraits<mpreal>::dummy_precision() << "\n";
19  std::cerr << "highest = " << NumTraits<mpreal>::highest() << "\n";
20  std::cerr << "lowest = " << NumTraits<mpreal>::lowest() << "\n";
21  std::cerr << "digits10 = " << NumTraits<mpreal>::digits10() << "\n";
22 
23  for(int i = 0; i < g_repeat; i++) {
24  int s = Eigen::internal::random<int>(1,100);
25  MatrixXmp A = MatrixXmp::Random(s,s);
26  MatrixXmp B = MatrixXmp::Random(s,s);
27  MatrixXmp S = A.adjoint() * A;
28  MatrixXmp X;
29  MatrixXcmp Ac = MatrixXcmp::Random(s,s);
30  MatrixXcmp Bc = MatrixXcmp::Random(s,s);
31  MatrixXcmp Sc = Ac.adjoint() * Ac;
32  MatrixXcmp Xc;
33 
34  // Basic stuffs
35  VERIFY_IS_APPROX(A.real(), A);
36  VERIFY(Eigen::internal::isApprox(A.array().abs2().sum(), A.squaredNorm()));
37  VERIFY_IS_APPROX(A.array().exp(), exp(A.array()));
38  VERIFY_IS_APPROX(A.array().abs2().sqrt(), A.array().abs());
39  VERIFY_IS_APPROX(A.array().sin(), sin(A.array()));
40  VERIFY_IS_APPROX(A.array().cos(), cos(A.array()));
41 
42  // Cholesky
43  X = S.selfadjointView<Lower>().llt().solve(B);
44  VERIFY_IS_APPROX((S.selfadjointView<Lower>()*X).eval(),B);
45 
46  Xc = Sc.selfadjointView<Lower>().llt().solve(Bc);
47  VERIFY_IS_APPROX((Sc.selfadjointView<Lower>()*Xc).eval(),Bc);
48 
49  // partial LU
50  X = A.lu().solve(B);
51  VERIFY_IS_APPROX((A*X).eval(),B);
52 
53  // symmetric eigenvalues
55  VERIFY_IS_EQUAL(eig.info(), Success);
56  VERIFY( (S.selfadjointView<Lower>() * eig.eigenvectors()).isApprox(eig.eigenvectors() * eig.eigenvalues().asDiagonal(), NumTraits<mpreal>::dummy_precision()*1e3) );
57  }
58 
59  {
60  MatrixXmp A(8,3); A.setRandom();
61  // test output (interesting things happen in this code)
62  std::stringstream stream;
63  stream << A;
64  }
65 }
const mpreal exp(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())
Definition: mpreal.h:2227
XmlRpcServer s
Computes eigenvalues and eigenvectors of selfadjoint matrices.
Definition: LDLT.h:16
Definition: mpreal.h:140
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:150
const mpreal cos(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())
Definition: mpreal.h:2230
EIGEN_DEVICE_FUNC ComputationInfo info() const
Reports whether previous computation was successful.
static void set_default_prec(mp_prec_t prec)
Definition: mpreal.h:2666
const mpreal sin(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())
Definition: mpreal.h:2231
EIGEN_DEVICE_FUNC const RealVectorType & eigenvalues() const
Returns the eigenvalues of given matrix.
void test_mpreal_support()
EIGEN_DEVICE_FUNC const EigenvectorsType & eigenvectors() const
Returns the eigenvectors of given matrix.
const int Dynamic
Definition: Constants.h:21
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:178


hebiros
Author(s): Xavier Artache , Matthew Tesch
autogenerated on Thu Sep 3 2020 04:08:30