1 // This file is part of Eigen, a lightweight C++ template library 2 // for linear algebra. 3 // 4 // Copyright (C) 2010 Gael Guennebaud <gael.guennebaud (at) inria.fr> 5 // 6 // This Source Code Form is subject to the terms of the Mozilla 7 // Public License v. 2.0. If a copy of the MPL was not distributed 8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 10 #include "main.h" 11 12 #define CHECK_MMTR(DEST, TRI, OP) { \ 13 ref2 = ref1 = DEST; \ 14 DEST.template triangularView<TRI>() OP; \ 15 ref1 OP; \ 16 ref2.template triangularView<TRI>() = ref1; \ 17 VERIFY_IS_APPROX(DEST,ref2); \ 18 } 19 20 template<typename Scalar> void mmtr(int size) 21 { 22 typedef typename NumTraits<Scalar>::Real RealScalar; 23 24 typedef Matrix<Scalar,Dynamic,Dynamic,ColMajor> MatrixColMaj; 25 typedef Matrix<Scalar,Dynamic,Dynamic,RowMajor> MatrixRowMaj; 26 27 DenseIndex othersize = internal::random<DenseIndex>(1,200); 28 29 MatrixColMaj matc(size, size); 30 MatrixRowMaj matr(size, size); 31 MatrixColMaj ref1(size, size), ref2(size, size); 32 33 MatrixColMaj soc(size,othersize); soc.setRandom(); 34 MatrixColMaj osc(othersize,size); osc.setRandom(); 35 MatrixRowMaj sor(size,othersize); sor.setRandom(); 36 MatrixRowMaj osr(othersize,size); osr.setRandom(); 37 38 Scalar s = internal::random<Scalar>(); 39 40 CHECK_MMTR(matc, Lower, = s*soc*sor.adjoint()); 41 CHECK_MMTR(matc, Upper, = s*(soc*soc.adjoint())); 42 CHECK_MMTR(matr, Lower, = s*soc*soc.adjoint()); 43 CHECK_MMTR(matr, Upper, = soc*(s*sor.adjoint())); 44 45 CHECK_MMTR(matc, Lower, += s*soc*soc.adjoint()); 46 CHECK_MMTR(matc, Upper, += s*(soc*sor.transpose())); 47 CHECK_MMTR(matr, Lower, += s*sor*soc.adjoint()); 48 CHECK_MMTR(matr, Upper, += soc*(s*soc.adjoint())); 49 50 CHECK_MMTR(matc, Lower, -= s*soc*soc.adjoint()); 51 CHECK_MMTR(matc, Upper, -= s*(osc.transpose()*osc.conjugate())); 52 CHECK_MMTR(matr, Lower, -= s*soc*soc.adjoint()); 53 CHECK_MMTR(matr, Upper, -= soc*(s*soc.adjoint())); 54 } 55 56 void test_product_mmtr() 57 { 58 for(int i = 0; i < g_repeat ; i++) 59 { 60 CALL_SUBTEST_1((mmtr<float>(internal::random<int>(1,EIGEN_TEST_MAX_SIZE)))); 61 CALL_SUBTEST_2((mmtr<double>(internal::random<int>(1,EIGEN_TEST_MAX_SIZE)))); 62 CALL_SUBTEST_3((mmtr<std::complex<float> >(internal::random<int>(1,EIGEN_TEST_MAX_SIZE/2)))); 63 CALL_SUBTEST_4((mmtr<std::complex<double> >(internal::random<int>(1,EIGEN_TEST_MAX_SIZE/2)))); 64 } 65 } 66