schur_complex.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) 2010 Jitse Niesen <jitse@maths.leeds.ac.uk>
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 <limits>
00027 #include <Eigen/Eigenvalues>
00028 
00029 template<typename MatrixType> void schur(int size = MatrixType::ColsAtCompileTime)
00030 {
00031   typedef typename ComplexSchur<MatrixType>::ComplexScalar ComplexScalar;
00032   typedef typename ComplexSchur<MatrixType>::ComplexMatrixType ComplexMatrixType;
00033 
00034   // Test basic functionality: T is triangular and A = U T U*
00035   for(int counter = 0; counter < g_repeat; ++counter) {
00036     MatrixType A = MatrixType::Random(size, size);
00037     ComplexSchur<MatrixType> schurOfA(A);
00038     VERIFY_IS_EQUAL(schurOfA.info(), Success);
00039     ComplexMatrixType U = schurOfA.matrixU();
00040     ComplexMatrixType T = schurOfA.matrixT();
00041     for(int row = 1; row < size; ++row) {
00042       for(int col = 0; col < row; ++col) {
00043         VERIFY(T(row,col) == (typename MatrixType::Scalar)0);
00044       }
00045     }
00046     VERIFY_IS_APPROX(A.template cast<ComplexScalar>(), U * T * U.adjoint());
00047   }
00048 
00049   // Test asserts when not initialized
00050   ComplexSchur<MatrixType> csUninitialized;
00051   VERIFY_RAISES_ASSERT(csUninitialized.matrixT());
00052   VERIFY_RAISES_ASSERT(csUninitialized.matrixU());
00053   VERIFY_RAISES_ASSERT(csUninitialized.info());
00054   
00055   // Test whether compute() and constructor returns same result
00056   MatrixType A = MatrixType::Random(size, size);
00057   ComplexSchur<MatrixType> cs1;
00058   cs1.compute(A);
00059   ComplexSchur<MatrixType> cs2(A);
00060   VERIFY_IS_EQUAL(cs1.info(), Success);
00061   VERIFY_IS_EQUAL(cs2.info(), Success);
00062   VERIFY_IS_EQUAL(cs1.matrixT(), cs2.matrixT());
00063   VERIFY_IS_EQUAL(cs1.matrixU(), cs2.matrixU());
00064 
00065   // Test computation of only T, not U
00066   ComplexSchur<MatrixType> csOnlyT(A, false);
00067   VERIFY_IS_EQUAL(csOnlyT.info(), Success);
00068   VERIFY_IS_EQUAL(cs1.matrixT(), csOnlyT.matrixT());
00069   VERIFY_RAISES_ASSERT(csOnlyT.matrixU());
00070 
00071   if (size > 1)
00072   {
00073     // Test matrix with NaN
00074     A(0,0) = std::numeric_limits<typename MatrixType::RealScalar>::quiet_NaN();
00075     ComplexSchur<MatrixType> csNaN(A);
00076     VERIFY_IS_EQUAL(csNaN.info(), NoConvergence);
00077   }
00078 }
00079 
00080 void test_schur_complex()
00081 {
00082   CALL_SUBTEST_1(( schur<Matrix4cd>() ));
00083   CALL_SUBTEST_2(( schur<MatrixXcf>(internal::random<int>(1,50)) ));
00084   CALL_SUBTEST_3(( schur<Matrix<std::complex<float>, 1, 1> >() ));
00085   CALL_SUBTEST_4(( schur<Matrix<float, 3, 3, Eigen::RowMajor> >() ));
00086 
00087   // Test problem size constructors
00088   CALL_SUBTEST_5(ComplexSchur<MatrixXf>(10));
00089 }


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