diff options
author | Gael Guennebaud <g.gael@free.fr> | 2016-07-25 12:36:22 +0200 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2016-07-25 12:36:22 +0200 |
commit | 4184a3e5440d0592b76738aa87e9e78c53f5d5af (patch) | |
tree | c04ab35aabe7bc862bc9f3805fa80a2e14a9900a /test/boostmultiprec.cpp | |
parent | 1b2049fbdad3d9ac292e6a71836a16329fcaf02a (diff) |
Extend boost.multiprec unit test with ET on, complexes, and general/generalized eigenvalue solvers.
Diffstat (limited to 'test/boostmultiprec.cpp')
-rw-r--r-- | test/boostmultiprec.cpp | 56 |
1 files changed, 47 insertions, 9 deletions
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 <boost/multiprecision/cpp_dec_float.hpp> #include <boost/multiprecision/number.hpp> +#include <boost/math/special_functions.hpp> +#include <boost/math/complex.hpp> namespace mp = boost::multiprecision; -typedef mp::number<mp::cpp_dec_float<100>, mp::et_off> Real; // swith to et_on for testing with expression templates +typedef mp::number<mp::cpp_dec_float<100>, mp::et_on> Real; namespace Eigen { template<> struct NumTraits<Real> : GenericNumTraits<Real> { @@ -75,13 +85,18 @@ namespace Eigen { // needed in C++93 mode where number does not support explicit cast. namespace internal { template<typename NewType> - struct cast_impl<Real,NewType> - { - static inline NewType run(const Real& x) - { + struct cast_impl<Real,NewType> { + static inline NewType run(const Real& x) { return x.template convert_to<NewType>(); } }; + + template<> + struct cast_impl<Real,std::complex<Real> > { + static inline std::complex<Real> run(const Real& x) { + return std::complex<Real>(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>: + 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<Real>(a-b)/Eigen::numext::mini<Real>(abs2(a),abs2(b))); } } } @@ -120,11 +144,13 @@ namespace Eigen { void test_boostmultiprec() { typedef Matrix<Real,Dynamic,Dynamic> Mat; + typedef Matrix<std::complex<Real>,Dynamic,Dynamic> MatC; std::cout << "NumTraits<Real>::epsilon() = " << NumTraits<Real>::epsilon() << std::endl; std::cout << "NumTraits<Real>::dummy_precision() = " << NumTraits<Real>::dummy_precision() << std::endl; std::cout << "NumTraits<Real>::lowest() = " << NumTraits<Real>::lowest() << std::endl; std::cout << "NumTraits<Real>::highest() = " << NumTraits<Real>::highest() << std::endl; + std::cout << "NumTraits<Real>::digits10() = " << NumTraits<Real>::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<int>(1,EIGEN_TEST_MAX_SIZE); @@ -141,6 +173,8 @@ void test_boostmultiprec() CALL_SUBTEST_2( lu_non_invertible<Mat>() ); CALL_SUBTEST_2( lu_invertible<Mat>() ); + CALL_SUBTEST_2( lu_non_invertible<MatC>() ); + CALL_SUBTEST_2( lu_invertible<MatC>() ); CALL_SUBTEST_3( qr(Mat(internal::random<int>(1,EIGEN_TEST_MAX_SIZE),internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) ); CALL_SUBTEST_3( qr_invertible<Mat>() ); @@ -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<int>(EIGEN_TEST_MAX_SIZE/4, EIGEN_TEST_MAX_SIZE), internal::random<int>(EIGEN_TEST_MAX_SIZE/4, EIGEN_TEST_MAX_SIZE/2))) )); - CALL_SUBTEST_8(( bdcsvd(Mat(internal::random<int>(EIGEN_TEST_MAX_SIZE/4, EIGEN_TEST_MAX_SIZE), internal::random<int>(EIGEN_TEST_MAX_SIZE/4, EIGEN_TEST_MAX_SIZE/2))) )); + CALL_SUBTEST_9(( jacobisvd(Mat(internal::random<int>(EIGEN_TEST_MAX_SIZE/4, EIGEN_TEST_MAX_SIZE), internal::random<int>(EIGEN_TEST_MAX_SIZE/4, EIGEN_TEST_MAX_SIZE/2))) )); + CALL_SUBTEST_10(( bdcsvd(Mat(internal::random<int>(EIGEN_TEST_MAX_SIZE/4, EIGEN_TEST_MAX_SIZE), internal::random<int>(EIGEN_TEST_MAX_SIZE/4, EIGEN_TEST_MAX_SIZE/2))) )); } |