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 syrk(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::ColsAtCompileTime, Dynamic> Rhs1;
00033 typedef Matrix<Scalar, Dynamic, MatrixType::RowsAtCompileTime> Rhs2;
00034 typedef Matrix<Scalar, MatrixType::ColsAtCompileTime, Dynamic,RowMajor> Rhs3;
00035
00036 Index rows = m.rows();
00037 Index cols = m.cols();
00038
00039 MatrixType m1 = MatrixType::Random(rows, cols),
00040 m2 = MatrixType::Random(rows, cols);
00041
00042 Rhs1 rhs1 = Rhs1::Random(internal::random<int>(1,320), cols);
00043 Rhs2 rhs2 = Rhs2::Random(rows, internal::random<int>(1,320));
00044 Rhs3 rhs3 = Rhs3::Random(internal::random<int>(1,320), rows);
00045
00046 Scalar s1 = internal::random<Scalar>();
00047
00048 Index c = internal::random<Index>(0,cols-1);
00049
00050 m2.setZero();
00051 VERIFY_IS_APPROX((m2.template selfadjointView<Lower>().rankUpdate(rhs2,s1)._expression()),
00052 ((s1 * rhs2 * rhs2.adjoint()).eval().template triangularView<Lower>().toDenseMatrix()));
00053
00054 m2.setZero();
00055 VERIFY_IS_APPROX(m2.template selfadjointView<Upper>().rankUpdate(rhs2,s1)._expression(),
00056 (s1 * rhs2 * rhs2.adjoint()).eval().template triangularView<Upper>().toDenseMatrix());
00057
00058 m2.setZero();
00059 VERIFY_IS_APPROX(m2.template selfadjointView<Lower>().rankUpdate(rhs1.adjoint(),s1)._expression(),
00060 (s1 * rhs1.adjoint() * rhs1).eval().template triangularView<Lower>().toDenseMatrix());
00061
00062 m2.setZero();
00063 VERIFY_IS_APPROX(m2.template selfadjointView<Upper>().rankUpdate(rhs1.adjoint(),s1)._expression(),
00064 (s1 * rhs1.adjoint() * rhs1).eval().template triangularView<Upper>().toDenseMatrix());
00065
00066 m2.setZero();
00067 VERIFY_IS_APPROX(m2.template selfadjointView<Lower>().rankUpdate(rhs3.adjoint(),s1)._expression(),
00068 (s1 * rhs3.adjoint() * rhs3).eval().template triangularView<Lower>().toDenseMatrix());
00069
00070 m2.setZero();
00071 VERIFY_IS_APPROX(m2.template selfadjointView<Upper>().rankUpdate(rhs3.adjoint(),s1)._expression(),
00072 (s1 * rhs3.adjoint() * rhs3).eval().template triangularView<Upper>().toDenseMatrix());
00073
00074 m2.setZero();
00075 VERIFY_IS_APPROX((m2.template selfadjointView<Lower>().rankUpdate(m1.col(c),s1)._expression()),
00076 ((s1 * m1.col(c) * m1.col(c).adjoint()).eval().template triangularView<Lower>().toDenseMatrix()));
00077
00078 m2.setZero();
00079 VERIFY_IS_APPROX((m2.template selfadjointView<Upper>().rankUpdate(m1.col(c),s1)._expression()),
00080 ((s1 * m1.col(c) * m1.col(c).adjoint()).eval().template triangularView<Upper>().toDenseMatrix()));
00081
00082 m2.setZero();
00083 VERIFY_IS_APPROX((m2.template selfadjointView<Lower>().rankUpdate(m1.col(c).conjugate(),s1)._expression()),
00084 ((s1 * m1.col(c).conjugate() * m1.col(c).conjugate().adjoint()).eval().template triangularView<Lower>().toDenseMatrix()));
00085
00086 m2.setZero();
00087 VERIFY_IS_APPROX((m2.template selfadjointView<Upper>().rankUpdate(m1.col(c).conjugate(),s1)._expression()),
00088 ((s1 * m1.col(c).conjugate() * m1.col(c).conjugate().adjoint()).eval().template triangularView<Upper>().toDenseMatrix()));
00089
00090 m2.setZero();
00091 VERIFY_IS_APPROX((m2.template selfadjointView<Lower>().rankUpdate(m1.row(c),s1)._expression()),
00092 ((s1 * m1.row(c).transpose() * m1.row(c).transpose().adjoint()).eval().template triangularView<Lower>().toDenseMatrix()));
00093
00094 m2.setZero();
00095 VERIFY_IS_APPROX((m2.template selfadjointView<Upper>().rankUpdate(m1.row(c).adjoint(),s1)._expression()),
00096 ((s1 * m1.row(c).adjoint() * m1.row(c).adjoint().adjoint()).eval().template triangularView<Upper>().toDenseMatrix()));
00097 }
00098
00099 void test_product_syrk()
00100 {
00101 for(int i = 0; i < g_repeat ; i++)
00102 {
00103 int s;
00104 s = internal::random<int>(1,320);
00105 CALL_SUBTEST_1( syrk(MatrixXf(s, s)) );
00106 s = internal::random<int>(1,320);
00107 CALL_SUBTEST_2( syrk(MatrixXd(s, s)) );
00108 s = internal::random<int>(1,200);
00109 CALL_SUBTEST_3( syrk(MatrixXcf(s, s)) );
00110 s = internal::random<int>(1,200);
00111 CALL_SUBTEST_4( syrk(MatrixXcd(s, s)) );
00112 }
00113 }