From 87e89fea4e05f2f516bf6efb3986a8ee9aee6de6 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Thu, 15 Jul 2010 16:29:04 +0200 Subject: add a support module for MPFR C++ with basic unit testing --- unsupported/test/mpreal_support.cpp | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 unsupported/test/mpreal_support.cpp (limited to 'unsupported/test/mpreal_support.cpp') diff --git a/unsupported/test/mpreal_support.cpp b/unsupported/test/mpreal_support.cpp new file mode 100644 index 000000000..32570f092 --- /dev/null +++ b/unsupported/test/mpreal_support.cpp @@ -0,0 +1,42 @@ +#include "main.h" +#include + +using namespace mpfr; +using namespace std; +using namespace Eigen; + +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 = ei_random(1,100); + MatrixXmp A = MatrixXmp::Random(s,s); + MatrixXmp B = MatrixXmp::Random(s,s); + MatrixXmp S = A.adjoint() * A; + MatrixXmp X; + + // 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_IS_APPROX((S.selfadjointView() * eig.eigenvectors()), + eig.eigenvectors() * eig.eigenvalues().asDiagonal()); + } +} + +#include "mpreal.cpp" -- cgit v1.2.3