mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
big huge changes, so i dont remember everything.
* renaming, e.g. LU ---> FullPivLU * split tests framework: more robust, e.g. dont generate empty tests if a number is skipped * make all remaining tests use that splitting, as needed. * Fix 4x4 inversion (see stable branch) * Transform::inverse() and geo_transform test : adapt to new inverse() API, it was also trying to instantiate inverse() for 3x4 matrices. * CMakeLists: more robust regexp to parse the version number * misc fixes in unit tests
This commit is contained in:
54
test/lu.cpp
54
test/lu.cpp
@@ -58,13 +58,13 @@ template<typename MatrixType> void lu_non_invertible()
|
||||
int rank = ei_random<int>(1, std::min(rows, cols)-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));
|
||||
VERIFY((MatrixType::Zero(rows,cols).fullPivLu().image(MatrixType::Zero(rows,cols)).cols() == 1));
|
||||
|
||||
MatrixType m1(rows, cols), m3(rows, cols2);
|
||||
CMatrixType m2(cols, cols2);
|
||||
createRandomMatrixOfRank(rank, rows, cols, m1);
|
||||
|
||||
LU<MatrixType> lu(m1);
|
||||
FullPivLU<MatrixType> lu(m1);
|
||||
KernelMatrixType m1kernel = lu.kernel();
|
||||
ImageMatrixType m1image = lu.image(m1);
|
||||
|
||||
@@ -75,20 +75,16 @@ template<typename MatrixType> void lu_non_invertible()
|
||||
VERIFY(!lu.isInvertible());
|
||||
VERIFY(!lu.isSurjective());
|
||||
VERIFY((m1 * m1kernel).isMuchSmallerThan(m1));
|
||||
VERIFY(m1image.lu().rank() == rank);
|
||||
VERIFY(m1image.fullPivLu().rank() == rank);
|
||||
DynamicMatrixType sidebyside(m1.rows(), m1.cols() + m1image.cols());
|
||||
sidebyside << m1, m1image;
|
||||
VERIFY(sidebyside.lu().rank() == rank);
|
||||
VERIFY(sidebyside.fullPivLu().rank() == rank);
|
||||
m2 = CMatrixType::Random(cols,cols2);
|
||||
m3 = m1*m2;
|
||||
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);
|
||||
|
||||
CMatrixType m4(cols, cols), m5(cols, cols);
|
||||
createRandomMatrixOfRank(cols/2, cols, cols, m4);
|
||||
VERIFY(!m4.computeInverseWithCheck(&m5));
|
||||
}
|
||||
|
||||
template<typename MatrixType> void lu_invertible()
|
||||
@@ -109,14 +105,14 @@ template<typename MatrixType> void lu_invertible()
|
||||
m1 += a * a.adjoint();
|
||||
}
|
||||
|
||||
LU<MatrixType> lu(m1);
|
||||
FullPivLU<MatrixType> 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());
|
||||
VERIFY(lu.isInvertible());
|
||||
VERIFY(lu.image(m1).lu().isInvertible());
|
||||
VERIFY(lu.image(m1).fullPivLu().isInvertible());
|
||||
m3 = MatrixType::Random(size,size);
|
||||
m2 = lu.solve(m3);
|
||||
VERIFY_IS_APPROX(m3, m1*m2);
|
||||
@@ -127,7 +123,7 @@ template<typename MatrixType> void lu_verify_assert()
|
||||
{
|
||||
MatrixType tmp;
|
||||
|
||||
LU<MatrixType> lu;
|
||||
FullPivLU<MatrixType> lu;
|
||||
VERIFY_RAISES_ASSERT(lu.matrixLU())
|
||||
VERIFY_RAISES_ASSERT(lu.permutationP())
|
||||
VERIFY_RAISES_ASSERT(lu.permutationQ())
|
||||
@@ -142,10 +138,10 @@ template<typename MatrixType> void lu_verify_assert()
|
||||
VERIFY_RAISES_ASSERT(lu.isInvertible())
|
||||
VERIFY_RAISES_ASSERT(lu.inverse())
|
||||
|
||||
PartialLU<MatrixType> plu;
|
||||
PartialPivLU<MatrixType> plu;
|
||||
VERIFY_RAISES_ASSERT(plu.matrixLU())
|
||||
VERIFY_RAISES_ASSERT(plu.permutationP())
|
||||
VERIFY_RAISES_ASSERT(plu.solve(tmp,&tmp))
|
||||
VERIFY_RAISES_ASSERT(plu.solve(tmp))
|
||||
VERIFY_RAISES_ASSERT(plu.determinant())
|
||||
VERIFY_RAISES_ASSERT(plu.inverse())
|
||||
}
|
||||
@@ -153,26 +149,26 @@ template<typename MatrixType> void lu_verify_assert()
|
||||
void test_lu()
|
||||
{
|
||||
for(int i = 0; i < g_repeat; i++) {
|
||||
CALL_SUBTEST1( lu_non_invertible<Matrix3f>() );
|
||||
CALL_SUBTEST1( lu_verify_assert<Matrix3f>() );
|
||||
CALL_SUBTEST_1( lu_non_invertible<Matrix3f>() );
|
||||
CALL_SUBTEST_1( lu_verify_assert<Matrix3f>() );
|
||||
|
||||
CALL_SUBTEST2( (lu_non_invertible<Matrix<double, 4, 6> >()) );
|
||||
CALL_SUBTEST2( (lu_verify_assert<Matrix<double, 4, 6> >()) );
|
||||
CALL_SUBTEST_2( (lu_non_invertible<Matrix<double, 4, 6> >()) );
|
||||
CALL_SUBTEST_2( (lu_verify_assert<Matrix<double, 4, 6> >()) );
|
||||
|
||||
CALL_SUBTEST3( lu_non_invertible<MatrixXf>() );
|
||||
CALL_SUBTEST3( lu_invertible<MatrixXf>() );
|
||||
CALL_SUBTEST3( lu_verify_assert<MatrixXf>() );
|
||||
CALL_SUBTEST_3( lu_non_invertible<MatrixXf>() );
|
||||
CALL_SUBTEST_3( lu_invertible<MatrixXf>() );
|
||||
CALL_SUBTEST_3( lu_verify_assert<MatrixXf>() );
|
||||
|
||||
CALL_SUBTEST4( lu_non_invertible<MatrixXd>() );
|
||||
CALL_SUBTEST4( lu_invertible<MatrixXd>() );
|
||||
CALL_SUBTEST4( lu_verify_assert<MatrixXd>() );
|
||||
CALL_SUBTEST_4( lu_non_invertible<MatrixXd>() );
|
||||
CALL_SUBTEST_4( lu_invertible<MatrixXd>() );
|
||||
CALL_SUBTEST_4( lu_verify_assert<MatrixXd>() );
|
||||
|
||||
CALL_SUBTEST5( lu_non_invertible<MatrixXcf>() );
|
||||
CALL_SUBTEST5( lu_invertible<MatrixXcf>() );
|
||||
CALL_SUBTEST5( lu_verify_assert<MatrixXcf>() );
|
||||
CALL_SUBTEST_5( lu_non_invertible<MatrixXcf>() );
|
||||
CALL_SUBTEST_5( lu_invertible<MatrixXcf>() );
|
||||
CALL_SUBTEST_5( lu_verify_assert<MatrixXcf>() );
|
||||
|
||||
CALL_SUBTEST6( lu_non_invertible<MatrixXcd>() );
|
||||
CALL_SUBTEST6( lu_invertible<MatrixXcd>() );
|
||||
CALL_SUBTEST6( lu_verify_assert<MatrixXcd>() );
|
||||
CALL_SUBTEST_6( lu_non_invertible<MatrixXcd>() );
|
||||
CALL_SUBTEST_6( lu_invertible<MatrixXcd>() );
|
||||
CALL_SUBTEST_6( lu_verify_assert<MatrixXcd>() );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user