From 9a700c297490024bd94edfcd73f14c8a984705c9 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Mon, 19 Oct 2009 10:56:37 -0400 Subject: * LU unit test: finally test fixed sizes * ReturnByValue: after all don't eval to temporary for generic MatrixBase impl --- test/lu.cpp | 50 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 10 deletions(-) (limited to 'test/lu.cpp') diff --git a/test/lu.cpp b/test/lu.cpp index a08614e28..90755f59c 100644 --- a/test/lu.cpp +++ b/test/lu.cpp @@ -30,15 +30,43 @@ template void lu_non_invertible() /* this test covers the following files: LU.h */ - int rows = ei_random(20,200), cols = ei_random(20,200), cols2 = ei_random(20,200); + int rows, cols, cols2; + if(MatrixType::RowsAtCompileTime==Dynamic) + { + rows = ei_random(20,200); + } + else + { + rows = MatrixType::RowsAtCompileTime; + } + if(MatrixType::ColsAtCompileTime==Dynamic) + { + cols = ei_random(20,200); + cols2 = ei_random(20,200); + } + else + { + cols2 = cols = MatrixType::ColsAtCompileTime; + } + + typedef typename ei_lu_kernel_impl::ReturnMatrixType KernelMatrixType; + typedef typename ei_lu_image_impl ::ReturnMatrixType ImageMatrixType; + typedef Matrix DynamicMatrixType; + typedef Matrix + CMatrixType; + int rank = ei_random(1, std::min(rows, cols)-1); - MatrixType m1(rows, cols), m2(cols, cols2), m3(rows, cols2), k(1,1); + // The image of the zero matrix should consist of a single (zero) column vector + VERIFY((MatrixType::Zero(rows,cols).lu().image(MatrixType::Zero(rows,cols)).cols() == 1)); + + MatrixType m1(rows, cols), m3(rows, cols2); + CMatrixType m2(cols, cols2); createRandomMatrixOfRank(rank, rows, cols, m1); LU lu(m1); - typename ei_lu_kernel_impl::ReturnMatrixType m1kernel = lu.kernel(); - typename ei_lu_image_impl ::ReturnMatrixType m1image = lu.image(m1); + KernelMatrixType m1kernel = lu.kernel(); + ImageMatrixType m1image = lu.image(m1); // std::cerr << rank << " " << lu.rank() << std::endl; VERIFY(rank == lu.rank()); @@ -48,19 +76,18 @@ template void lu_non_invertible() VERIFY(!lu.isSurjective()); VERIFY((m1 * m1kernel).isMuchSmallerThan(m1)); VERIFY(m1image.lu().rank() == rank); - MatrixType sidebyside(m1.rows(), m1.cols() + m1image.cols()); + DynamicMatrixType sidebyside(m1.rows(), m1.cols() + m1image.cols()); sidebyside << m1, m1image; VERIFY(sidebyside.lu().rank() == rank); - m2 = MatrixType::Random(cols,cols2); + m2 = CMatrixType::Random(cols,cols2); m3 = m1*m2; - m2 = MatrixType::Random(cols,cols2); + m2 = CMatrixType::Random(cols,cols2); // test that the code, which does resize(), may be applied to an xpr m2.block(0,0,m2.rows(),m2.cols()) = lu.solve(m3); VERIFY_IS_APPROX(m3, m1*m2); - typedef Matrix SquareMatrixType; - SquareMatrixType m4(rows, rows), m5(rows, rows); - createRandomMatrixOfRank(rows/2, rows, rows, m4); + CMatrixType m4(cols, cols), m5(cols, cols); + createRandomMatrixOfRank(cols/2, cols, cols, m4); VERIFY(!m4.computeInverseWithCheck(&m5)); } @@ -84,6 +111,7 @@ template void lu_invertible() LU lu(m1); VERIFY(0 == lu.dimensionOfKernel()); + VERIFY(lu.kernel().cols() == 1); // the kernel() should consist of a single (zero) column vector VERIFY(size == lu.rank()); VERIFY(lu.isInjective()); VERIFY(lu.isSurjective()); @@ -125,6 +153,8 @@ template void lu_verify_assert() void test_lu() { for(int i = 0; i < g_repeat; i++) { + CALL_SUBTEST( lu_non_invertible() ); + CALL_SUBTEST( (lu_non_invertible >()) ); CALL_SUBTEST( lu_non_invertible() ); CALL_SUBTEST( lu_non_invertible() ); CALL_SUBTEST( lu_non_invertible() ); -- cgit v1.2.3