From 4184a3e5440d0592b76738aa87e9e78c53f5d5af Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 25 Jul 2016 12:36:22 +0200 Subject: Extend boost.multiprec unit test with ET on, complexes, and general/generalized eigenvalue solvers. --- test/boostmultiprec.cpp | 56 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 9 deletions(-) (limited to 'test/boostmultiprec.cpp') diff --git a/test/boostmultiprec.cpp b/test/boostmultiprec.cpp index b4d0decff..e06e9bdaf 100644 --- a/test/boostmultiprec.cpp +++ b/test/boostmultiprec.cpp @@ -40,10 +40,18 @@ #endif #ifdef EIGEN_TEST_PART_7 -#include "jacobisvd.cpp" +#include "eigensolver_generic.cpp" #endif #ifdef EIGEN_TEST_PART_8 +#include "eigensolver_generalized_real.cpp" +#endif + +#ifdef EIGEN_TEST_PART_9 +#include "jacobisvd.cpp" +#endif + +#ifdef EIGEN_TEST_PART_10 #include "bdcsvd.cpp" #endif @@ -57,9 +65,11 @@ #include #include +#include +#include namespace mp = boost::multiprecision; -typedef mp::number, mp::et_off> Real; // swith to et_on for testing with expression templates +typedef mp::number, mp::et_on> Real; namespace Eigen { template<> struct NumTraits : GenericNumTraits { @@ -75,13 +85,18 @@ namespace Eigen { // needed in C++93 mode where number does not support explicit cast. namespace internal { template - struct cast_impl - { - static inline NewType run(const Real& x) - { + struct cast_impl { + static inline NewType run(const Real& x) { return x.template convert_to(); } }; + + template<> + struct cast_impl > { + static inline std::complex run(const Real& x) { + return std::complex(x); + } + }; } } @@ -89,6 +104,14 @@ namespace boost { namespace multiprecision { // to make ADL works as expected: using boost::math::isfinite; + using boost::math::isnan; + using boost::math::isinf; + using boost::math::copysign; + using boost::math::hypot; + + // The following is needed for std::complex: + Real fabs(const Real& a) { return abs EIGEN_NOT_A_MACRO (a); } + Real fmax(const Real& a, const Real& b) { using std::max; return max(a,b); } // some specialization for the unit tests: inline bool test_isMuchSmallerThan(const Real& a, const Real& b) { @@ -108,7 +131,8 @@ namespace multiprecision { } Real test_relative_error(const Real &a, const Real &b) { - return Eigen::numext::sqrt(Real(Eigen::numext::abs2(a-b))/Real((Eigen::numext::mini)(Eigen::numext::abs2(a),Eigen::numext::abs2(b)))); + using Eigen::numext::abs2; + return sqrt(abs2(a-b)/Eigen::numext::mini(abs2(a),abs2(b))); } } } @@ -120,11 +144,13 @@ namespace Eigen { void test_boostmultiprec() { typedef Matrix Mat; + typedef Matrix,Dynamic,Dynamic> MatC; std::cout << "NumTraits::epsilon() = " << NumTraits::epsilon() << std::endl; std::cout << "NumTraits::dummy_precision() = " << NumTraits::dummy_precision() << std::endl; std::cout << "NumTraits::lowest() = " << NumTraits::lowest() << std::endl; std::cout << "NumTraits::highest() = " << NumTraits::highest() << std::endl; + std::cout << "NumTraits::digits10() = " << NumTraits::digits10() << std::endl; // chekc stream output { @@ -133,6 +159,12 @@ void test_boostmultiprec() std::stringstream ss; ss << A; } + { + MatC A(10,10); + A.setRandom(); + std::stringstream ss; + ss << A; + } for(int i = 0; i < g_repeat; i++) { int s = internal::random(1,EIGEN_TEST_MAX_SIZE); @@ -141,6 +173,8 @@ void test_boostmultiprec() CALL_SUBTEST_2( lu_non_invertible() ); CALL_SUBTEST_2( lu_invertible() ); + CALL_SUBTEST_2( lu_non_invertible() ); + CALL_SUBTEST_2( lu_invertible() ); CALL_SUBTEST_3( qr(Mat(internal::random(1,EIGEN_TEST_MAX_SIZE),internal::random(1,EIGEN_TEST_MAX_SIZE))) ); CALL_SUBTEST_3( qr_invertible() ); @@ -154,10 +188,14 @@ void test_boostmultiprec() CALL_SUBTEST_6( selfadjointeigensolver(Mat(s,s)) ); + CALL_SUBTEST_7( eigensolver(Mat(s,s)) ); + + CALL_SUBTEST_8( generalized_eigensolver_real(Mat(s,s)) ); + TEST_SET_BUT_UNUSED_VARIABLE(s) } - CALL_SUBTEST_7(( jacobisvd(Mat(internal::random(EIGEN_TEST_MAX_SIZE/4, EIGEN_TEST_MAX_SIZE), internal::random(EIGEN_TEST_MAX_SIZE/4, EIGEN_TEST_MAX_SIZE/2))) )); - CALL_SUBTEST_8(( bdcsvd(Mat(internal::random(EIGEN_TEST_MAX_SIZE/4, EIGEN_TEST_MAX_SIZE), internal::random(EIGEN_TEST_MAX_SIZE/4, EIGEN_TEST_MAX_SIZE/2))) )); + CALL_SUBTEST_9(( jacobisvd(Mat(internal::random(EIGEN_TEST_MAX_SIZE/4, EIGEN_TEST_MAX_SIZE), internal::random(EIGEN_TEST_MAX_SIZE/4, EIGEN_TEST_MAX_SIZE/2))) )); + CALL_SUBTEST_10(( bdcsvd(Mat(internal::random(EIGEN_TEST_MAX_SIZE/4, EIGEN_TEST_MAX_SIZE), internal::random(EIGEN_TEST_MAX_SIZE/4, EIGEN_TEST_MAX_SIZE/2))) )); } -- cgit v1.2.3