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 adjoint(const MatrixType& m)
00028 {
00029
00030
00031
00032
00033 typedef typename MatrixType::Scalar Scalar;
00034 typedef typename NumTraits<Scalar>::Real RealScalar;
00035 typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
00036 typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime> SquareMatrixType;
00037 int rows = m.rows();
00038 int cols = m.cols();
00039
00040 RealScalar largerEps = test_precision<RealScalar>();
00041 if (ei_is_same_type<RealScalar,float>::ret)
00042 largerEps = RealScalar(1e-3f);
00043
00044 MatrixType m1 = MatrixType::Random(rows, cols),
00045 m2 = MatrixType::Random(rows, cols),
00046 m3(rows, cols),
00047 mzero = MatrixType::Zero(rows, cols),
00048 identity = SquareMatrixType::Identity(rows, rows),
00049 square = SquareMatrixType::Random(rows, rows);
00050 VectorType v1 = VectorType::Random(rows),
00051 v2 = VectorType::Random(rows),
00052 v3 = VectorType::Random(rows),
00053 vzero = VectorType::Zero(rows);
00054
00055 Scalar s1 = ei_random<Scalar>(),
00056 s2 = ei_random<Scalar>();
00057
00058
00059 VERIFY_IS_APPROX(m1.transpose().conjugate().adjoint(), m1);
00060 VERIFY_IS_APPROX(m1.adjoint().conjugate().transpose(), m1);
00061
00062
00063 VERIFY_IS_APPROX((m1.adjoint() * m2).adjoint(), m2.adjoint() * m1);
00064 VERIFY_IS_APPROX((s1 * m1).adjoint(), ei_conj(s1) * m1.adjoint());
00065
00066
00067 typedef typename NumTraits<Scalar>::Real RealScalar;
00068 VERIFY(ei_isApprox((s1 * v1 + s2 * v2).eigen2_dot(v3), s1 * v1.eigen2_dot(v3) + s2 * v2.eigen2_dot(v3), largerEps));
00069 VERIFY(ei_isApprox(v3.eigen2_dot(s1 * v1 + s2 * v2), ei_conj(s1)*v3.eigen2_dot(v1)+ei_conj(s2)*v3.eigen2_dot(v2), largerEps));
00070 VERIFY_IS_APPROX(ei_conj(v1.eigen2_dot(v2)), v2.eigen2_dot(v1));
00071 VERIFY_IS_APPROX(ei_real(v1.eigen2_dot(v1)), v1.squaredNorm());
00072 if(NumTraits<Scalar>::HasFloatingPoint)
00073 VERIFY_IS_APPROX(v1.squaredNorm(), v1.norm() * v1.norm());
00074 VERIFY_IS_MUCH_SMALLER_THAN(ei_abs(vzero.eigen2_dot(v1)), static_cast<RealScalar>(1));
00075 if(NumTraits<Scalar>::HasFloatingPoint)
00076 VERIFY_IS_MUCH_SMALLER_THAN(vzero.norm(), static_cast<RealScalar>(1));
00077
00078
00079 VERIFY(ei_isApprox(v1.eigen2_dot(square * v2), (square.adjoint() * v1).eigen2_dot(v2), largerEps));
00080
00081
00082 int r = ei_random<int>(0, rows-1),
00083 c = ei_random<int>(0, cols-1);
00084 VERIFY_IS_APPROX(m1.conjugate()(r,c), ei_conj(m1(r,c)));
00085 VERIFY_IS_APPROX(m1.adjoint()(c,r), ei_conj(m1(r,c)));
00086
00087 if(NumTraits<Scalar>::HasFloatingPoint)
00088 {
00089
00090
00091 VERIFY_IS_APPROX(VectorType::Random(rows).normalized().norm(), RealScalar(1));
00092 }
00093
00094
00095 m3 = m1;
00096 m3.transposeInPlace();
00097 VERIFY_IS_APPROX(m3,m1.transpose());
00098 m3.transposeInPlace();
00099 VERIFY_IS_APPROX(m3,m1);
00100
00101 }
00102
00103 void test_eigen2_adjoint()
00104 {
00105 for(int i = 0; i < g_repeat; i++) {
00106 CALL_SUBTEST_1( adjoint(Matrix<float, 1, 1>()) );
00107 CALL_SUBTEST_2( adjoint(Matrix3d()) );
00108 CALL_SUBTEST_3( adjoint(Matrix4f()) );
00109 CALL_SUBTEST_4( adjoint(MatrixXcf(4, 4)) );
00110 CALL_SUBTEST_5( adjoint(MatrixXi(8, 12)) );
00111 CALL_SUBTEST_6( adjoint(MatrixXf(21, 21)) );
00112 }
00113
00114 CALL_SUBTEST_7( adjoint(Matrix<float, 100, 100>()) );
00115 }
00116