| 10 | #include "main.h" |
| 11 | |
| 12 | template<typename MatrixType> void product_extra(const MatrixType& m) |
| 13 | { |
| 14 | typedef typename MatrixType::Index Index; |
| 15 | typedef typename MatrixType::Scalar Scalar; |
| 16 | typedef Matrix<Scalar, 1, Dynamic> RowVectorType; |
| 17 | typedef Matrix<Scalar, Dynamic, 1> ColVectorType; |
| 18 | typedef Matrix<Scalar, Dynamic, Dynamic, |
| 19 | MatrixType::Flags&RowMajorBit> OtherMajorMatrixType; |
| 20 | |
| 21 | Index rows = m.rows(); |
| 22 | Index cols = m.cols(); |
| 23 | |
| 24 | MatrixType m1 = MatrixType::Random(rows, cols), |
| 25 | m2 = MatrixType::Random(rows, cols), |
| 26 | m3(rows, cols), |
| 27 | mzero = MatrixType::Zero(rows, cols), |
| 28 | identity = MatrixType::Identity(rows, rows), |
| 29 | square = MatrixType::Random(rows, rows), |
| 30 | res = MatrixType::Random(rows, rows), |
| 31 | square2 = MatrixType::Random(cols, cols), |
| 32 | res2 = MatrixType::Random(cols, cols); |
| 33 | RowVectorType v1 = RowVectorType::Random(rows), vrres(rows); |
| 34 | ColVectorType vc2 = ColVectorType::Random(cols), vcres(cols); |
| 35 | OtherMajorMatrixType tm1 = m1; |
| 36 | |
| 37 | Scalar s1 = internal::random<Scalar>(), |
| 38 | s2 = internal::random<Scalar>(), |
| 39 | s3 = internal::random<Scalar>(); |
| 40 | |
| 41 | VERIFY_IS_APPROX(m3.noalias() = m1 * m2.adjoint(), m1 * m2.adjoint().eval()); |
| 42 | VERIFY_IS_APPROX(m3.noalias() = m1.adjoint() * square.adjoint(), m1.adjoint().eval() * square.adjoint().eval()); |
| 43 | VERIFY_IS_APPROX(m3.noalias() = m1.adjoint() * m2, m1.adjoint().eval() * m2); |
| 44 | VERIFY_IS_APPROX(m3.noalias() = (s1 * m1.adjoint()) * m2, (s1 * m1.adjoint()).eval() * m2); |
| 45 | VERIFY_IS_APPROX(m3.noalias() = ((s1 * m1).adjoint()) * m2, (numext::conj(s1) * m1.adjoint()).eval() * m2); |
| 46 | VERIFY_IS_APPROX(m3.noalias() = (- m1.adjoint() * s1) * (s3 * m2), (- m1.adjoint() * s1).eval() * (s3 * m2).eval()); |
| 47 | VERIFY_IS_APPROX(m3.noalias() = (s2 * m1.adjoint() * s1) * m2, (s2 * m1.adjoint() * s1).eval() * m2); |
| 48 | VERIFY_IS_APPROX(m3.noalias() = (-m1*s2) * s1*m2.adjoint(), (-m1*s2).eval() * (s1*m2.adjoint()).eval()); |
| 49 | |
| 50 | // a very tricky case where a scale factor has to be automatically conjugated: |
| 51 | VERIFY_IS_APPROX( m1.adjoint() * (s1*m2).conjugate(), (m1.adjoint()).eval() * ((s1*m2).conjugate()).eval()); |
| 52 | |
| 53 | |
| 54 | // test all possible conjugate combinations for the four matrix-vector product cases: |
| 55 | |
| 56 | VERIFY_IS_APPROX((-m1.conjugate() * s2) * (s1 * vc2), |
| 57 | (-m1.conjugate()*s2).eval() * (s1 * vc2).eval()); |
| 58 | VERIFY_IS_APPROX((-m1 * s2) * (s1 * vc2.conjugate()), |
| 59 | (-m1*s2).eval() * (s1 * vc2.conjugate()).eval()); |
| 60 | VERIFY_IS_APPROX((-m1.conjugate() * s2) * (s1 * vc2.conjugate()), |
| 61 | (-m1.conjugate()*s2).eval() * (s1 * vc2.conjugate()).eval()); |
| 62 | |
| 63 | VERIFY_IS_APPROX((s1 * vc2.transpose()) * (-m1.adjoint() * s2), |
| 64 | (s1 * vc2.transpose()).eval() * (-m1.adjoint()*s2).eval()); |
| 65 | VERIFY_IS_APPROX((s1 * vc2.adjoint()) * (-m1.transpose() * s2), |
| 66 | (s1 * vc2.adjoint()).eval() * (-m1.transpose()*s2).eval()); |
| 67 | VERIFY_IS_APPROX((s1 * vc2.adjoint()) * (-m1.adjoint() * s2), |
| 68 | (s1 * vc2.adjoint()).eval() * (-m1.adjoint()*s2).eval()); |
| 69 | |