hessenberg.cpp
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 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 // Copyright (C) 2010 Jitse Niesen <jitse@maths.leeds.ac.uk>
00006 //
00007 // Eigen is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public
00009 // License as published by the Free Software Foundation; either
00010 // version 3 of the License, or (at your option) any later version.
00011 //
00012 // Alternatively, you can redistribute it and/or
00013 // modify it under the terms of the GNU General Public License as
00014 // published by the Free Software Foundation; either version 2 of
00015 // the License, or (at your option) any later version.
00016 //
00017 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00018 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00019 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00020 // GNU General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License and a copy of the GNU General Public License along with
00024 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00025 
00026 #include "main.h"
00027 #include <Eigen/Eigenvalues>
00028 
00029 template<typename Scalar,int Size> void hessenberg(int size = Size)
00030 {
00031   typedef Matrix<Scalar,Size,Size> MatrixType;
00032 
00033   // Test basic functionality: A = U H U* and H is Hessenberg
00034   for(int counter = 0; counter < g_repeat; ++counter) {
00035     MatrixType m = MatrixType::Random(size,size);
00036     HessenbergDecomposition<MatrixType> hess(m);
00037     MatrixType Q = hess.matrixQ();
00038     MatrixType H = hess.matrixH();
00039     VERIFY_IS_APPROX(m, Q * H * Q.adjoint());
00040     for(int row = 2; row < size; ++row) {
00041       for(int col = 0; col < row-1; ++col) {
00042         VERIFY(H(row,col) == (typename MatrixType::Scalar)0);
00043       }
00044     }
00045   }
00046 
00047   // Test whether compute() and constructor returns same result
00048   MatrixType A = MatrixType::Random(size, size);
00049   HessenbergDecomposition<MatrixType> cs1;
00050   cs1.compute(A);
00051   HessenbergDecomposition<MatrixType> cs2(A);
00052   VERIFY_IS_EQUAL(cs1.matrixH().eval(), cs2.matrixH().eval());
00053   MatrixType cs1Q = cs1.matrixQ();
00054   MatrixType cs2Q = cs2.matrixQ();  
00055   VERIFY_IS_EQUAL(cs1Q, cs2Q);
00056 
00057   // Test assertions for when used uninitialized
00058   HessenbergDecomposition<MatrixType> hessUninitialized;
00059   VERIFY_RAISES_ASSERT( hessUninitialized.matrixH() );
00060   VERIFY_RAISES_ASSERT( hessUninitialized.matrixQ() );
00061   VERIFY_RAISES_ASSERT( hessUninitialized.householderCoefficients() );
00062   VERIFY_RAISES_ASSERT( hessUninitialized.packedMatrix() );
00063 
00064   // TODO: Add tests for packedMatrix() and householderCoefficients()
00065 }
00066 
00067 void test_hessenberg()
00068 {
00069   CALL_SUBTEST_1(( hessenberg<std::complex<double>,1>() ));
00070   CALL_SUBTEST_2(( hessenberg<std::complex<double>,2>() ));
00071   CALL_SUBTEST_3(( hessenberg<std::complex<float>,4>() ));
00072   CALL_SUBTEST_4(( hessenberg<float,Dynamic>(internal::random<int>(1,320)) ));
00073   CALL_SUBTEST_5(( hessenberg<std::complex<double>,Dynamic>(internal::random<int>(1,320)) ));
00074 
00075   // Test problem size constructors
00076   CALL_SUBTEST_6(HessenbergDecomposition<MatrixXf>(10));
00077 }


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