358 typedef typename MatrixQR::Scalar
Scalar;
359 typedef typename MatrixQR::RealScalar RealScalar;
360 Index rows = mat.rows();
361 Index cols = mat.cols();
362 Index size = (std::min)(rows, cols);
364 eigen_assert(hCoeffs.size() == size);
370 tempData = tempVector.data();
373 for (
Index k = 0; k < size; ++k) {
374 Index remainingRows = rows - k;
375 Index remainingCols = cols - k - 1;
378 mat.col(k).tail(remainingRows).makeHouseholderInPlace(hCoeffs.coeffRef(k), beta);
379 mat.coeffRef(k, k) = beta;
382 mat.bottomRightCorner(remainingRows, remainingCols)
383 .applyHouseholderOnTheLeft(mat.col(k).tail(remainingRows - 1), hCoeffs.coeffRef(k), tempData + k + 1);
396template <
typename MatrixQR,
typename HCoeffs,
typename VectorQR>
397void householder_qr_inplace_update(MatrixQR& mat, HCoeffs& hCoeffs,
const VectorQR& newColumn,
398 typename MatrixQR::Index k,
typename MatrixQR::Scalar* tempData) {
399 typedef typename MatrixQR::Index
Index;
400 typedef typename MatrixQR::RealScalar RealScalar;
401 Index rows = mat.rows();
403 eigen_assert(k < mat.cols());
404 eigen_assert(k < rows);
405 eigen_assert(hCoeffs.size() == mat.cols());
406 eigen_assert(newColumn.size() == rows);
407 eigen_assert(tempData);
410 mat.col(k) = newColumn;
412 for (Index i = 0; i < k; ++i) {
413 Index remainingRows = rows - i;
416 .applyHouseholderOnTheLeft(mat.col(i).tail(remainingRows - 1), hCoeffs.coeffRef(i), tempData + i + 1);
420 mat.col(k).tail(rows - k).makeHouseholderInPlace(hCoeffs.coeffRef(k), beta);
421 mat.coeffRef(k, k) = beta;
425template <
typename MatrixQR,
typename HCoeffs,
typename MatrixQRScalar =
typename MatrixQR::Scalar,
426 bool InnerStrideIsOne = (MatrixQR::InnerStrideAtCompileTime == 1 && HCoeffs::InnerStrideAtCompileTime == 1)>
427struct householder_qr_inplace_blocked {
429 static void run(MatrixQR& mat, HCoeffs& hCoeffs, Index maxBlockSize = 32,
typename MatrixQR::Scalar* tempData = 0) {
430 typedef typename MatrixQR::Scalar Scalar;
431 typedef Block<MatrixQR, Dynamic, Dynamic> BlockType;
433 Index rows = mat.rows();
434 Index cols = mat.cols();
435 Index size = (std::min)(rows, cols);
437 typedef Matrix<Scalar, Dynamic, 1, ColMajor, MatrixQR::MaxColsAtCompileTime, 1> TempType;
440 tempVector.resize(cols);
441 tempData = tempVector.data();
444 Index blockSize = (std::min)(maxBlockSize, size);
447 for (k = 0; k < size; k += blockSize) {
448 Index bs = (std::min)(size - k, blockSize);
449 Index tcols = cols - k - bs;
450 Index brows = rows - k;
460 BlockType A11_21 = mat.block(k, k, brows, bs);
461 Block<HCoeffs, Dynamic, 1> hCoeffsSegment = hCoeffs.segment(k, bs);
463 householder_qr_inplace_unblocked(A11_21, hCoeffsSegment, tempData);
466 BlockType A21_22 = mat.block(k, k + bs, brows, tcols);
467 apply_block_householder_on_the_left(A21_22, A11_21, hCoeffsSegment,
false);
475#ifndef EIGEN_PARSED_BY_DOXYGEN
476template <
typename MatrixType_>
477template <
typename RhsType,
typename DstType>
478void HouseholderQR<MatrixType_>::_solve_impl(
const RhsType& rhs, DstType& dst)
const {
479 const Index rank = (std::min)(rows(), cols());
481 typename RhsType::PlainObject c(rhs);
485 m_qr.topLeftCorner(rank, rank).template triangularView<Upper>().solveInPlace(c.topRows(rank));
487 dst.topRows(rank) = c.topRows(rank);
488 dst.bottomRows(cols() - rank).setZero();
491template <
typename MatrixType_>
492template <
bool Conjugate,
typename RhsType,
typename DstType>
493void HouseholderQR<MatrixType_>::_solve_impl_transposed(
const RhsType& rhs, DstType& dst)
const {
494 const Index rank = (std::min)(rows(), cols());
496 typename RhsType::PlainObject c(rhs);
498 m_qr.topLeftCorner(rank, rank)
499 .template triangularView<Upper>()
501 .template conjugateIf<Conjugate>()
502 .solveInPlace(c.topRows(rank));
504 dst.topRows(rank) = c.topRows(rank);
505 dst.bottomRows(rows() - rank).setZero();
507 dst.applyOnTheLeft(
householderQ().setLength(rank).
template conjugateIf<!Conjugate>());
517template <
typename MatrixType>
519 Index rows = m_qr.rows();
520 Index cols = m_qr.cols();
523 m_hCoeffs.resize(
size);
527 internal::householder_qr_inplace_blocked<MatrixType, HCoeffsType>::run(m_qr, m_hCoeffs, 48, m_temp.data());
529 m_isInitialized =
true;
536template <
typename Derived>