From 191d5275a7c59f1a8bcf590479c337a68543f3ad Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Mon, 24 Aug 2009 13:46:14 -0400 Subject: modernize HouseholderQR too, uniformize all that stuff, update tests --- test/qr.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'test/qr.cpp') diff --git a/test/qr.cpp b/test/qr.cpp index f004a36ca..f2e2eda61 100644 --- a/test/qr.cpp +++ b/test/qr.cpp @@ -27,7 +27,6 @@ template void qr(const MatrixType& m) { - /* this test covers the following files: QR.h */ int rows = m.rows(); int cols = m.cols(); @@ -37,8 +36,11 @@ template void qr(const MatrixType& m) MatrixType a = MatrixType::Random(rows,cols); HouseholderQR qrOfA(a); - VERIFY_IS_APPROX(a, qrOfA.matrixQ() * qrOfA.matrixR().toDense()); - VERIFY_IS_NOT_APPROX(a+MatrixType::Identity(rows, cols), qrOfA.matrixQ() * qrOfA.matrixR().toDense()); + MatrixType r = qrOfA.matrixQR(); + // FIXME need better way to construct trapezoid + for(int i = 0; i < rows; i++) for(int j = 0; j < cols; j++) if(i>j) r(i,j) = Scalar(0); + + VERIFY_IS_APPROX(a, qrOfA.matrixQ() * r); SquareMatrixType b = a.adjoint() * a; @@ -57,8 +59,9 @@ template void qr(const MatrixType& m) template void qr_invertible() { - /* this test covers the following files: QR.h */ typedef typename NumTraits::Real RealScalar; + typedef typename MatrixType::Scalar Scalar; + int size = ei_random(10,50); MatrixType m1(size, size), m2(size, size), m3(size, size); @@ -75,6 +78,16 @@ template void qr_invertible() m3 = MatrixType::Random(size,size); qr.solve(m3, &m2); VERIFY_IS_APPROX(m3, m1*m2); + + // now construct a matrix with prescribed determinant + m1.setZero(); + for(int i = 0; i < size; i++) m1(i,i) = ei_random(); + RealScalar absdet = ei_abs(m1.diagonal().prod()); + m3 = qr.matrixQ(); // get a unitary + m1 = m3 * m1 * m3; + qr.compute(m1); + VERIFY_IS_APPROX(absdet, qr.absDeterminant()); + VERIFY_IS_APPROX(ei_log(absdet), qr.logAbsDeterminant()); } template void qr_verify_assert() @@ -82,9 +95,11 @@ template void qr_verify_assert() MatrixType tmp; HouseholderQR qr; - VERIFY_RAISES_ASSERT(qr.matrixR()) + VERIFY_RAISES_ASSERT(qr.matrixQR()) VERIFY_RAISES_ASSERT(qr.solve(tmp,&tmp)) VERIFY_RAISES_ASSERT(qr.matrixQ()) + VERIFY_RAISES_ASSERT(qr.absDeterminant()) + VERIFY_RAISES_ASSERT(qr.logAbsDeterminant()) } void test_qr() -- cgit v1.2.3