aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2009-10-12 22:33:51 -0400
committerGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2009-10-12 22:33:51 -0400
commitc4ab6a2032895957e0e8dbea564b0c9c7f88b48a (patch)
treecef64758138c2da22644ac64c263a4d70b4c3e3a
parente5bf72679c993e302df95aa2947402482aaded71 (diff)
also test that the matrix Q is unitary
-rw-r--r--test/qr.cpp6
-rw-r--r--test/qr_colpivoting.cpp6
-rw-r--r--test/qr_fullpivoting.cpp6
3 files changed, 15 insertions, 3 deletions
diff --git a/test/qr.cpp b/test/qr.cpp
index 036a3c9f2..864828750 100644
--- a/test/qr.cpp
+++ b/test/qr.cpp
@@ -31,12 +31,16 @@ template<typename MatrixType> void qr(const MatrixType& m)
int cols = m.cols();
typedef typename MatrixType::Scalar Scalar;
- typedef Matrix<Scalar, MatrixType::ColsAtCompileTime, MatrixType::ColsAtCompileTime> SquareMatrixType;
+ typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime> MatrixQType;
typedef Matrix<Scalar, MatrixType::ColsAtCompileTime, 1> VectorType;
MatrixType a = MatrixType::Random(rows,cols);
HouseholderQR<MatrixType> qrOfA(a);
MatrixType r = qrOfA.matrixQR();
+
+ MatrixQType q = qrOfA.matrixQ();
+ VERIFY_IS_UNITARY(q);
+
// 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);
diff --git a/test/qr_colpivoting.cpp b/test/qr_colpivoting.cpp
index 4b6f7dd6b..5c5c5d259 100644
--- a/test/qr_colpivoting.cpp
+++ b/test/qr_colpivoting.cpp
@@ -32,7 +32,7 @@ template<typename MatrixType> void qr()
int rank = ei_random<int>(1, std::min(rows, cols)-1);
typedef typename MatrixType::Scalar Scalar;
- typedef Matrix<Scalar, MatrixType::ColsAtCompileTime, MatrixType::ColsAtCompileTime> SquareMatrixType;
+ typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime> MatrixQType;
typedef Matrix<Scalar, MatrixType::ColsAtCompileTime, 1> VectorType;
MatrixType m1;
createRandomMatrixOfRank(rank,rows,cols,m1);
@@ -44,6 +44,10 @@ template<typename MatrixType> void qr()
VERIFY(!qr.isSurjective());
MatrixType r = qr.matrixQR();
+
+ MatrixQType q = qr.matrixQ();
+ VERIFY_IS_UNITARY(q);
+
// 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);
diff --git a/test/qr_fullpivoting.cpp b/test/qr_fullpivoting.cpp
index 3a37bcb46..891c2a527 100644
--- a/test/qr_fullpivoting.cpp
+++ b/test/qr_fullpivoting.cpp
@@ -32,7 +32,7 @@ template<typename MatrixType> void qr()
int rank = ei_random<int>(1, std::min(rows, cols)-1);
typedef typename MatrixType::Scalar Scalar;
- typedef Matrix<Scalar, MatrixType::ColsAtCompileTime, MatrixType::ColsAtCompileTime> SquareMatrixType;
+ typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime> MatrixQType;
typedef Matrix<Scalar, MatrixType::ColsAtCompileTime, 1> VectorType;
MatrixType m1;
createRandomMatrixOfRank(rank,rows,cols,m1);
@@ -44,6 +44,10 @@ template<typename MatrixType> void qr()
VERIFY(!qr.isSurjective());
MatrixType r = qr.matrixQR();
+
+ MatrixQType q = qr.matrixQ();
+ VERIFY_IS_UNITARY(q);
+
// 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);