#include "main.h" #include #include #include #include using namespace mpfr; using namespace StormEigen; void test_mpreal_support() { // set precision to 256 bits (double has only 53 bits) mpreal::set_default_prec(256); typedef Matrix MatrixXmp; std::cerr << "epsilon = " << NumTraits::epsilon() << "\n"; std::cerr << "dummy_precision = " << NumTraits::dummy_precision() << "\n"; std::cerr << "highest = " << NumTraits::highest() << "\n"; std::cerr << "lowest = " << NumTraits::lowest() << "\n"; for(int i = 0; i < g_repeat; i++) { int s = StormEigen::internal::random(1,100); MatrixXmp A = MatrixXmp::Random(s,s); MatrixXmp B = MatrixXmp::Random(s,s); MatrixXmp S = A.adjoint() * A; MatrixXmp X; // Basic stuffs VERIFY_IS_APPROX(A.real(), A); VERIFY(StormEigen::internal::isApprox(A.array().abs2().sum(), A.squaredNorm())); VERIFY_IS_APPROX(A.array().exp(), exp(A.array())); VERIFY_IS_APPROX(A.array().abs2().sqrt(), A.array().abs()); VERIFY_IS_APPROX(A.array().sin(), sin(A.array())); VERIFY_IS_APPROX(A.array().cos(), cos(A.array())); // Cholesky X = S.selfadjointView().llt().solve(B); VERIFY_IS_APPROX((S.selfadjointView()*X).eval(),B); // partial LU X = A.lu().solve(B); VERIFY_IS_APPROX((A*X).eval(),B); // symmetric eigenvalues SelfAdjointEigenSolver eig(S); VERIFY_IS_EQUAL(eig.info(), Success); VERIFY( (S.selfadjointView() * eig.eigenvectors()).isApprox(eig.eigenvectors() * eig.eigenvalues().asDiagonal(), NumTraits::dummy_precision()*1e3) ); } { MatrixXmp A(8,3); A.setRandom(); // test output (interesting things happen in this code) std::stringstream stream; stream << A; } }