26 #ifndef EIGEN_COLPIVOTINGHOUSEHOLDERQR_H
27 #define EIGEN_COLPIVOTINGHOUSEHOLDERQR_H
64 typedef typename MatrixType::Scalar
Scalar;
66 typedef typename MatrixType::Index
Index;
68 typedef typename internal::plain_diag_type<MatrixType>::type
HCoeffsType;
71 typedef typename internal::plain_row_type<MatrixType>::type
RowVectorType;
136 template<
typename Rhs>
137 inline const internal::solve_retval<ColPivHouseholderQR, Rhs>
141 return internal::solve_retval<ColPivHouseholderQR, Rhs>(*
this, b.derived());
263 internal::solve_retval<ColPivHouseholderQR, typename MatrixType::IdentityReturnType>
267 return internal::solve_retval<ColPivHouseholderQR,typename MatrixType::IdentityReturnType>
268 (*
this, MatrixType::Identity(
m_qr.rows(),
m_qr.cols()));
357 template<
typename MatrixType>
360 eigen_assert(m_isInitialized &&
"ColPivHouseholderQR is not initialized.");
361 eigen_assert(m_qr.rows() == m_qr.cols() &&
"You can't take the determinant of a non-square matrix!");
365 template<
typename MatrixType>
368 eigen_assert(m_isInitialized &&
"ColPivHouseholderQR is not initialized.");
369 eigen_assert(m_qr.rows() == m_qr.cols() &&
"You can't take the determinant of a non-square matrix!");
370 return m_qr.diagonal().cwiseAbs().array().log().sum();
373 template<
typename MatrixType>
377 Index cols = matrix.cols();
378 Index size = matrix.diagonalSize();
381 m_hCoeffs.resize(size);
385 m_colsTranspositions.resize(matrix.cols());
386 Index number_of_transpositions = 0;
388 m_colSqNorms.resize(cols);
389 for(
Index k = 0; k < cols; ++k)
390 m_colSqNorms.coeffRef(k) = m_qr.col(k).squaredNorm();
394 m_nonzero_pivots = size;
397 for(
Index k = 0; k < size; ++k)
400 Index biggest_col_index;
401 RealScalar biggest_col_sq_norm = m_colSqNorms.tail(cols-k).maxCoeff(&biggest_col_index);
402 biggest_col_index += k;
408 biggest_col_sq_norm = m_qr.col(biggest_col_index).tail(rows-k).squaredNorm();
411 m_colSqNorms.coeffRef(biggest_col_index) = biggest_col_sq_norm;
418 if(biggest_col_sq_norm < threshold_helper *
RealScalar(rows-k))
420 m_nonzero_pivots = k;
421 m_hCoeffs.tail(size-k).setZero();
422 m_qr.bottomRightCorner(rows-k,cols-k)
423 .template triangularView<StrictlyLower>()
429 m_colsTranspositions.coeffRef(k) = biggest_col_index;
430 if(k != biggest_col_index) {
431 m_qr.col(k).swap(m_qr.col(biggest_col_index));
432 std::swap(m_colSqNorms.coeffRef(k), m_colSqNorms.coeffRef(biggest_col_index));
433 ++number_of_transpositions;
438 m_qr.col(k).tail(rows-k).makeHouseholderInPlace(m_hCoeffs.coeffRef(k), beta);
441 m_qr.coeffRef(k,k) = beta;
447 m_qr.bottomRightCorner(rows-k, cols-k-1)
448 .applyHouseholderOnTheLeft(m_qr.col(k).tail(rows-k-1), m_hCoeffs.coeffRef(k), &m_temp.coeffRef(k+1));
451 m_colSqNorms.tail(cols-k-1) -= m_qr.row(k).tail(cols-k-1).cwiseAbs2();
454 m_colsPermutation.setIdentity(cols);
455 for(
Index k = 0; k < m_nonzero_pivots; ++k)
456 m_colsPermutation.applyTranspositionOnTheRight(k, m_colsTranspositions.coeff(k));
458 m_det_pq = (number_of_transpositions%2) ? -1 : 1;
459 m_isInitialized =
true;
466 template<
typename _MatrixType,
typename Rhs>
468 : solve_retval_base<ColPivHouseholderQR<_MatrixType>, Rhs>
472 template<typename Dest>
void evalTo(Dest& dst)
const
476 const int cols = dec().cols(),
477 nonzero_pivots = dec().nonzeroPivots();
479 if(nonzero_pivots == 0)
485 typename Rhs::PlainObject c(rhs());
489 .setLength(dec().nonzeroPivots())
494 .topLeftCorner(nonzero_pivots, nonzero_pivots)
495 .template triangularView<Upper>()
496 .solveInPlace(c.topRows(nonzero_pivots));
499 typename Rhs::PlainObject d(c);
500 d.topRows(nonzero_pivots)
502 .topLeftCorner(nonzero_pivots, nonzero_pivots)
503 .template triangularView<Upper>()
504 * c.topRows(nonzero_pivots);
506 for(Index i = 0; i < nonzero_pivots; ++i) dst.row(dec().colsPermutation().indices().coeff(i)) = c.row(i);
507 for(Index i = nonzero_pivots; i < cols; ++i) dst.row(dec().colsPermutation().indices().coeff(i)).setZero();
514 template<
typename MatrixType>
518 eigen_assert(m_isInitialized &&
"ColPivHouseholderQR is not initialized.");
526 template<
typename Derived>
535 #endif // EIGEN_COLPIVOTINGHOUSEHOLDERQR_H