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