Clang-format tests, examples, libraries, benchmarks, etc.

This commit is contained in:
Antonio Sánchez
2023-12-05 21:22:55 +00:00
committed by Rasmus Munk Larsen
parent 3252ecc7a4
commit 46e9cdb7fe
876 changed files with 33453 additions and 37795 deletions

View File

@@ -77,79 +77,74 @@
typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<100>, boost::multiprecision::et_on> Real;
namespace Eigen {
template<> struct NumTraits<Real> : GenericNumTraits<Real> {
static inline Real dummy_precision() { return 1e-50; }
};
template <>
struct NumTraits<Real> : GenericNumTraits<Real> {
static inline Real dummy_precision() { return 1e-50; }
};
template<typename T1,typename T2,typename T3,typename T4,typename T5>
struct NumTraits<boost::multiprecision::detail::expression<T1,T2,T3,T4,T5> > : NumTraits<Real> {};
template <typename T1, typename T2, typename T3, typename T4, typename T5>
struct NumTraits<boost::multiprecision::detail::expression<T1, T2, T3, T4, T5> > : NumTraits<Real> {};
template<>
Real test_precision<Real>() { return 1e-50; }
// 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) {
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);
}
};
}
template <>
Real test_precision<Real>() {
return 1e-50;
}
// 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) { 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); }
};
} // namespace internal
} // namespace Eigen
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;
// 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>:
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<Real>());
}
inline bool test_isApprox(const Real& a, const Real& b) {
return internal::isApprox(a, b, test_precision<Real>());
}
inline bool test_isApproxOrLessThan(const Real& a, const Real& b) {
return internal::isApproxOrLessThan(a, b, test_precision<Real>());
}
Real get_test_precision(const Real&) {
return test_precision<Real>();
}
Real test_relative_error(const Real &a, const Real &b) {
using Eigen::numext::abs2;
return sqrt(abs2<Real>(a-b)/Eigen::numext::mini<Real>(abs2(a),abs2(b)));
}
}
// 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);
}
namespace Eigen {
// some specialization for the unit tests:
inline bool test_isMuchSmallerThan(const Real& a, const Real& b) {
return internal::isMuchSmallerThan(a, b, test_precision<Real>());
}
EIGEN_DECLARE_TEST(boostmultiprec)
{
typedef Matrix<Real,Dynamic,Dynamic> Mat;
typedef Matrix<std::complex<Real>,Dynamic,Dynamic> MatC;
inline bool test_isApprox(const Real& a, const Real& b) { return internal::isApprox(a, b, test_precision<Real>()); }
inline bool test_isApproxOrLessThan(const Real& a, const Real& b) {
return internal::isApproxOrLessThan(a, b, test_precision<Real>());
}
Real get_test_precision(const Real&) { return test_precision<Real>(); }
Real test_relative_error(const Real& a, const Real& b) {
using Eigen::numext::abs2;
return sqrt(abs2<Real>(a - b) / Eigen::numext::mini<Real>(abs2(a), abs2(b)));
}
} // namespace multiprecision
} // namespace boost
namespace Eigen {}
EIGEN_DECLARE_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;
@@ -160,51 +155,58 @@ EIGEN_DECLARE_TEST(boostmultiprec)
// check stream output
{
Mat A(10,10);
Mat A(10, 10);
A.setRandom();
std::stringstream ss;
ss << A;
}
{
MatC A(10,10);
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);
for (int i = 0; i < g_repeat; i++) {
int s = internal::random<int>(1, EIGEN_TEST_MAX_SIZE);
CALL_SUBTEST_1( cholesky(Mat(s,s)) );
CALL_SUBTEST_1(cholesky(Mat(s, s)));
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_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>() );
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>());
CALL_SUBTEST_4( qr<Mat>() );
CALL_SUBTEST_4( cod<Mat>() );
CALL_SUBTEST_4( qr_invertible<Mat>() );
CALL_SUBTEST_4(qr<Mat>());
CALL_SUBTEST_4(cod<Mat>());
CALL_SUBTEST_4(qr_invertible<Mat>());
CALL_SUBTEST_5( qr<Mat>() );
CALL_SUBTEST_5( qr_invertible<Mat>() );
CALL_SUBTEST_5(qr<Mat>());
CALL_SUBTEST_5(qr_invertible<Mat>());
CALL_SUBTEST_6( selfadjointeigensolver(Mat(s,s)) );
CALL_SUBTEST_6(selfadjointeigensolver(Mat(s, s)));
CALL_SUBTEST_7( eigensolver(Mat(s,s)) );
CALL_SUBTEST_7(eigensolver(Mat(s, s)));
CALL_SUBTEST_8( generalized_eigensolver_real(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<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_full_options(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_thin_options(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_full_options(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_thin_options(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_full_options(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_thin_options(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_full_options(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_11(( test_simplicial_cholesky_T<Real,int,ColMajor>() ));
CALL_SUBTEST_11((test_simplicial_cholesky_T<Real, int, ColMajor>()));
}