From 2120fed849e1d00724694a2c8a041ec5561c750b Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Sat, 23 Aug 2008 15:14:20 +0000 Subject: * bug fixes in: Dot, generalized eigen problem, singular matrix detetection in Cholesky * fix all numerical instabilies in the unit tests, now all tests can be run 2000 times with almost zero failures. --- test/adjoint.cpp | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) (limited to 'test/adjoint.cpp') diff --git a/test/adjoint.cpp b/test/adjoint.cpp index 50ebb70dc..982584eea 100644 --- a/test/adjoint.cpp +++ b/test/adjoint.cpp @@ -31,25 +31,29 @@ template void adjoint(const MatrixType& m) */ typedef typename MatrixType::Scalar Scalar; + typedef typename NumTraits::Real RealScalar; typedef Matrix VectorType; + typedef Matrix SquareMatrixType; int rows = m.rows(); int cols = m.cols(); - MatrixType m1 = MatrixType::Random(rows, cols), - m2 = MatrixType::Random(rows, cols), + RealScalar largerEps = test_precision(); + if (ei_is_same_type::ret) + largerEps = 1e-3f; + + MatrixType m1 = test_random_matrix(rows, cols), + m2 = test_random_matrix(rows, cols), m3(rows, cols), mzero = MatrixType::Zero(rows, cols), - identity = Matrix - ::Identity(rows, rows), - square = Matrix - ::Random(rows, rows); - VectorType v1 = VectorType::Random(rows), - v2 = VectorType::Random(rows), - v3 = VectorType::Random(rows), + identity = SquareMatrixType::Identity(rows, rows), + square = test_random_matrix(rows, rows); + VectorType v1 = test_random_matrix(rows), + v2 = test_random_matrix(rows), + v3 = test_random_matrix(rows), vzero = VectorType::Zero(rows); - Scalar s1 = ei_random(), - s2 = ei_random(); + Scalar s1 = test_random(), + s2 = test_random(); // check basic compatibility of adjoint, transpose, conjugate VERIFY_IS_APPROX(m1.transpose().conjugate().adjoint(), m1); @@ -61,19 +65,18 @@ template void adjoint(const MatrixType& m) // check basic properties of dot, norm, norm2 typedef typename NumTraits::Real RealScalar; - VERIFY_IS_APPROX((s1 * v1 + s2 * v2).dot(v3), s1 * v1.dot(v3) + s2 * v2.dot(v3)); - VERIFY_IS_APPROX(v3.dot(s1 * v1 + s2 * v2), ei_conj(s1)*v3.dot(v1)+ei_conj(s2)*v3.dot(v2)); - VERIFY_IS_APPROX(ei_conj(v1.dot(v2)), v2.dot(v1)); - VERIFY_IS_APPROX(ei_abs(v1.dot(v1)), v1.norm2()); + VERIFY(ei_isApprox((s1 * v1 + s2 * v2).dot(v3), s1 * v1.dot(v3) + s2 * v2.dot(v3), largerEps)); + VERIFY(ei_isApprox(v3.dot(s1 * v1 + s2 * v2), ei_conj(s1)*v3.dot(v1)+ei_conj(s2)*v3.dot(v2), largerEps)); + VERIFY_IS_APPROX(ei_conj(v1.dot(v2)), v2.dot(v1)); + VERIFY_IS_APPROX(ei_abs(v1.dot(v1)), v1.norm2()); if(NumTraits::HasFloatingPoint) - VERIFY_IS_APPROX(v1.norm2(), v1.norm() * v1.norm()); - VERIFY_IS_MUCH_SMALLER_THAN(ei_abs(vzero.dot(v1)), static_cast(1)); + VERIFY_IS_APPROX(v1.norm2(), v1.norm() * v1.norm()); + VERIFY_IS_MUCH_SMALLER_THAN(ei_abs(vzero.dot(v1)), static_cast(1)); if(NumTraits::HasFloatingPoint) - VERIFY_IS_MUCH_SMALLER_THAN(vzero.norm(), static_cast(1)); + VERIFY_IS_MUCH_SMALLER_THAN(vzero.norm(), static_cast(1)); // check compatibility of dot and adjoint - // FIXME this line failed with MSVC and complex in the ei_aligned_free() - VERIFY_IS_APPROX(v1.dot(square * v2), (square.adjoint() * v1).dot(v2)); + VERIFY(ei_isApprox(v1.dot(square * v2), (square.adjoint() * v1).dot(v2), largerEps)); // like in testBasicStuff, test operator() to check const-qualification int r = ei_random(0, rows-1), @@ -93,10 +96,11 @@ void test_adjoint() { for(int i = 0; i < g_repeat; i++) { CALL_SUBTEST( adjoint(Matrix()) ); - CALL_SUBTEST( adjoint(Matrix4d()) ); - CALL_SUBTEST( adjoint(MatrixXcf(3, 3)) ); + CALL_SUBTEST( adjoint(Matrix3d()) ); + CALL_SUBTEST( adjoint(Matrix4f()) ); + CALL_SUBTEST( adjoint(MatrixXcf(4, 4)) ); CALL_SUBTEST( adjoint(MatrixXi(8, 12)) ); - CALL_SUBTEST( adjoint(MatrixXcd(20, 20)) ); + CALL_SUBTEST( adjoint(MatrixXf(21, 21)) ); } // test a large matrix only once CALL_SUBTEST( adjoint(Matrix()) ); -- cgit v1.2.3