selfadjoint.cpp
Go to the documentation of this file.
00001 // This file is triangularView of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.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 
00027 // This file tests the basic selfadjointView API,
00028 // the related products and decompositions are tested in specific files.
00029 
00030 template<typename MatrixType> void selfadjoint(const MatrixType& m)
00031 {
00032   typedef typename MatrixType::Index Index;
00033   typedef typename MatrixType::Scalar Scalar;
00034   typedef typename NumTraits<Scalar>::Real RealScalar;
00035 
00036   Index rows = m.rows();
00037   Index cols = m.cols();
00038 
00039   MatrixType m1 = MatrixType::Random(rows, cols),
00040              m3(rows, cols);
00041 
00042   m1.diagonal() = m1.diagonal().real().template cast<Scalar>();
00043 
00044   // check selfadjoint to dense
00045   m3 = m1.template selfadjointView<Upper>();
00046   VERIFY_IS_APPROX(MatrixType(m3.template triangularView<Upper>()), MatrixType(m1.template triangularView<Upper>()));
00047   VERIFY_IS_APPROX(m3, m3.adjoint());
00048 
00049 
00050   m3 = m1.template selfadjointView<Lower>();
00051   VERIFY_IS_APPROX(MatrixType(m3.template triangularView<Lower>()), MatrixType(m1.template triangularView<Lower>()));
00052   VERIFY_IS_APPROX(m3, m3.adjoint());
00053 }
00054 
00055 void bug_159()
00056 {
00057   Matrix3d m = Matrix3d::Random().selfadjointView<Lower>(); 
00058 }
00059 
00060 void test_selfadjoint()
00061 {
00062   for(int i = 0; i < g_repeat ; i++)
00063   {
00064     int s = internal::random<int>(1,20); EIGEN_UNUSED_VARIABLE(s);
00065 
00066     CALL_SUBTEST_1( selfadjoint(Matrix<float, 1, 1>()) );
00067     CALL_SUBTEST_2( selfadjoint(Matrix<float, 2, 2>()) );
00068     CALL_SUBTEST_3( selfadjoint(Matrix3cf()) );
00069     CALL_SUBTEST_4( selfadjoint(MatrixXcd(s,s)) );
00070     CALL_SUBTEST_5( selfadjoint(Matrix<float,Dynamic,Dynamic,RowMajor>(s, s)) );
00071   }
00072   
00073   CALL_SUBTEST_1( bug_159() );
00074 }


libicr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:33:20