Go to the documentation of this file.00001 #include "main.h"
00002 #include <Eigen/MPRealSupport>
00003 #include <Eigen/LU>
00004 #include <Eigen/Eigenvalues>
00005 #include <sstream>
00006
00007 using namespace mpfr;
00008 using namespace Eigen;
00009
00010 void test_mpreal_support()
00011 {
00012
00013 mpreal::set_default_prec(256);
00014 typedef Matrix<mpreal,Eigen::Dynamic,Eigen::Dynamic> MatrixXmp;
00015
00016 std::cerr << "epsilon = " << NumTraits<mpreal>::epsilon() << "\n";
00017 std::cerr << "dummy_precision = " << NumTraits<mpreal>::dummy_precision() << "\n";
00018 std::cerr << "highest = " << NumTraits<mpreal>::highest() << "\n";
00019 std::cerr << "lowest = " << NumTraits<mpreal>::lowest() << "\n";
00020
00021 for(int i = 0; i < g_repeat; i++) {
00022 int s = Eigen::internal::random<int>(1,100);
00023 MatrixXmp A = MatrixXmp::Random(s,s);
00024 MatrixXmp B = MatrixXmp::Random(s,s);
00025 MatrixXmp S = A.adjoint() * A;
00026 MatrixXmp X;
00027
00028
00029 VERIFY_IS_APPROX(A.real(), A);
00030 VERIFY(Eigen::internal::isApprox(A.array().abs2().sum(), A.squaredNorm()));
00031 VERIFY_IS_APPROX(A.array().exp(), exp(A.array()));
00032 VERIFY_IS_APPROX(A.array().abs2().sqrt(), A.array().abs());
00033 VERIFY_IS_APPROX(A.array().sin(), sin(A.array()));
00034 VERIFY_IS_APPROX(A.array().cos(), cos(A.array()));
00035
00036
00037
00038 X = S.selfadjointView<Lower>().llt().solve(B);
00039 VERIFY_IS_APPROX((S.selfadjointView<Lower>()*X).eval(),B);
00040
00041
00042 X = A.lu().solve(B);
00043 VERIFY_IS_APPROX((A*X).eval(),B);
00044
00045
00046 SelfAdjointEigenSolver<MatrixXmp> eig(S);
00047 VERIFY_IS_EQUAL(eig.info(), Success);
00048 VERIFY( (S.selfadjointView<Lower>() * eig.eigenvectors()).isApprox(eig.eigenvectors() * eig.eigenvalues().asDiagonal(), NumTraits<mpreal>::dummy_precision()*1e3) );
00049 }
00050
00051 {
00052 MatrixXmp A(8,3); A.setRandom();
00053
00054 std::stringstream stream;
00055 stream << A;
00056 }
00057 }