eigen2support.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 //
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 #define EIGEN2_SUPPORT
00026 
00027 #include "main.h"
00028 
00029 template<typename MatrixType> void eigen2support(const MatrixType& m)
00030 {
00031   typedef typename MatrixType::Index Index;
00032   typedef typename MatrixType::Scalar Scalar;
00033 
00034   Index rows = m.rows();
00035   Index cols = m.cols();
00036 
00037   MatrixType m1 = MatrixType::Random(rows, cols),
00038              m2 = MatrixType::Random(rows, cols),
00039              m3(rows, cols);
00040 
00041   Scalar  s1 = internal::random<Scalar>(),
00042           s2 = internal::random<Scalar>();
00043 
00044   // scalar addition
00045   VERIFY_IS_APPROX(m1.cwise() + s1, s1 + m1.cwise());
00046   VERIFY_IS_APPROX(m1.cwise() + s1, MatrixType::Constant(rows,cols,s1) + m1);
00047   VERIFY_IS_APPROX((m1*Scalar(2)).cwise() - s2, (m1+m1) - MatrixType::Constant(rows,cols,s2) );
00048   m3 = m1;
00049   m3.cwise() += s2;
00050   VERIFY_IS_APPROX(m3, m1.cwise() + s2);
00051   m3 = m1;
00052   m3.cwise() -= s1;
00053   VERIFY_IS_APPROX(m3, m1.cwise() - s1);
00054 
00055   VERIFY_IS_EQUAL((m1.corner(TopLeft,1,1)), (m1.block(0,0,1,1)));
00056   VERIFY_IS_EQUAL((m1.template corner<1,1>(TopLeft)), (m1.template block<1,1>(0,0)));
00057   VERIFY_IS_EQUAL((m1.col(0).start(1)), (m1.col(0).segment(0,1)));
00058   VERIFY_IS_EQUAL((m1.col(0).template start<1>()), (m1.col(0).segment(0,1)));
00059   VERIFY_IS_EQUAL((m1.col(0).end(1)), (m1.col(0).segment(rows-1,1)));
00060   VERIFY_IS_EQUAL((m1.col(0).template end<1>()), (m1.col(0).segment(rows-1,1)));
00061   
00062   using namespace internal;
00063   VERIFY_IS_EQUAL(ei_cos(s1), cos(s1));
00064   VERIFY_IS_EQUAL(ei_real(s1), real(s1));
00065   VERIFY_IS_EQUAL(ei_abs2(s1), abs2(s1));
00066 
00067   m1.minor(0,0);
00068 }
00069 
00070 void test_eigen2support()
00071 {
00072   for(int i = 0; i < g_repeat; i++) {
00073     CALL_SUBTEST_1( eigen2support(Matrix<double,1,1>()) );
00074     CALL_SUBTEST_2( eigen2support(MatrixXd(1,1)) );
00075     CALL_SUBTEST_4( eigen2support(Matrix3f()) );
00076     CALL_SUBTEST_5( eigen2support(Matrix4d()) );
00077     CALL_SUBTEST_2( eigen2support(MatrixXf(200,200)) );
00078     CALL_SUBTEST_6( eigen2support(MatrixXcd(100,100)) );
00079   }
00080 }


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