23 typedef int StorageIndex;
57 :
public SolverBase<HouseholderQR<_MatrixType> >
61 typedef _MatrixType MatrixType;
67 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
68 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
81 HouseholderQR() : m_qr(), m_hCoeffs(), m_temp(), m_isInitialized(false) {}
91 m_hCoeffs((std::min)(rows,cols)),
93 m_isInitialized(false) {}
107 template<
typename InputType>
109 : m_qr(matrix.rows(), matrix.cols()),
110 m_hCoeffs((std::min)(matrix.rows(),matrix.cols())),
111 m_temp(matrix.cols()),
112 m_isInitialized(false)
125 template<
typename InputType>
127 : m_qr(matrix.derived()),
128 m_hCoeffs((std::min)(matrix.rows(),matrix.cols())),
129 m_temp(matrix.cols()),
130 m_isInitialized(false)
135 #ifdef EIGEN_PARSED_BY_DOXYGEN
150 template<
typename Rhs>
165 eigen_assert(m_isInitialized &&
"HouseholderQR is not initialized.");
174 eigen_assert(m_isInitialized &&
"HouseholderQR is not initialized.");
178 template<
typename InputType>
214 inline Index rows()
const {
return m_qr.rows(); }
215 inline Index cols()
const {
return m_qr.cols(); }
223 #ifndef EIGEN_PARSED_BY_DOXYGEN
224 template<
typename RhsType,
typename DstType>
225 void _solve_impl(
const RhsType &rhs, DstType &dst)
const;
227 template<
bool Conjugate,
typename RhsType,
typename DstType>
228 void _solve_impl_transposed(
const RhsType &rhs, DstType &dst)
const;
233 static void check_template_parameters()
235 EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar);
243 bool m_isInitialized;
246 template<
typename MatrixType>
250 eigen_assert(m_isInitialized &&
"HouseholderQR is not initialized.");
251 eigen_assert(m_qr.rows() == m_qr.cols() &&
"You can't take the determinant of a non-square matrix!");
252 return abs(m_qr.diagonal().prod());
255 template<
typename MatrixType>
258 eigen_assert(m_isInitialized &&
"HouseholderQR is not initialized.");
259 eigen_assert(m_qr.rows() == m_qr.cols() &&
"You can't take the determinant of a non-square matrix!");
260 return m_qr.diagonal().cwiseAbs().array().log().sum();
266 template<
typename MatrixQR,
typename HCoeffs>
267 void householder_qr_inplace_unblocked(MatrixQR& mat, HCoeffs& hCoeffs,
typename MatrixQR::Scalar* tempData = 0)
269 typedef typename MatrixQR::Scalar Scalar;
270 typedef typename MatrixQR::RealScalar RealScalar;
271 Index rows = mat.rows();
272 Index cols = mat.cols();
273 Index size = (std::min)(rows,cols);
275 eigen_assert(hCoeffs.size() == size);
282 tempData = tempVector.data();
285 for(Index k = 0; k < size; ++k)
287 Index remainingRows = rows - k;
288 Index remainingCols = cols - k - 1;
291 mat.col(k).tail(remainingRows).makeHouseholderInPlace(hCoeffs.coeffRef(k), beta);
292 mat.coeffRef(k,k) = beta;
295 mat.bottomRightCorner(remainingRows, remainingCols)
296 .applyHouseholderOnTheLeft(mat.col(k).tail(remainingRows-1), hCoeffs.coeffRef(k), tempData+k+1);
301 template<
typename MatrixQR,
typename HCoeffs,
302 typename MatrixQRScalar =
typename MatrixQR::Scalar,
303 bool InnerStrideIsOne = (MatrixQR::InnerStrideAtCompileTime == 1 && HCoeffs::InnerStrideAtCompileTime == 1)>
307 static void run(MatrixQR& mat, HCoeffs& hCoeffs,
Index maxBlockSize=32,
308 typename MatrixQR::Scalar* tempData = 0)
310 typedef typename MatrixQR::Scalar Scalar;
313 Index rows = mat.rows();
314 Index cols = mat.cols();
315 Index size = (std::min)(rows, cols);
322 tempData = tempVector.data();
325 Index blockSize = (std::min)(maxBlockSize,size);
328 for (k = 0; k < size; k += blockSize)
330 Index bs = (std::min)(size-k,blockSize);
331 Index tcols = cols - k - bs;
332 Index brows = rows-k;
342 BlockType A11_21 = mat.block(k,k,brows,bs);
345 householder_qr_inplace_unblocked(A11_21, hCoeffsSegment, tempData);
349 BlockType A21_22 = mat.block(k,k+bs,brows,tcols);
350 apply_block_householder_on_the_left(A21_22,A11_21,hCoeffsSegment,
false);
358 #ifndef EIGEN_PARSED_BY_DOXYGEN
359 template<
typename _MatrixType>
360 template<
typename RhsType,
typename DstType>
363 const Index rank = (std::min)(rows(), cols());
365 typename RhsType::PlainObject c(rhs);
367 c.applyOnTheLeft(householderQ().setLength(rank).adjoint() );
369 m_qr.topLeftCorner(rank, rank)
370 .template triangularView<Upper>()
371 .solveInPlace(c.topRows(rank));
373 dst.topRows(rank) = c.topRows(rank);
374 dst.bottomRows(cols()-rank).setZero();
377 template<
typename _MatrixType>
378 template<
bool Conjugate,
typename RhsType,
typename DstType>
381 const Index rank = (std::min)(rows(), cols());
383 typename RhsType::PlainObject c(rhs);
385 m_qr.topLeftCorner(rank, rank)
386 .template triangularView<Upper>()
387 .transpose().template conjugateIf<Conjugate>()
388 .solveInPlace(c.topRows(rank));
390 dst.topRows(rank) = c.topRows(rank);
391 dst.bottomRows(rows()-rank).setZero();
393 dst.applyOnTheLeft(householderQ().setLength(rank).
template conjugateIf<!Conjugate>() );
403 template<
typename MatrixType>
406 check_template_parameters();
408 Index rows = m_qr.rows();
409 Index cols = m_qr.cols();
410 Index size = (std::min)(rows,cols);
412 m_hCoeffs.resize(size);
418 m_isInitialized =
true;
425 template<
typename Derived>