aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2009-08-24 13:46:14 -0400
committerGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2009-08-24 13:46:14 -0400
commit191d5275a7c59f1a8bcf590479c337a68543f3ad (patch)
tree1e77beb2a9dc6f396688533dc87e5cbc17ff9b6c /test
parent7e4bd70157465c9ed26dffdffe84e890b05cb975 (diff)
modernize HouseholderQR too, uniformize all that stuff, update tests
Diffstat (limited to 'test')
-rw-r--r--test/qr.cpp25
-rw-r--r--test/qr_colpivoting.cpp10
-rw-r--r--test/qr_fullpivoting.cpp4
3 files changed, 32 insertions, 7 deletions
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<typename MatrixType> 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<typename MatrixType> void qr(const MatrixType& m)
MatrixType a = MatrixType::Random(rows,cols);
HouseholderQR<MatrixType> 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<typename MatrixType> void qr(const MatrixType& m)
template<typename MatrixType> void qr_invertible()
{
- /* this test covers the following files: QR.h */
typedef typename NumTraits<typename MatrixType::Scalar>::Real RealScalar;
+ typedef typename MatrixType::Scalar Scalar;
+
int size = ei_random<int>(10,50);
MatrixType m1(size, size), m2(size, size), m3(size, size);
@@ -75,6 +78,16 @@ template<typename MatrixType> 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<Scalar>();
+ 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<typename MatrixType> void qr_verify_assert()
@@ -82,9 +95,11 @@ template<typename MatrixType> void qr_verify_assert()
MatrixType tmp;
HouseholderQR<MatrixType> 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()
diff --git a/test/qr_colpivoting.cpp b/test/qr_colpivoting.cpp
index d190bce73..283855451 100644
--- a/test/qr_colpivoting.cpp
+++ b/test/qr_colpivoting.cpp
@@ -101,9 +101,17 @@ template<typename MatrixType> void qr_verify_assert()
MatrixType tmp;
ColPivotingHouseholderQR<MatrixType> 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.dimensionOfKernel())
+ VERIFY_RAISES_ASSERT(qr.isInjective())
+ VERIFY_RAISES_ASSERT(qr.isSurjective())
+ VERIFY_RAISES_ASSERT(qr.isInvertible())
+ VERIFY_RAISES_ASSERT(qr.computeInverse(&tmp))
+ VERIFY_RAISES_ASSERT(qr.inverse())
+ VERIFY_RAISES_ASSERT(qr.absDeterminant())
+ VERIFY_RAISES_ASSERT(qr.logAbsDeterminant())
}
void test_qr_colpivoting()
diff --git a/test/qr_fullpivoting.cpp b/test/qr_fullpivoting.cpp
index bdebea7cc..525c669a5 100644
--- a/test/qr_fullpivoting.cpp
+++ b/test/qr_fullpivoting.cpp
@@ -105,7 +105,7 @@ template<typename MatrixType> void qr_verify_assert()
MatrixType tmp;
FullPivotingHouseholderQR<MatrixType> 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.dimensionOfKernel())
@@ -114,6 +114,8 @@ template<typename MatrixType> void qr_verify_assert()
VERIFY_RAISES_ASSERT(qr.isInvertible())
VERIFY_RAISES_ASSERT(qr.computeInverse(&tmp))
VERIFY_RAISES_ASSERT(qr.inverse())
+ VERIFY_RAISES_ASSERT(qr.absDeterminant())
+ VERIFY_RAISES_ASSERT(qr.logAbsDeterminant())
}
void test_qr_fullpivoting()