From 44861dcbfeee041223c4aac1ee075e92fa4daa01 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 18 Sep 2016 12:42:15 +0200 Subject: update --- eigen/test/eigen2/eigen2_qr.cpp | 69 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 eigen/test/eigen2/eigen2_qr.cpp (limited to 'eigen/test/eigen2/eigen2_qr.cpp') diff --git a/eigen/test/eigen2/eigen2_qr.cpp b/eigen/test/eigen2/eigen2_qr.cpp new file mode 100644 index 0000000..76977e4 --- /dev/null +++ b/eigen/test/eigen2/eigen2_qr.cpp @@ -0,0 +1,69 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. Eigen itself is part of the KDE project. +// +// Copyright (C) 2008 Gael Guennebaud +// +// This Source Code Form is subject to the terms of the Mozilla +// Public License v. 2.0. If a copy of the MPL was not distributed +// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include "main.h" +#include + +template void qr(const MatrixType& m) +{ + /* this test covers the following files: + QR.h + */ + int rows = m.rows(); + int cols = m.cols(); + + typedef typename MatrixType::Scalar Scalar; + typedef Matrix SquareMatrixType; + typedef Matrix VectorType; + + MatrixType a = MatrixType::Random(rows,cols); + QR qrOfA(a); + VERIFY_IS_APPROX(a, qrOfA.matrixQ() * qrOfA.matrixR()); + VERIFY_IS_NOT_APPROX(a+MatrixType::Identity(rows, cols), qrOfA.matrixQ() * qrOfA.matrixR()); + + #if 0 // eigenvalues module not yet ready + SquareMatrixType b = a.adjoint() * a; + + // check tridiagonalization + Tridiagonalization tridiag(b); + VERIFY_IS_APPROX(b, tridiag.matrixQ() * tridiag.matrixT() * tridiag.matrixQ().adjoint()); + + // check hessenberg decomposition + HessenbergDecomposition 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()); + #endif +} + +void test_eigen2_qr() +{ + for(int i = 0; i < 1; i++) { + CALL_SUBTEST_1( qr(Matrix2f()) ); + CALL_SUBTEST_2( qr(Matrix4d()) ); + CALL_SUBTEST_3( qr(MatrixXf(12,8)) ); + CALL_SUBTEST_4( qr(MatrixXcd(5,5)) ); + CALL_SUBTEST_4( qr(MatrixXcd(7,3)) ); + } + +#ifdef EIGEN_TEST_PART_5 + // small isFullRank test + { + Matrix3d mat; + mat << 1, 45, 1, 2, 2, 2, 1, 2, 3; + VERIFY(mat.qr().isFullRank()); + mat << 1, 1, 1, 2, 2, 2, 1, 2, 3; + //always returns true in eigen2support + //VERIFY(!mat.qr().isFullRank()); + } + +#endif +} -- cgit v1.2.3