mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-11 11:19:02 +08:00
also test that the matrix Q is unitary
This commit is contained in:
parent
e5bf72679c
commit
c4ab6a2032
@ -31,12 +31,16 @@ template<typename MatrixType> void qr(const MatrixType& m)
|
|||||||
int cols = m.cols();
|
int cols = m.cols();
|
||||||
|
|
||||||
typedef typename MatrixType::Scalar Scalar;
|
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;
|
typedef Matrix<Scalar, MatrixType::ColsAtCompileTime, 1> VectorType;
|
||||||
|
|
||||||
MatrixType a = MatrixType::Random(rows,cols);
|
MatrixType a = MatrixType::Random(rows,cols);
|
||||||
HouseholderQR<MatrixType> qrOfA(a);
|
HouseholderQR<MatrixType> qrOfA(a);
|
||||||
MatrixType r = qrOfA.matrixQR();
|
MatrixType r = qrOfA.matrixQR();
|
||||||
|
|
||||||
|
MatrixQType q = qrOfA.matrixQ();
|
||||||
|
VERIFY_IS_UNITARY(q);
|
||||||
|
|
||||||
// FIXME need better way to construct trapezoid
|
// 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);
|
for(int i = 0; i < rows; i++) for(int j = 0; j < cols; j++) if(i>j) r(i,j) = Scalar(0);
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ template<typename MatrixType> void qr()
|
|||||||
int rank = ei_random<int>(1, std::min(rows, cols)-1);
|
int rank = ei_random<int>(1, std::min(rows, cols)-1);
|
||||||
|
|
||||||
typedef typename MatrixType::Scalar Scalar;
|
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;
|
typedef Matrix<Scalar, MatrixType::ColsAtCompileTime, 1> VectorType;
|
||||||
MatrixType m1;
|
MatrixType m1;
|
||||||
createRandomMatrixOfRank(rank,rows,cols,m1);
|
createRandomMatrixOfRank(rank,rows,cols,m1);
|
||||||
@ -44,6 +44,10 @@ template<typename MatrixType> void qr()
|
|||||||
VERIFY(!qr.isSurjective());
|
VERIFY(!qr.isSurjective());
|
||||||
|
|
||||||
MatrixType r = qr.matrixQR();
|
MatrixType r = qr.matrixQR();
|
||||||
|
|
||||||
|
MatrixQType q = qr.matrixQ();
|
||||||
|
VERIFY_IS_UNITARY(q);
|
||||||
|
|
||||||
// FIXME need better way to construct trapezoid
|
// 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);
|
for(int i = 0; i < rows; i++) for(int j = 0; j < cols; j++) if(i>j) r(i,j) = Scalar(0);
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ template<typename MatrixType> void qr()
|
|||||||
int rank = ei_random<int>(1, std::min(rows, cols)-1);
|
int rank = ei_random<int>(1, std::min(rows, cols)-1);
|
||||||
|
|
||||||
typedef typename MatrixType::Scalar Scalar;
|
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;
|
typedef Matrix<Scalar, MatrixType::ColsAtCompileTime, 1> VectorType;
|
||||||
MatrixType m1;
|
MatrixType m1;
|
||||||
createRandomMatrixOfRank(rank,rows,cols,m1);
|
createRandomMatrixOfRank(rank,rows,cols,m1);
|
||||||
@ -44,6 +44,10 @@ template<typename MatrixType> void qr()
|
|||||||
VERIFY(!qr.isSurjective());
|
VERIFY(!qr.isSurjective());
|
||||||
|
|
||||||
MatrixType r = qr.matrixQR();
|
MatrixType r = qr.matrixQR();
|
||||||
|
|
||||||
|
MatrixQType q = qr.matrixQ();
|
||||||
|
VERIFY_IS_UNITARY(q);
|
||||||
|
|
||||||
// FIXME need better way to construct trapezoid
|
// 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);
|
for(int i = 0; i < rows; i++) for(int j = 0; j < cols; j++) if(i>j) r(i,j) = Scalar(0);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user