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 Matrix<Scalar,Dynamic,Dynamic,ColMajor> MatrixColMaj; 23 typedef Matrix<Scalar,Dynamic,Dynamic,RowMajor> MatrixRowMaj; 24 25 DenseIndex othersize = internal::random<DenseIndex>(1,200); 26 27 MatrixColMaj matc = MatrixColMaj::Zero(size, size); 28 MatrixRowMaj matr = MatrixRowMaj::Zero(size, size); 29 MatrixColMaj ref1(size, size), ref2(size, size); 30 31 MatrixColMaj soc(size,othersize); soc.setRandom(); 32 MatrixColMaj osc(othersize,size); osc.setRandom(); 33 MatrixRowMaj sor(size,othersize); sor.setRandom(); 34 MatrixRowMaj osr(othersize,size); osr.setRandom(); 35 36 Scalar s = internal::random<Scalar>(); 37 38 CHECK_MMTR(matc, Lower, = s*soc*sor.adjoint()); 39 CHECK_MMTR(matc, Upper, = s*(soc*soc.adjoint())); 40 CHECK_MMTR(matr, Lower, = s*soc*soc.adjoint()); 41 CHECK_MMTR(matr, Upper, = soc*(s*sor.adjoint())); 42 43 CHECK_MMTR(matc, Lower, += s*soc*soc.adjoint()); 44 CHECK_MMTR(matc, Upper, += s*(soc*sor.transpose())); 45 CHECK_MMTR(matr, Lower, += s*sor*soc.adjoint()); 46 CHECK_MMTR(matr, Upper, += soc*(s*soc.adjoint())); 47 48 CHECK_MMTR(matc, Lower, -= s*soc*soc.adjoint()); 49 CHECK_MMTR(matc, Upper, -= s*(osc.transpose()*osc.conjugate())); 50 CHECK_MMTR(matr, Lower, -= s*soc*soc.adjoint()); 51 CHECK_MMTR(matr, Upper, -= soc*(s*soc.adjoint())); 52 } 53 54 void test_product_mmtr() 55 { 56 for(int i = 0; i < g_repeat ; i++) 57 { 58 CALL_SUBTEST_1((mmtr<float>(internal::random<int>(1,EIGEN_TEST_MAX_SIZE)))); 59 CALL_SUBTEST_2((mmtr<double>(internal::random<int>(1,EIGEN_TEST_MAX_SIZE)))); 60 CALL_SUBTEST_3((mmtr<std::complex<float> >(internal::random<int>(1,EIGEN_TEST_MAX_SIZE/2)))); 61 CALL_SUBTEST_4((mmtr<std::complex<double> >(internal::random<int>(1,EIGEN_TEST_MAX_SIZE/2)))); 62 } 63 } 64