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 MatrixType> void product_selfadjoint(const MatrixType& m)
00028 {
00029 typedef typename MatrixType::Index Index;
00030 typedef typename MatrixType::Scalar Scalar;
00031 typedef typename NumTraits<Scalar>::Real RealScalar;
00032 typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
00033 typedef Matrix<Scalar, 1, MatrixType::RowsAtCompileTime> RowVectorType;
00034
00035 typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, Dynamic, RowMajor> RhsMatrixType;
00036
00037 Index rows = m.rows();
00038 Index cols = m.cols();
00039
00040 MatrixType m1 = MatrixType::Random(rows, cols),
00041 m2 = MatrixType::Random(rows, cols),
00042 m3;
00043 VectorType v1 = VectorType::Random(rows),
00044 v2 = VectorType::Random(rows),
00045 v3(rows);
00046 RowVectorType r1 = RowVectorType::Random(rows),
00047 r2 = RowVectorType::Random(rows);
00048 RhsMatrixType m4 = RhsMatrixType::Random(rows,10);
00049
00050 Scalar s1 = internal::random<Scalar>(),
00051 s2 = internal::random<Scalar>(),
00052 s3 = internal::random<Scalar>();
00053
00054 m1 = (m1.adjoint() + m1).eval();
00055
00056
00057 m2 = m1.template triangularView<Lower>();
00058 m2.template selfadjointView<Lower>().rankUpdate(v1,v2);
00059 VERIFY_IS_APPROX(m2, (m1 + v1 * v2.adjoint()+ v2 * v1.adjoint()).template triangularView<Lower>().toDenseMatrix());
00060
00061 m2 = m1.template triangularView<Upper>();
00062 m2.template selfadjointView<Upper>().rankUpdate(-v1,s2*v2,s3);
00063 VERIFY_IS_APPROX(m2, (m1 + (s3*(-v1)*(s2*v2).adjoint()+internal::conj(s3)*(s2*v2)*(-v1).adjoint())).template triangularView<Upper>().toDenseMatrix());
00064
00065 m2 = m1.template triangularView<Upper>();
00066 m2.template selfadjointView<Upper>().rankUpdate(-s2*r1.adjoint(),r2.adjoint()*s3,s1);
00067 VERIFY_IS_APPROX(m2, (m1 + s1*(-s2*r1.adjoint())*(r2.adjoint()*s3).adjoint() + internal::conj(s1)*(r2.adjoint()*s3) * (-s2*r1.adjoint()).adjoint()).template triangularView<Upper>().toDenseMatrix());
00068
00069 if (rows>1)
00070 {
00071 m2 = m1.template triangularView<Lower>();
00072 m2.block(1,1,rows-1,cols-1).template selfadjointView<Lower>().rankUpdate(v1.tail(rows-1),v2.head(cols-1));
00073 m3 = m1;
00074 m3.block(1,1,rows-1,cols-1) += v1.tail(rows-1) * v2.head(cols-1).adjoint()+ v2.head(cols-1) * v1.tail(rows-1).adjoint();
00075 VERIFY_IS_APPROX(m2, m3.template triangularView<Lower>().toDenseMatrix());
00076 }
00077 }
00078
00079 void test_product_selfadjoint()
00080 {
00081 int s;
00082 for(int i = 0; i < g_repeat ; i++) {
00083 CALL_SUBTEST_1( product_selfadjoint(Matrix<float, 1, 1>()) );
00084 CALL_SUBTEST_2( product_selfadjoint(Matrix<float, 2, 2>()) );
00085 CALL_SUBTEST_3( product_selfadjoint(Matrix3d()) );
00086 s = internal::random<int>(1,150);
00087 CALL_SUBTEST_4( product_selfadjoint(MatrixXcf(s, s)) );
00088 s = internal::random<int>(1,150);
00089 CALL_SUBTEST_5( product_selfadjoint(MatrixXcd(s,s)) );
00090 s = internal::random<int>(1,320);
00091 CALL_SUBTEST_6( product_selfadjoint(MatrixXd(s,s)) );
00092 s = internal::random<int>(1,320);
00093 CALL_SUBTEST_7( product_selfadjoint(Matrix<float,Dynamic,Dynamic,RowMajor>(s,s)) );
00094 }
00095 }