mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
remove GSL dependency in the unit tests
This commit is contained in:
@@ -27,10 +27,6 @@
|
||||
#include <limits>
|
||||
#include <Eigen/Eigenvalues>
|
||||
|
||||
#ifdef HAS_GSL
|
||||
#include "gsl_helper.h"
|
||||
#endif
|
||||
|
||||
template<typename MatrixType> void selfadjointeigensolver(const MatrixType& m)
|
||||
{
|
||||
typedef typename MatrixType::Index Index;
|
||||
@@ -64,52 +60,6 @@ template<typename MatrixType> void selfadjointeigensolver(const MatrixType& m)
|
||||
// generalized eigen pb
|
||||
GeneralizedSelfAdjointEigenSolver<MatrixType> eiSymmGen(symmA, symmB);
|
||||
|
||||
#ifdef HAS_GSL
|
||||
if (internal::is_same<RealScalar,double>::value)
|
||||
{
|
||||
// restore symmA and symmB.
|
||||
symmA = MatrixType(symmA.template selfadjointView<Lower>());
|
||||
symmB = MatrixType(symmB.template selfadjointView<Lower>());
|
||||
typedef GslTraits<Scalar> Gsl;
|
||||
typename Gsl::Matrix gEvec=0, gSymmA=0, gSymmB=0;
|
||||
typename GslTraits<RealScalar>::Vector gEval=0;
|
||||
RealVectorType _eval;
|
||||
MatrixType _evec;
|
||||
convert<MatrixType>(symmA, gSymmA);
|
||||
convert<MatrixType>(symmB, gSymmB);
|
||||
convert<MatrixType>(symmA, gEvec);
|
||||
gEval = GslTraits<RealScalar>::createVector(rows);
|
||||
|
||||
Gsl::eigen_symm(gSymmA, gEval, gEvec);
|
||||
convert(gEval, _eval);
|
||||
convert(gEvec, _evec);
|
||||
|
||||
// test gsl itself !
|
||||
VERIFY((symmA * _evec).isApprox(_evec * _eval.asDiagonal(), largerEps));
|
||||
|
||||
// compare with eigen
|
||||
VERIFY_IS_APPROX(_eval, eiSymm.eigenvalues());
|
||||
VERIFY_IS_APPROX(_evec.cwiseAbs(), eiSymm.eigenvectors().cwiseAbs());
|
||||
|
||||
// generalized pb
|
||||
Gsl::eigen_symm_gen(gSymmA, gSymmB, gEval, gEvec);
|
||||
convert(gEval, _eval);
|
||||
convert(gEvec, _evec);
|
||||
// test GSL itself:
|
||||
VERIFY((symmA * _evec).isApprox(symmB * (_evec * _eval.asDiagonal()), largerEps));
|
||||
|
||||
// compare with eigen
|
||||
MatrixType normalized_eivec = eiSymmGen.eigenvectors()*eiSymmGen.eigenvectors().colwise().norm().asDiagonal().inverse();
|
||||
VERIFY_IS_APPROX(_eval, eiSymmGen.eigenvalues());
|
||||
VERIFY_IS_APPROX(_evec.cwiseAbs(), normalized_eivec.cwiseAbs());
|
||||
|
||||
Gsl::free(gSymmA);
|
||||
Gsl::free(gSymmB);
|
||||
GslTraits<RealScalar>::free(gEval);
|
||||
Gsl::free(gEvec);
|
||||
}
|
||||
#endif
|
||||
|
||||
VERIFY_IS_EQUAL(eiSymm.info(), Success);
|
||||
VERIFY((symmA.template selfadjointView<Lower>() * eiSymm.eigenvectors()).isApprox(
|
||||
eiSymm.eigenvectors() * eiSymm.eigenvalues().asDiagonal(), largerEps));
|
||||
@@ -180,7 +130,8 @@ void test_eigensolver_selfadjoint()
|
||||
{
|
||||
int s;
|
||||
for(int i = 0; i < g_repeat; i++) {
|
||||
// very important to test a 3x3 matrix since we provide a special path for it
|
||||
// very important to test 3x3 and 2x2 matrices since we provide special paths for them
|
||||
CALL_SUBTEST_1( selfadjointeigensolver(Matrix2d()) );
|
||||
CALL_SUBTEST_1( selfadjointeigensolver(Matrix3f()) );
|
||||
CALL_SUBTEST_2( selfadjointeigensolver(Matrix4d()) );
|
||||
s = internal::random<int>(1,EIGEN_TEST_MAX_SIZE/4);
|
||||
|
||||
Reference in New Issue
Block a user