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_extra(const MatrixType& m)
00028 {
00029 typedef typename MatrixType::Index Index;
00030 typedef typename MatrixType::Scalar Scalar;
00031 typedef typename NumTraits<Scalar>::NonInteger NonInteger;
00032 typedef Matrix<Scalar, 1, Dynamic> RowVectorType;
00033 typedef Matrix<Scalar, Dynamic, 1> ColVectorType;
00034 typedef Matrix<Scalar, Dynamic, Dynamic,
00035 MatrixType::Flags&RowMajorBit> OtherMajorMatrixType;
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(rows, cols),
00043 mzero = MatrixType::Zero(rows, cols),
00044 identity = MatrixType::Identity(rows, rows),
00045 square = MatrixType::Random(rows, rows),
00046 res = MatrixType::Random(rows, rows),
00047 square2 = MatrixType::Random(cols, cols),
00048 res2 = MatrixType::Random(cols, cols);
00049 RowVectorType v1 = RowVectorType::Random(rows), vrres(rows);
00050 ColVectorType vc2 = ColVectorType::Random(cols), vcres(cols);
00051 OtherMajorMatrixType tm1 = m1;
00052
00053 Scalar s1 = internal::random<Scalar>(),
00054 s2 = internal::random<Scalar>(),
00055 s3 = internal::random<Scalar>();
00056
00057 VERIFY_IS_APPROX(m3.noalias() = m1 * m2.adjoint(), m1 * m2.adjoint().eval());
00058 VERIFY_IS_APPROX(m3.noalias() = m1.adjoint() * square.adjoint(), m1.adjoint().eval() * square.adjoint().eval());
00059 VERIFY_IS_APPROX(m3.noalias() = m1.adjoint() * m2, m1.adjoint().eval() * m2);
00060 VERIFY_IS_APPROX(m3.noalias() = (s1 * m1.adjoint()) * m2, (s1 * m1.adjoint()).eval() * m2);
00061 VERIFY_IS_APPROX(m3.noalias() = ((s1 * m1).adjoint()) * m2, (internal::conj(s1) * m1.adjoint()).eval() * m2);
00062 VERIFY_IS_APPROX(m3.noalias() = (- m1.adjoint() * s1) * (s3 * m2), (- m1.adjoint() * s1).eval() * (s3 * m2).eval());
00063 VERIFY_IS_APPROX(m3.noalias() = (s2 * m1.adjoint() * s1) * m2, (s2 * m1.adjoint() * s1).eval() * m2);
00064 VERIFY_IS_APPROX(m3.noalias() = (-m1*s2) * s1*m2.adjoint(), (-m1*s2).eval() * (s1*m2.adjoint()).eval());
00065
00066
00067 VERIFY_IS_APPROX( m1.adjoint() * (s1*m2).conjugate(), (m1.adjoint()).eval() * ((s1*m2).conjugate()).eval());
00068
00069
00070
00071
00072 VERIFY_IS_APPROX((-m1.conjugate() * s2) * (s1 * vc2),
00073 (-m1.conjugate()*s2).eval() * (s1 * vc2).eval());
00074 VERIFY_IS_APPROX((-m1 * s2) * (s1 * vc2.conjugate()),
00075 (-m1*s2).eval() * (s1 * vc2.conjugate()).eval());
00076 VERIFY_IS_APPROX((-m1.conjugate() * s2) * (s1 * vc2.conjugate()),
00077 (-m1.conjugate()*s2).eval() * (s1 * vc2.conjugate()).eval());
00078
00079 VERIFY_IS_APPROX((s1 * vc2.transpose()) * (-m1.adjoint() * s2),
00080 (s1 * vc2.transpose()).eval() * (-m1.adjoint()*s2).eval());
00081 VERIFY_IS_APPROX((s1 * vc2.adjoint()) * (-m1.transpose() * s2),
00082 (s1 * vc2.adjoint()).eval() * (-m1.transpose()*s2).eval());
00083 VERIFY_IS_APPROX((s1 * vc2.adjoint()) * (-m1.adjoint() * s2),
00084 (s1 * vc2.adjoint()).eval() * (-m1.adjoint()*s2).eval());
00085
00086 VERIFY_IS_APPROX((-m1.adjoint() * s2) * (s1 * v1.transpose()),
00087 (-m1.adjoint()*s2).eval() * (s1 * v1.transpose()).eval());
00088 VERIFY_IS_APPROX((-m1.transpose() * s2) * (s1 * v1.adjoint()),
00089 (-m1.transpose()*s2).eval() * (s1 * v1.adjoint()).eval());
00090 VERIFY_IS_APPROX((-m1.adjoint() * s2) * (s1 * v1.adjoint()),
00091 (-m1.adjoint()*s2).eval() * (s1 * v1.adjoint()).eval());
00092
00093 VERIFY_IS_APPROX((s1 * v1) * (-m1.conjugate() * s2),
00094 (s1 * v1).eval() * (-m1.conjugate()*s2).eval());
00095 VERIFY_IS_APPROX((s1 * v1.conjugate()) * (-m1 * s2),
00096 (s1 * v1.conjugate()).eval() * (-m1*s2).eval());
00097 VERIFY_IS_APPROX((s1 * v1.conjugate()) * (-m1.conjugate() * s2),
00098 (s1 * v1.conjugate()).eval() * (-m1.conjugate()*s2).eval());
00099
00100 VERIFY_IS_APPROX((-m1.adjoint() * s2) * (s1 * v1.adjoint()),
00101 (-m1.adjoint()*s2).eval() * (s1 * v1.adjoint()).eval());
00102
00103
00104 Index i = internal::random<Index>(0,m1.rows()-2);
00105 Index j = internal::random<Index>(0,m1.cols()-2);
00106 Index r = internal::random<Index>(1,m1.rows()-i);
00107 Index c = internal::random<Index>(1,m1.cols()-j);
00108 Index i2 = internal::random<Index>(0,m1.rows()-1);
00109 Index j2 = internal::random<Index>(0,m1.cols()-1);
00110
00111 VERIFY_IS_APPROX(m1.col(j2).adjoint() * m1.block(0,j,m1.rows(),c), m1.col(j2).adjoint().eval() * m1.block(0,j,m1.rows(),c).eval());
00112 VERIFY_IS_APPROX(m1.block(i,0,r,m1.cols()) * m1.row(i2).adjoint(), m1.block(i,0,r,m1.cols()).eval() * m1.row(i2).adjoint().eval());
00113
00114
00115 MatrixType tmp = m1 * m1.adjoint() * s1;
00116 VERIFY_IS_APPROX(tmp, m1 * m1.adjoint() * s1);
00117 }
00118
00119 void zero_sized_objects()
00120 {
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 Matrix<float,1,Dynamic,RowMajor,1,5> a(1,4);
00139 Matrix<float,Dynamic,Dynamic,ColMajor,5,1> b(4,0);
00140 a*b;
00141 }
00142
00143 void test_product_extra()
00144 {
00145 for(int i = 0; i < g_repeat; i++) {
00146 CALL_SUBTEST_1( product_extra(MatrixXf(internal::random<int>(1,320), internal::random<int>(1,320))) );
00147 CALL_SUBTEST_2( product_extra(MatrixXd(internal::random<int>(1,320), internal::random<int>(1,320))) );
00148 CALL_SUBTEST_3( product_extra(MatrixXcf(internal::random<int>(1,150), internal::random<int>(1,150))) );
00149 CALL_SUBTEST_4( product_extra(MatrixXcd(internal::random<int>(1,150), internal::random<int>(1,150))) );
00150 CALL_SUBTEST_5( zero_sized_objects() );
00151 }
00152 }