| 65 | }; |
| 66 | |
| 67 | template<typename MatrixType> void adjoint(const MatrixType& m) |
| 68 | { |
| 69 | /* this test covers the following files: |
| 70 | Transpose.h Conjugate.h Dot.h |
| 71 | */ |
| 72 | using std::abs; |
| 73 | typedef typename MatrixType::Index Index; |
| 74 | typedef typename MatrixType::Scalar Scalar; |
| 75 | typedef typename NumTraits<Scalar>::Real RealScalar; |
| 76 | typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType; |
| 77 | typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime> SquareMatrixType; |
| 78 | const Index PacketSize = internal::packet_traits<Scalar>::size; |
| 79 | |
| 80 | Index rows = m.rows(); |
| 81 | Index cols = m.cols(); |
| 82 | |
| 83 | MatrixType m1 = MatrixType::Random(rows, cols), |
| 84 | m2 = MatrixType::Random(rows, cols), |
| 85 | m3(rows, cols), |
| 86 | square = SquareMatrixType::Random(rows, rows); |
| 87 | VectorType v1 = VectorType::Random(rows), |
| 88 | v2 = VectorType::Random(rows), |
| 89 | v3 = VectorType::Random(rows), |
| 90 | vzero = VectorType::Zero(rows); |
| 91 | |
| 92 | Scalar s1 = internal::random<Scalar>(), |
| 93 | s2 = internal::random<Scalar>(); |
| 94 | |
| 95 | // check basic compatibility of adjoint, transpose, conjugate |
| 96 | VERIFY_IS_APPROX(m1.transpose().conjugate().adjoint(), m1); |
| 97 | VERIFY_IS_APPROX(m1.adjoint().conjugate().transpose(), m1); |
| 98 | |
| 99 | // check multiplicative behavior |
| 100 | VERIFY_IS_APPROX((m1.adjoint() * m2).adjoint(), m2.adjoint() * m1); |
| 101 | VERIFY_IS_APPROX((s1 * m1).adjoint(), numext::conj(s1) * m1.adjoint()); |
| 102 | |
| 103 | // check basic properties of dot, squaredNorm |
| 104 | VERIFY_IS_APPROX(numext::conj(v1.dot(v2)), v2.dot(v1)); |
| 105 | VERIFY_IS_APPROX(numext::real(v1.dot(v1)), v1.squaredNorm()); |
| 106 | |
| 107 | adjoint_specific<NumTraits<Scalar>::IsInteger>::run(v1, v2, v3, square, s1, s2); |
| 108 | |
| 109 | VERIFY_IS_MUCH_SMALLER_THAN(abs(vzero.dot(v1)), static_cast<RealScalar>(1)); |
| 110 | |
| 111 | // like in testBasicStuff, test operator() to check const-qualification |
| 112 | Index r = internal::random<Index>(0, rows-1), |
| 113 | c = internal::random<Index>(0, cols-1); |
| 114 | VERIFY_IS_APPROX(m1.conjugate()(r,c), numext::conj(m1(r,c))); |
| 115 | VERIFY_IS_APPROX(m1.adjoint()(c,r), numext::conj(m1(r,c))); |
| 116 | |
| 117 | // check inplace transpose |
| 118 | m3 = m1; |
| 119 | m3.transposeInPlace(); |
| 120 | VERIFY_IS_APPROX(m3,m1.transpose()); |
| 121 | m3.transposeInPlace(); |
| 122 | VERIFY_IS_APPROX(m3,m1); |
| 123 | |
| 124 | if(PacketSize<m3.rows() && PacketSize<m3.cols()) |