44 template<
typename _MatrixType>
class HouseholderQR
48 typedef _MatrixType MatrixType;
50 RowsAtCompileTime = MatrixType::RowsAtCompileTime,
51 ColsAtCompileTime = MatrixType::ColsAtCompileTime,
52 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
53 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
55 typedef typename MatrixType::Scalar Scalar;
56 typedef typename MatrixType::RealScalar RealScalar;
58 typedef typename MatrixType::StorageIndex StorageIndex;
59 typedef Matrix<Scalar, RowsAtCompileTime, RowsAtCompileTime, (MatrixType::Flags&RowMajorBit) ? RowMajor : ColMajor, MaxRowsAtCompileTime, MaxRowsAtCompileTime> MatrixQType;
60 typedef typename internal::plain_diag_type<MatrixType>::type HCoeffsType;
61 typedef typename internal::plain_row_type<MatrixType>::type RowVectorType;
62 typedef HouseholderSequence<MatrixType,typename internal::remove_all<typename HCoeffsType::ConjugateReturnType>::type> HouseholderSequenceType;
70 HouseholderQR() : m_qr(), m_hCoeffs(), m_temp(), m_isInitialized(false) {}
80 m_hCoeffs((
std::min)(rows,cols)),
82 m_isInitialized(false) {}
96 template<
typename InputType>
98 : m_qr(matrix.rows(), matrix.cols()),
99 m_hCoeffs((
std::min)(matrix.rows(),matrix.cols())),
100 m_temp(matrix.cols()),
101 m_isInitialized(false)
114 template<
typename InputType>
116 : m_qr(matrix.derived()),
117 m_hCoeffs((
std::min)(matrix.rows(),matrix.cols())),
118 m_temp(matrix.cols()),
119 m_isInitialized(false)
138 template<
typename Rhs>
142 eigen_assert(m_isInitialized &&
"HouseholderQR is not initialized.");
156 eigen_assert(m_isInitialized &&
"HouseholderQR is not initialized.");
157 return HouseholderSequenceType(m_qr, m_hCoeffs.conjugate());
165 eigen_assert(m_isInitialized &&
"HouseholderQR is not initialized.");
169 template<
typename InputType>
205 inline Index rows()
const {
return m_qr.rows(); }
206 inline Index cols()
const {
return m_qr.cols(); }
212 const HCoeffsType&
hCoeffs()
const {
return m_hCoeffs; }
214 #ifndef EIGEN_PARSED_BY_DOXYGEN 215 template<
typename RhsType,
typename DstType>
217 void _solve_impl(
const RhsType &rhs, DstType &dst)
const;
222 static void check_template_parameters()
224 EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar);
230 HCoeffsType m_hCoeffs;
231 RowVectorType m_temp;
232 bool m_isInitialized;
235 template<
typename MatrixType>
239 eigen_assert(m_isInitialized &&
"HouseholderQR is not initialized.");
240 eigen_assert(m_qr.rows() == m_qr.cols() &&
"You can't take the determinant of a non-square matrix!");
241 return abs(m_qr.diagonal().prod());
244 template<
typename MatrixType>
247 eigen_assert(m_isInitialized &&
"HouseholderQR is not initialized.");
248 eigen_assert(m_qr.rows() == m_qr.cols() &&
"You can't take the determinant of a non-square matrix!");
249 return m_qr.diagonal().cwiseAbs().array().log().sum();
255 template<
typename MatrixQR,
typename HCoeffs>
256 void householder_qr_inplace_unblocked(MatrixQR& mat, HCoeffs&
hCoeffs,
typename MatrixQR::Scalar* tempData = 0)
258 typedef typename MatrixQR::Scalar Scalar;
259 typedef typename MatrixQR::RealScalar RealScalar;
260 Index rows = mat.rows();
261 Index cols = mat.cols();
262 Index size = (std::min)(rows,cols);
264 eigen_assert(hCoeffs.size() == size);
271 tempData = tempVector.data();
274 for(
Index k = 0; k < size; ++k)
276 Index remainingRows = rows - k;
277 Index remainingCols = cols - k - 1;
280 mat.col(k).tail(remainingRows).makeHouseholderInPlace(hCoeffs.coeffRef(k), beta);
281 mat.coeffRef(k,k) = beta;
284 mat.bottomRightCorner(remainingRows, remainingCols)
285 .applyHouseholderOnTheLeft(mat.col(k).tail(remainingRows-1), hCoeffs.coeffRef(k), tempData+k+1);
290 template<
typename MatrixQR,
typename HCoeffs,
291 typename MatrixQRScalar =
typename MatrixQR::Scalar,
292 bool InnerStrideIsOne = (MatrixQR::InnerStrideAtCompileTime == 1 && HCoeffs::InnerStrideAtCompileTime == 1)>
296 static void run(MatrixQR& mat, HCoeffs& hCoeffs,
Index maxBlockSize=32,
297 typename MatrixQR::Scalar* tempData = 0)
299 typedef typename MatrixQR::Scalar Scalar;
302 Index rows = mat.rows();
303 Index cols = mat.cols();
304 Index size = (std::min)(rows, cols);
311 tempData = tempVector.data();
314 Index blockSize = (std::min)(maxBlockSize,size);
317 for (k = 0; k < size; k += blockSize)
319 Index bs = (std::min)(size-k,blockSize);
320 Index tcols = cols - k - bs;
321 Index brows = rows-k;
331 BlockType A11_21 = mat.block(k,k,brows,bs);
334 householder_qr_inplace_unblocked(A11_21, hCoeffsSegment, tempData);
338 BlockType A21_22 = mat.block(k,k+bs,brows,tcols);
339 apply_block_householder_on_the_left(A21_22,A11_21,hCoeffsSegment,
false);
347 #ifndef EIGEN_PARSED_BY_DOXYGEN 348 template<
typename _MatrixType>
349 template<
typename RhsType,
typename DstType>
352 const Index rank = (std::min)(rows(), cols());
353 eigen_assert(rhs.rows() == rows());
355 typename RhsType::PlainObject c(rhs);
360 m_hCoeffs.head(rank)).transpose()
363 m_qr.topLeftCorner(rank, rank)
364 .template triangularView<Upper>()
365 .solveInPlace(c.topRows(rank));
367 dst.topRows(rank) = c.topRows(rank);
368 dst.bottomRows(cols()-rank).setZero();
378 template<
typename MatrixType>
381 check_template_parameters();
383 Index rows = m_qr.rows();
384 Index cols = m_qr.cols();
385 Index size = (std::min)(rows,cols);
387 m_hCoeffs.resize(size);
393 m_isInitialized =
true;
400 template<
typename Derived>
HouseholderQR(Index rows, Index cols)
Default Constructor with memory preallocation.
Definition: HouseholderQR.h:78
Definition: HouseholderQR.h:293
const MatrixType & matrixQR() const
Definition: HouseholderQR.h:163
MatrixType::RealScalar absDeterminant() const
Definition: HouseholderQR.h:236
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:85
const Solve< HouseholderQR, Rhs > solve(const MatrixBase< Rhs > &b) const
This method finds a solution x to the equation Ax=b, where A is the matrix of which *this is the QR d...
Definition: HouseholderQR.h:140
HouseholderSequence< VectorsType, CoeffsType > householderSequence(const VectorsType &v, const CoeffsType &h)
\
Definition: HouseholderSequence.h:451
Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor Matrix...
Definition: EigenBase.h:28
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index rows, Index cols)
Resizes *this to a rows x cols matrix.
Definition: PlainObjectBase.h:273
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
HouseholderQR(EigenBase< InputType > &matrix)
Constructs a QR factorization from a given matrix.
Definition: HouseholderQR.h:115
MatrixType::RealScalar logAbsDeterminant() const
Definition: HouseholderQR.h:245
const HouseholderQR< PlainObject > householderQr() const
Definition: HouseholderQR.h:402
HouseholderSequenceType householderQ() const
This method returns an expression of the unitary matrix Q as a sequence of Householder transformation...
Definition: HouseholderQR.h:154
Definition: BandTriangularSolver.h:13
Expression of a fixed-size or dynamic-size block.
Definition: Block.h:103
Householder QR decomposition of a matrix.
Definition: ForwardDeclarations.h:254
void computeInPlace()
Performs the QR factorization of the given matrix matrix.
Definition: HouseholderQR.h:379
Pseudo expression representing a solving operation.
Definition: Solve.h:62
HouseholderQR()
Default Constructor.
Definition: HouseholderQR.h:70
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:178
EIGEN_DEVICE_FUNC Derived & derived()
Definition: EigenBase.h:44
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
HouseholderQR(const EigenBase< InputType > &matrix)
Constructs a QR factorization from a given matrix.
Definition: HouseholderQR.h:97
const HCoeffsType & hCoeffs() const
Definition: HouseholderQR.h:212