aboutsummaryrefslogtreecommitdiff
path: root/test/qr_fullpivoting.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/qr_fullpivoting.cpp')
-rw-r--r--test/qr_fullpivoting.cpp34
1 files changed, 28 insertions, 6 deletions
diff --git a/test/qr_fullpivoting.cpp b/test/qr_fullpivoting.cpp
index 511f2473f..70e89c198 100644
--- a/test/qr_fullpivoting.cpp
+++ b/test/qr_fullpivoting.cpp
@@ -15,16 +15,20 @@ template<typename MatrixType> void qr()
{
typedef typename MatrixType::Index Index;
- Index rows = internal::random<Index>(20,200), cols = internal::random<int>(20,200), cols2 = internal::random<int>(20,200);
- Index rank = internal::random<Index>(1, (std::min)(rows, cols)-1);
+ Index max_size = EIGEN_TEST_MAX_SIZE;
+ Index min_size = numext::maxi(1,EIGEN_TEST_MAX_SIZE/10);
+ Index rows = internal::random<Index>(min_size,max_size),
+ cols = internal::random<Index>(min_size,max_size),
+ cols2 = internal::random<Index>(min_size,max_size),
+ rank = internal::random<Index>(1, (std::min)(rows, cols)-1);
typedef typename MatrixType::Scalar Scalar;
typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime> MatrixQType;
MatrixType m1;
createRandomPIMatrixOfRank(rank,rows,cols,m1);
FullPivHouseholderQR<MatrixType> qr(m1);
- VERIFY(rank == qr.rank());
- VERIFY(cols - qr.rank() == qr.dimensionOfKernel());
+ VERIFY_IS_EQUAL(rank, qr.rank());
+ VERIFY_IS_EQUAL(cols - qr.rank(), qr.dimensionOfKernel());
VERIFY(!qr.isInjective());
VERIFY(!qr.isInvertible());
VERIFY(!qr.isSurjective());
@@ -40,12 +44,28 @@ template<typename MatrixType> void qr()
MatrixType c = qr.matrixQ() * r * qr.colsPermutation().inverse();
VERIFY_IS_APPROX(m1, c);
-
+
+ // stress the ReturnByValue mechanism
+ MatrixType tmp;
+ VERIFY_IS_APPROX(tmp.noalias() = qr.matrixQ() * r, (qr.matrixQ() * r).eval());
+
MatrixType m2 = MatrixType::Random(cols,cols2);
MatrixType m3 = m1*m2;
m2 = MatrixType::Random(cols,cols2);
m2 = qr.solve(m3);
VERIFY_IS_APPROX(m3, m1*m2);
+
+ {
+ Index size = rows;
+ do {
+ m1 = MatrixType::Random(size,size);
+ qr.compute(m1);
+ } while(!qr.isInvertible());
+ MatrixType m1_inv = qr.inverse();
+ m3 = m1 * MatrixType::Random(size,cols2);
+ m2 = qr.solve(m3);
+ VERIFY_IS_APPROX(m2, m1_inv*m3);
+ }
}
template<typename MatrixType> void qr_invertible()
@@ -55,7 +75,9 @@ template<typename MatrixType> void qr_invertible()
typedef typename NumTraits<typename MatrixType::Scalar>::Real RealScalar;
typedef typename MatrixType::Scalar Scalar;
- int size = internal::random<int>(10,50);
+ Index max_size = numext::mini(50,EIGEN_TEST_MAX_SIZE);
+ Index min_size = numext::maxi(1,EIGEN_TEST_MAX_SIZE/10);
+ Index size = internal::random<Index>(min_size,max_size);
MatrixType m1(size, size), m2(size, size), m3(size, size);
m1 = MatrixType::Random(size,size);