product_mmtr.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) 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 #define CHECK_MMTR(DEST, TRI, OP) {                   \
00028     ref2 = ref1 = DEST;                               \
00029     DEST.template triangularView<TRI>() OP;           \
00030     ref1 OP;                                          \
00031     ref2.template triangularView<TRI>() = ref1;       \
00032     VERIFY_IS_APPROX(DEST,ref2);                      \
00033   }
00034 
00035 template<typename Scalar> void mmtr(int size)
00036 {
00037   typedef typename NumTraits<Scalar>::Real RealScalar;
00038 
00039   typedef Matrix<Scalar,Dynamic,Dynamic,ColMajor> MatrixColMaj;
00040   typedef Matrix<Scalar,Dynamic,Dynamic,RowMajor> MatrixRowMaj;
00041 
00042   DenseIndex othersize = internal::random<DenseIndex>(1,200);
00043   
00044   MatrixColMaj matc(size, size);
00045   MatrixRowMaj matr(size, size);
00046   MatrixColMaj ref1(size, size), ref2(size, size);
00047   
00048   MatrixColMaj soc(size,othersize); soc.setRandom();
00049   MatrixColMaj osc(othersize,size); osc.setRandom();
00050   MatrixRowMaj sor(size,othersize); sor.setRandom();
00051   MatrixRowMaj osr(othersize,size); osr.setRandom();
00052   
00053   Scalar s = internal::random<Scalar>();
00054   
00055   CHECK_MMTR(matc, Lower, = s*soc*sor.adjoint());
00056   CHECK_MMTR(matc, Upper, = s*(soc*soc.adjoint()));
00057   CHECK_MMTR(matr, Lower, = s*soc*soc.adjoint());
00058   CHECK_MMTR(matr, Upper, = soc*(s*sor.adjoint()));
00059   
00060   CHECK_MMTR(matc, Lower, += s*soc*soc.adjoint());
00061   CHECK_MMTR(matc, Upper, += s*(soc*sor.transpose()));
00062   CHECK_MMTR(matr, Lower, += s*sor*soc.adjoint());
00063   CHECK_MMTR(matr, Upper, += soc*(s*soc.adjoint()));
00064   
00065   CHECK_MMTR(matc, Lower, -= s*soc*soc.adjoint());
00066   CHECK_MMTR(matc, Upper, -= s*(osc.transpose()*osc.conjugate()));
00067   CHECK_MMTR(matr, Lower, -= s*soc*soc.adjoint());
00068   CHECK_MMTR(matr, Upper, -= soc*(s*soc.adjoint()));
00069 }
00070 
00071 void test_product_mmtr()
00072 {
00073   for(int i = 0; i < g_repeat ; i++)
00074   {
00075     CALL_SUBTEST_1((mmtr<float>(internal::random<int>(1,320))));
00076     CALL_SUBTEST_2((mmtr<double>(internal::random<int>(1,320))));
00077     CALL_SUBTEST_3((mmtr<std::complex<float> >(internal::random<int>(1,200))));
00078     CALL_SUBTEST_4((mmtr<std::complex<double> >(internal::random<int>(1,200))));
00079   }
00080 }


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