Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "main.h"
00011 #include <unsupported/Eigen/MatrixFunctions>
00012
00013 template <typename MatrixType, int IsComplex = NumTraits<typename internal::traits<MatrixType>::Scalar>::IsComplex>
00014 struct generateTestMatrix;
00015
00016
00017 template <typename MatrixType>
00018 struct generateTestMatrix<MatrixType,0>
00019 {
00020 static void run(MatrixType& result, typename MatrixType::Index size)
00021 {
00022 MatrixType mat = MatrixType::Random(size, size);
00023 EigenSolver<MatrixType> es(mat);
00024 typename EigenSolver<MatrixType>::EigenvalueType eivals = es.eigenvalues();
00025 for (typename MatrixType::Index i = 0; i < size; ++i) {
00026 if (eivals(i).imag() == 0 && eivals(i).real() < 0)
00027 eivals(i) = -eivals(i);
00028 }
00029 result = (es.eigenvectors() * eivals.asDiagonal() * es.eigenvectors().inverse()).real();
00030 }
00031 };
00032
00033
00034 template <typename MatrixType>
00035 struct generateTestMatrix<MatrixType,1>
00036 {
00037 static void run(MatrixType& result, typename MatrixType::Index size)
00038 {
00039 result = MatrixType::Random(size, size);
00040 }
00041 };
00042
00043 template <typename Derived, typename OtherDerived>
00044 double relerr(const MatrixBase<Derived>& A, const MatrixBase<OtherDerived>& B)
00045 {
00046 return std::sqrt((A - B).cwiseAbs2().sum() / (std::min)(A.cwiseAbs2().sum(), B.cwiseAbs2().sum()));
00047 }