eigen2_miscmatrices.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) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
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 template<typename MatrixType> void miscMatrices(const MatrixType& m)
00028 {
00029   /* this test covers the following files:
00030      DiagonalMatrix.h Ones.h
00031   */
00032 
00033   typedef typename MatrixType::Scalar Scalar;
00034   typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
00035   typedef Matrix<Scalar, 1, MatrixType::ColsAtCompileTime> RowVectorType;
00036   int rows = m.rows();
00037   int cols = m.cols();
00038 
00039   int r = ei_random<int>(0, rows-1), r2 = ei_random<int>(0, rows-1), c = ei_random<int>(0, cols-1);
00040   VERIFY_IS_APPROX(MatrixType::Ones(rows,cols)(r,c), static_cast<Scalar>(1));
00041   MatrixType m1 = MatrixType::Ones(rows,cols);
00042   VERIFY_IS_APPROX(m1(r,c), static_cast<Scalar>(1));
00043   VectorType v1 = VectorType::Random(rows);
00044   v1[0];
00045   Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>
00046   square = v1.asDiagonal();
00047   if(r==r2) VERIFY_IS_APPROX(square(r,r2), v1[r]);
00048   else VERIFY_IS_MUCH_SMALLER_THAN(square(r,r2), static_cast<Scalar>(1));
00049   square = MatrixType::Zero(rows, rows);
00050   square.diagonal() = VectorType::Ones(rows);
00051   VERIFY_IS_APPROX(square, MatrixType::Identity(rows, rows));
00052 }
00053 
00054 void test_eigen2_miscmatrices()
00055 {
00056   for(int i = 0; i < g_repeat; i++) {
00057     CALL_SUBTEST_1( miscMatrices(Matrix<float, 1, 1>()) );
00058     CALL_SUBTEST_2( miscMatrices(Matrix4d()) );
00059     CALL_SUBTEST_3( miscMatrices(MatrixXcf(3, 3)) );
00060     CALL_SUBTEST_4( miscMatrices(MatrixXi(8, 12)) );
00061     CALL_SUBTEST_5( miscMatrices(MatrixXcd(20, 20)) );
00062   }
00063 }


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