00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "main.h"
00026
00027 template<typename Scalar, int Size, int OtherSize> void symm(int size = Size, int othersize = OtherSize)
00028 {
00029 typedef typename NumTraits<Scalar>::Real RealScalar;
00030
00031 typedef Matrix<Scalar, Size, Size> MatrixType;
00032 typedef Matrix<Scalar, Size, OtherSize> Rhs1;
00033 typedef Matrix<Scalar, OtherSize, Size> Rhs2;
00034 enum { order = OtherSize==1 ? 0 : RowMajor };
00035 typedef Matrix<Scalar, Size, OtherSize,order> Rhs3;
00036 typedef typename MatrixType::Index Index;
00037
00038 Index rows = size;
00039 Index cols = size;
00040
00041 MatrixType m1 = MatrixType::Random(rows, cols),
00042 m2 = MatrixType::Random(rows, cols), m3;
00043
00044 m1 = (m1+m1.adjoint()).eval();
00045
00046 Rhs1 rhs1 = Rhs1::Random(cols, othersize), rhs12(cols, othersize), rhs13(cols, othersize);
00047 Rhs2 rhs2 = Rhs2::Random(othersize, rows), rhs22(othersize, rows), rhs23(othersize, rows);
00048 Rhs3 rhs3 = Rhs3::Random(cols, othersize), rhs32(cols, othersize), rhs33(cols, othersize);
00049
00050 Scalar s1 = internal::random<Scalar>(),
00051 s2 = internal::random<Scalar>();
00052
00053 m2 = m1.template triangularView<Lower>();
00054 m3 = m2.template selfadjointView<Lower>();
00055 VERIFY_IS_EQUAL(m1, m3);
00056 VERIFY_IS_APPROX(rhs12 = (s1*m2).template selfadjointView<Lower>() * (s2*rhs1),
00057 rhs13 = (s1*m1) * (s2*rhs1));
00058
00059 m2 = m1.template triangularView<Upper>(); rhs12.setRandom(); rhs13 = rhs12;
00060 m3 = m2.template selfadjointView<Upper>();
00061 VERIFY_IS_EQUAL(m1, m3);
00062 VERIFY_IS_APPROX(rhs12 += (s1*m2).template selfadjointView<Upper>() * (s2*rhs1),
00063 rhs13 += (s1*m1) * (s2*rhs1));
00064
00065 m2 = m1.template triangularView<Lower>();
00066 VERIFY_IS_APPROX(rhs12 = (s1*m2).template selfadjointView<Lower>() * (s2*rhs2.adjoint()),
00067 rhs13 = (s1*m1) * (s2*rhs2.adjoint()));
00068
00069 m2 = m1.template triangularView<Upper>();
00070 VERIFY_IS_APPROX(rhs12 = (s1*m2).template selfadjointView<Upper>() * (s2*rhs2.adjoint()),
00071 rhs13 = (s1*m1) * (s2*rhs2.adjoint()));
00072
00073 m2 = m1.template triangularView<Upper>();
00074 VERIFY_IS_APPROX(rhs12 = (s1*m2.adjoint()).template selfadjointView<Lower>() * (s2*rhs2.adjoint()),
00075 rhs13 = (s1*m1.adjoint()) * (s2*rhs2.adjoint()));
00076
00077
00078 m2 = m1.template triangularView<Lower>(); rhs12.setRandom(); rhs13 = rhs12;
00079 VERIFY_IS_APPROX(rhs12 -= (s1*m2).template selfadjointView<Lower>() * (s2*rhs3),
00080 rhs13 -= (s1*m1) * (s2 * rhs3));
00081
00082 m2 = m1.template triangularView<Upper>();
00083 VERIFY_IS_APPROX(rhs12 = (s1*m2.adjoint()).template selfadjointView<Lower>() * (s2*rhs3).conjugate(),
00084 rhs13 = (s1*m1.adjoint()) * (s2*rhs3).conjugate());
00085
00086
00087 m2 = m1.template triangularView<Upper>(); rhs13 = rhs12;
00088 VERIFY_IS_APPROX(rhs12.noalias() += s1 * ((m2.adjoint()).template selfadjointView<Lower>() * (s2*rhs3).conjugate()),
00089 rhs13 += (s1*m1.adjoint()) * (s2*rhs3).conjugate());
00090
00091 m2 = m1.template triangularView<Lower>();
00092 VERIFY_IS_APPROX(rhs22 = (rhs2) * (m2).template selfadjointView<Lower>(), rhs23 = (rhs2) * (m1));
00093 VERIFY_IS_APPROX(rhs22 = (s2*rhs2) * (s1*m2).template selfadjointView<Lower>(), rhs23 = (s2*rhs2) * (s1*m1));
00094
00095 }
00096
00097 void test_product_symm()
00098 {
00099 for(int i = 0; i < g_repeat ; i++)
00100 {
00101 CALL_SUBTEST_1(( symm<float,Dynamic,Dynamic>(internal::random<int>(1,320),internal::random<int>(1,320)) ));
00102 CALL_SUBTEST_2(( symm<double,Dynamic,Dynamic>(internal::random<int>(1,320),internal::random<int>(1,320)) ));
00103 CALL_SUBTEST_3(( symm<std::complex<float>,Dynamic,Dynamic>(internal::random<int>(1,200),internal::random<int>(1,200)) ));
00104 CALL_SUBTEST_4(( symm<std::complex<double>,Dynamic,Dynamic>(internal::random<int>(1,200),internal::random<int>(1,200)) ));
00105
00106 CALL_SUBTEST_5(( symm<float,Dynamic,1>(internal::random<int>(1,320)) ));
00107 CALL_SUBTEST_6(( symm<double,Dynamic,1>(internal::random<int>(1,320)) ));
00108 CALL_SUBTEST_7(( symm<std::complex<float>,Dynamic,1>(internal::random<int>(1,320)) ));
00109 CALL_SUBTEST_8(( symm<std::complex<double>,Dynamic,1>(internal::random<int>(1,320)) ));
00110 }
00111 }