// This file is part of Eigen, a lightweight C++ template library // for linear algebra. // // Copyright (C) 2016 Gael Guennebaud // // This Source Code Form is subject to the terms of the Mozilla // Public License v. 2.0. If a copy of the MPL was not distributed // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. #include #ifdef EIGEN_TEST_MAX_SIZE #undef EIGEN_TEST_MAX_SIZE #endif #define EIGEN_TEST_MAX_SIZE 50 #ifdef EIGEN_TEST_PART_1 #include "cholesky.cpp" #endif #ifdef EIGEN_TEST_PART_2 #include "lu.cpp" #endif #ifdef EIGEN_TEST_PART_3 #include "qr.cpp" #endif #ifdef EIGEN_TEST_PART_4 #include "qr_colpivoting.cpp" #endif #ifdef EIGEN_TEST_PART_5 #include "qr_fullpivoting.cpp" #endif #ifdef EIGEN_TEST_PART_6 #include "eigensolver_selfadjoint.cpp" #endif #ifdef EIGEN_TEST_PART_7 #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 #ifdef EIGEN_TEST_PART_11 #include "simplicial_cholesky.cpp" #endif #include #undef min #undef max #undef isnan #undef isinf #undef isfinite #undef I #include #include #include #include #include typedef boost::multiprecision::number, boost::multiprecision::et_on> Real; namespace Eigen { template <> struct NumTraits : GenericNumTraits { static inline Real dummy_precision() { return 1e-50; } }; template struct NumTraits > : NumTraits {}; template <> Real test_precision() { return 1e-50; } // 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) { return x.template convert_to(); } }; template <> struct cast_impl > { static inline std::complex run(const Real& x) { return std::complex(x); } }; } // namespace internal } // namespace Eigen namespace boost { namespace multiprecision { // to make ADL works as expected: using boost::math::copysign; using boost::math::hypot; using boost::math::isfinite; using boost::math::isinf; using boost::math::isnan; // 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) { return internal::isMuchSmallerThan(a, b, test_precision()); } inline bool test_isApprox(const Real& a, const Real& b) { return internal::isApprox(a, b, test_precision()); } inline bool test_isApproxOrLessThan(const Real& a, const Real& b) { return internal::isApproxOrLessThan(a, b, test_precision()); } Real get_test_precision(const Real&) { return test_precision(); } Real test_relative_error(const Real& a, const Real& b) { using Eigen::numext::abs2; return sqrt(abs2(a - b) / Eigen::numext::mini(abs2(a), abs2(b))); } } // namespace multiprecision } // namespace boost namespace Eigen {} EIGEN_DECLARE_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; std::cout << "NumTraits::max_digits10() = " << NumTraits::max_digits10() << std::endl; // check stream output { Mat A(10, 10); A.setRandom(); 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); CALL_SUBTEST_1(cholesky(Mat(s, s))); 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()); CALL_SUBTEST_4(qr()); CALL_SUBTEST_4(cod()); CALL_SUBTEST_4(qr_invertible()); CALL_SUBTEST_5(qr()); CALL_SUBTEST_5(qr_invertible()); 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_9( (jacobisvd_thin_options(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_full_options(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_thin_options(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_full_options(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_11((test_simplicial_cholesky_T())); }