eigen2_qr.cpp
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra. Eigen itself is part of the KDE project.
00003 //
00004 // Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
00005 //
00006 // Eigen is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 3 of the License, or (at your option) any later version.
00010 //
00011 // Alternatively, you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License as
00013 // published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License and a copy of the GNU General Public License along with
00023 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00024 
00025 #include "main.h"
00026 #include <Eigen/QR>
00027 
00028 template<typename MatrixType> void qr(const MatrixType& m)
00029 {
00030   /* this test covers the following files:
00031      QR.h
00032   */
00033   int rows = m.rows();
00034   int cols = m.cols();
00035 
00036   typedef typename MatrixType::Scalar Scalar;
00037   typedef Matrix<Scalar, MatrixType::ColsAtCompileTime, MatrixType::ColsAtCompileTime> SquareMatrixType;
00038   typedef Matrix<Scalar, MatrixType::ColsAtCompileTime, 1> VectorType;
00039 
00040   MatrixType a = MatrixType::Random(rows,cols);
00041   QR<MatrixType> qrOfA(a);
00042   VERIFY_IS_APPROX(a, qrOfA.matrixQ() * qrOfA.matrixR());
00043   VERIFY_IS_NOT_APPROX(a+MatrixType::Identity(rows, cols), qrOfA.matrixQ() * qrOfA.matrixR());
00044 
00045   #if 0 // eigenvalues module not yet ready
00046   SquareMatrixType b = a.adjoint() * a;
00047 
00048   // check tridiagonalization
00049   Tridiagonalization<SquareMatrixType> tridiag(b);
00050   VERIFY_IS_APPROX(b, tridiag.matrixQ() * tridiag.matrixT() * tridiag.matrixQ().adjoint());
00051 
00052   // check hessenberg decomposition
00053   HessenbergDecomposition<SquareMatrixType> hess(b);
00054   VERIFY_IS_APPROX(b, hess.matrixQ() * hess.matrixH() * hess.matrixQ().adjoint());
00055   VERIFY_IS_APPROX(tridiag.matrixT(), hess.matrixH());
00056   b = SquareMatrixType::Random(cols,cols);
00057   hess.compute(b);
00058   VERIFY_IS_APPROX(b, hess.matrixQ() * hess.matrixH() * hess.matrixQ().adjoint());
00059   #endif
00060 }
00061 
00062 void test_eigen2_qr()
00063 {
00064   for(int i = 0; i < 1; i++) {
00065     CALL_SUBTEST_1( qr(Matrix2f()) );
00066     CALL_SUBTEST_2( qr(Matrix4d()) );
00067     CALL_SUBTEST_3( qr(MatrixXf(12,8)) );
00068     CALL_SUBTEST_4( qr(MatrixXcd(5,5)) );
00069     CALL_SUBTEST_4( qr(MatrixXcd(7,3)) );
00070   }
00071 
00072 #ifdef EIGEN_TEST_PART_5
00073   // small isFullRank test
00074   {
00075     Matrix3d mat;
00076     mat << 1, 45, 1, 2, 2, 2, 1, 2, 3;
00077     VERIFY(mat.qr().isFullRank());
00078     mat << 1, 1, 1, 2, 2, 2, 1, 2, 3;
00079     //always returns true in eigen2support
00080     //VERIFY(!mat.qr().isFullRank());
00081   }
00082 
00083 #endif
00084 }


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:31:04