1 // This file is part of Eigen, a lightweight C++ template library 2 // for linear algebra. 3 // 4 // Copyright (C) 2008 Gael Guennebaud <g.gael (at) free.fr> 5 // Copyright (C) 2011 Benoit Jacob <jacob.benoit.1 (at) gmail.com> 6 // 7 // This Source Code Form is subject to the terms of the Mozilla 8 // Public License v. 2.0. If a copy of the MPL was not distributed 9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 10 11 #ifndef EIGEN2_QR_H 12 #define EIGEN2_QR_H 13 14 namespace Eigen { 15 16 template<typename MatrixType> 17 class QR : public HouseholderQR<MatrixType> 18 { 19 public: 20 21 typedef HouseholderQR<MatrixType> Base; 22 typedef Block<const MatrixType, MatrixType::ColsAtCompileTime, MatrixType::ColsAtCompileTime> MatrixRBlockType; 23 24 QR() : Base() {} 25 26 template<typename T> 27 explicit QR(const T& t) : Base(t) {} 28 29 template<typename OtherDerived, typename ResultType> 30 bool solve(const MatrixBase<OtherDerived>& b, ResultType *result) const 31 { 32 *result = static_cast<const Base*>(this)->solve(b); 33 return true; 34 } 35 36 MatrixType matrixQ(void) const { 37 MatrixType ret = MatrixType::Identity(this->rows(), this->cols()); 38 ret = this->householderQ() * ret; 39 return ret; 40 } 41 42 bool isFullRank() const { 43 return true; 44 } 45 46 const TriangularView<MatrixRBlockType, UpperTriangular> 47 matrixR(void) const 48 { 49 int cols = this->cols(); 50 return MatrixRBlockType(this->matrixQR(), 0, 0, cols, cols).template triangularView<UpperTriangular>(); 51 } 52 }; 53 54 /** \return the QR decomposition of \c *this. 55 * 56 * \sa class QR 57 */ 58 template<typename Derived> 59 const QR<typename MatrixBase<Derived>::PlainObject> 60 MatrixBase<Derived>::qr() const 61 { 62 return QR<PlainObject>(eval()); 63 } 64 65 } // end namespace Eigen 66 67 #endif // EIGEN2_QR_H 68