matrix_functions.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2009-2011 Jitse Niesen <jitse@maths.leeds.ac.uk>
00005 //
00006 // This Source Code Form is subject to the terms of the Mozilla
00007 // Public License v. 2.0. If a copy of the MPL was not distributed
00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
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 // for real matrices, make sure none of the eigenvalues are negative
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 // for complex matrices, any matrix is fine
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 }


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:33:01