aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/qr.cpp
diff options
context:
space:
mode:
authorGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2009-09-28 10:49:55 -0400
committerGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2009-09-28 10:49:55 -0400
commiteeabd18afc5fca290612aada629a294f85d9d353 (patch)
treef34a66f06bd69c856bc66d83e6d20b114724e8dd /test/qr.cpp
parent67bf7c90c5c41d8b62411c298d657908537118ea (diff)
Fix compilation of HouseholderQR and ColPivotingHouseholderQR for non-square fixed-size matrices.
For Colpiv that was just changing MatrixQType to MatrixType in the instantiation of HouseholderSequence. For HouseholderQR I also re-ported the solve method from Colpiv as there were multiple issues.
Diffstat (limited to 'test/qr.cpp')
-rw-r--r--test/qr.cpp38
1 files changed, 22 insertions, 16 deletions
diff --git a/test/qr.cpp b/test/qr.cpp
index f185ac86e..036a3c9f2 100644
--- a/test/qr.cpp
+++ b/test/qr.cpp
@@ -41,20 +41,26 @@ template<typename MatrixType> void qr(const MatrixType& m)
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;
+template<typename MatrixType, int Cols2> void qr_fixedsize()
+{
+ enum { Rows = MatrixType::RowsAtCompileTime, Cols = MatrixType::ColsAtCompileTime };
+ typedef typename MatrixType::Scalar Scalar;
+ Matrix<Scalar,Rows,Cols> m1 = Matrix<Scalar,Rows,Cols>::Random();
+ HouseholderQR<Matrix<Scalar,Rows,Cols> > qr(m1);
- // check tridiagonalization
- Tridiagonalization<SquareMatrixType> tridiag(b);
- VERIFY_IS_APPROX(b, tridiag.matrixQ() * tridiag.matrixT() * tridiag.matrixQ().adjoint());
+ Matrix<Scalar,Rows,Cols> r = qr.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);
- // check hessenberg decomposition
- HessenbergDecomposition<SquareMatrixType> hess(b);
- VERIFY_IS_APPROX(b, hess.matrixQ() * hess.matrixH() * hess.matrixQ().adjoint());
- VERIFY_IS_APPROX(tridiag.matrixT(), hess.matrixH());
- b = SquareMatrixType::Random(cols,cols);
- hess.compute(b);
- VERIFY_IS_APPROX(b, hess.matrixQ() * hess.matrixH() * hess.matrixQ().adjoint());
+ VERIFY_IS_APPROX(m1, qr.matrixQ() * r);
+
+ Matrix<Scalar,Cols,Cols2> m2 = Matrix<Scalar,Cols,Cols2>::Random(Cols,Cols2);
+ Matrix<Scalar,Rows,Cols2> m3 = m1*m2;
+ m2 = Matrix<Scalar,Cols,Cols2>::Random(Cols,Cols2);
+ qr.solve(m3, &m2);
+ VERIFY_IS_APPROX(m3, m1*m2);
}
template<typename MatrixType> void qr_invertible()
@@ -105,11 +111,11 @@ template<typename MatrixType> void qr_verify_assert()
void test_qr()
{
for(int i = 0; i < 1; i++) {
- // FIXME : very weird bug here
-// CALL_SUBTEST( qr(Matrix2f()) );
- CALL_SUBTEST( qr(Matrix4d()) );
- CALL_SUBTEST( qr(MatrixXf(47,40)) );
- CALL_SUBTEST( qr(MatrixXcd(17,7)) );
+ CALL_SUBTEST( qr(MatrixXf(47,40)) );
+ CALL_SUBTEST( qr(MatrixXcd(17,7)) );
+ CALL_SUBTEST(( qr_fixedsize<Matrix<float,3,4>, 2 >() ));
+ CALL_SUBTEST(( qr_fixedsize<Matrix<double,6,2>, 4 >() ));
+ CALL_SUBTEST(( qr_fixedsize<Matrix<double,2,5>, 7 >() ));
}
for(int i = 0; i < g_repeat; i++) {