eigen2_inverse.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 // Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com>
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/LU>
00028 
00029 template<typename MatrixType> void inverse(const MatrixType& m)
00030 {
00031   /* this test covers the following files:
00032      Inverse.h
00033   */
00034   int rows = m.rows();
00035   int cols = m.cols();
00036 
00037   typedef typename MatrixType::Scalar Scalar;
00038   typedef typename NumTraits<Scalar>::Real RealScalar;
00039   typedef Matrix<Scalar, MatrixType::ColsAtCompileTime, 1> VectorType;
00040 
00041   MatrixType m1 = MatrixType::Random(rows, cols),
00042              m2(rows, cols),
00043              mzero = MatrixType::Zero(rows, cols),
00044              identity = MatrixType::Identity(rows, rows);
00045 
00046   while(ei_abs(m1.determinant()) < RealScalar(0.1) && rows <= 8)
00047   {
00048     m1 = MatrixType::Random(rows, cols);
00049   }
00050 
00051   m2 = m1.inverse();
00052   VERIFY_IS_APPROX(m1, m2.inverse() );
00053 
00054   m1.computeInverse(&m2);
00055   VERIFY_IS_APPROX(m1, m2.inverse() );
00056 
00057   VERIFY_IS_APPROX((Scalar(2)*m2).inverse(), m2.inverse()*Scalar(0.5));
00058 
00059   VERIFY_IS_APPROX(identity, m1.inverse() * m1 );
00060   VERIFY_IS_APPROX(identity, m1 * m1.inverse() );
00061 
00062   VERIFY_IS_APPROX(m1, m1.inverse().inverse() );
00063 
00064   // since for the general case we implement separately row-major and col-major, test that
00065   VERIFY_IS_APPROX(m1.transpose().inverse(), m1.inverse().transpose());
00066 }
00067 
00068 void test_eigen2_inverse()
00069 {
00070   for(int i = 0; i < g_repeat; i++) {
00071     CALL_SUBTEST_1( inverse(Matrix<double,1,1>()) );
00072     CALL_SUBTEST_2( inverse(Matrix2d()) );
00073     CALL_SUBTEST_3( inverse(Matrix3f()) );
00074     CALL_SUBTEST_4( inverse(Matrix4f()) );
00075     CALL_SUBTEST_5( inverse(MatrixXf(8,8)) );
00076     CALL_SUBTEST_6( inverse(MatrixXcd(7,7)) );
00077   }
00078 }


libicr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:32:38