42 template<
typename _MatrixType>
class HouseholderQR
46 typedef _MatrixType MatrixType;
48 RowsAtCompileTime = MatrixType::RowsAtCompileTime,
49 ColsAtCompileTime = MatrixType::ColsAtCompileTime,
51 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
52 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
55 typedef typename MatrixType::RealScalar RealScalar;
56 typedef typename MatrixType::Index Index;
57 typedef Matrix<Scalar, RowsAtCompileTime, RowsAtCompileTime, (MatrixType::Flags&RowMajorBit) ? RowMajor : ColMajor, MaxRowsAtCompileTime, MaxRowsAtCompileTime> MatrixQType;
58 typedef typename internal::plain_diag_type<MatrixType>::type HCoeffsType;
59 typedef typename internal::plain_row_type<MatrixType>::type RowVectorType;
60 typedef HouseholderSequence<MatrixType,typename internal::remove_all<typename HCoeffsType::ConjugateReturnType>::type> HouseholderSequenceType;
68 HouseholderQR() : m_qr(), m_hCoeffs(), m_temp(), m_isInitialized(false) {}
78 m_hCoeffs((
std::min)(rows,cols)),
80 m_isInitialized(false) {}
95 : m_qr(matrix.rows(), matrix.cols()),
96 m_hCoeffs((
std::min)(matrix.rows(),matrix.cols())),
97 m_temp(matrix.cols()),
98 m_isInitialized(false)
120 template<
typename Rhs>
124 eigen_assert(m_isInitialized &&
"HouseholderQR is not initialized.");
138 eigen_assert(m_isInitialized &&
"HouseholderQR is not initialized.");
139 return HouseholderSequenceType(m_qr, m_hCoeffs.conjugate());
147 eigen_assert(m_isInitialized &&
"HouseholderQR is not initialized.");
182 inline Index rows()
const {
return m_qr.rows(); }
183 inline Index cols()
const {
return m_qr.cols(); }
189 const HCoeffsType&
hCoeffs()
const {
return m_hCoeffs; }
193 static void check_template_parameters()
195 EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar);
199 HCoeffsType m_hCoeffs;
200 RowVectorType m_temp;
201 bool m_isInitialized;
204 template<
typename MatrixType>
208 eigen_assert(m_isInitialized &&
"HouseholderQR is not initialized.");
209 eigen_assert(m_qr.rows() == m_qr.cols() &&
"You can't take the determinant of a non-square matrix!");
210 return abs(m_qr.diagonal().prod());
213 template<
typename MatrixType>
216 eigen_assert(m_isInitialized &&
"HouseholderQR is not initialized.");
217 eigen_assert(m_qr.rows() == m_qr.cols() &&
"You can't take the determinant of a non-square matrix!");
218 return m_qr.diagonal().cwiseAbs().array().log().sum();
224 template<
typename MatrixQR,
typename HCoeffs>
225 void householder_qr_inplace_unblocked(MatrixQR& mat, HCoeffs&
hCoeffs,
typename MatrixQR::Scalar* tempData = 0)
227 typedef typename MatrixQR::Index Index;
229 typedef typename MatrixQR::RealScalar RealScalar;
230 Index rows = mat.rows();
231 Index cols = mat.cols();
232 Index
size = (std::min)(rows,cols);
234 eigen_assert(hCoeffs.size() ==
size);
241 tempData = tempVector.data();
244 for(Index k = 0; k <
size; ++k)
246 Index remainingRows = rows - k;
247 Index remainingCols = cols - k - 1;
250 mat.col(k).tail(remainingRows).makeHouseholderInPlace(hCoeffs.coeffRef(k), beta);
251 mat.coeffRef(k,k) = beta;
254 mat.bottomRightCorner(remainingRows, remainingCols)
255 .applyHouseholderOnTheLeft(mat.col(k).tail(remainingRows-1), hCoeffs.coeffRef(k), tempData+k+1);
260 template<
typename MatrixQR,
typename HCoeffs,
262 bool InnerStrideIsOne = (MatrixQR::InnerStrideAtCompileTime == 1 && HCoeffs::InnerStrideAtCompileTime == 1)>
266 static void run(MatrixQR& mat, HCoeffs& hCoeffs,
267 typename MatrixQR::Index maxBlockSize=32,
270 typedef typename MatrixQR::Index Index;
274 Index rows = mat.rows();
275 Index cols = mat.cols();
276 Index
size = (std::min)(rows, cols);
283 tempData = tempVector.data();
286 Index blockSize = (std::min)(maxBlockSize,size);
289 for (k = 0; k <
size; k += blockSize)
291 Index bs = (std::min)(size-k,blockSize);
292 Index tcols = cols - k - bs;
293 Index brows = rows-k;
303 BlockType A11_21 = mat.block(k,k,brows,bs);
306 householder_qr_inplace_unblocked(A11_21, hCoeffsSegment, tempData);
310 BlockType A21_22 = mat.block(k,k+bs,brows,tcols);
311 apply_block_householder_on_the_left(A21_22,A11_21,hCoeffsSegment.adjoint());
317 template<
typename _MatrixType,
typename Rhs>
323 template<
typename Dest>
void evalTo(Dest& dst)
const 325 const Index rows = dec().rows(), cols = dec().cols();
326 const Index rank = (std::min)(rows, cols);
327 eigen_assert(rhs().rows() == rows);
329 typename Rhs::PlainObject c(rhs());
338 .topLeftCorner(rank, rank)
339 .template triangularView<Upper>()
340 .solveInPlace(c.topRows(rank));
342 dst.topRows(rank) = c.topRows(rank);
343 dst.bottomRows(cols-rank).setZero();
355 template<
typename MatrixType>
358 check_template_parameters();
360 Index rows = matrix.rows();
361 Index cols = matrix.cols();
362 Index
size = (std::min)(rows,cols);
365 m_hCoeffs.resize(size);
371 m_isInitialized =
true;
379 template<
typename Derived>
HouseholderQR(const MatrixType &matrix)
Constructs a QR factorization from a given matrix.
Definition: HouseholderQR.h:94
Definition: ForwardDeclarations.h:124
HouseholderQR(Index rows, Index cols)
Default Constructor with memory preallocation.
Definition: HouseholderQR.h:76
Definition: HouseholderQR.h:263
const MatrixType & matrixQR() const
Definition: HouseholderQR.h:145
MatrixType::RealScalar absDeterminant() const
Definition: HouseholderQR.h:205
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: TestIMU_Common.h:87
typename detail::split_list_< List... >::head head
Get the first element of a list.
Definition: SplitList.h:54
Definition: TypeSafeIdHash.h:44
HouseholderSequence< VectorsType, CoeffsType > householderSequence(const VectorsType &v, const CoeffsType &h)
\
Definition: HouseholderSequence.h:422
detail::size< coerce_list< Ts... >> size
Get the size of a list (number of elements.)
Definition: Size.h:56
EIGEN_STRONG_INLINE void resize(Index nbRows, Index nbCols)
Resizes *this to a rows x cols matrix.
Definition: PlainObjectBase.h:235
MatrixType::RealScalar logAbsDeterminant() const
Definition: HouseholderQR.h:214
const HouseholderQR< PlainObject > householderQr() const
Definition: HouseholderQR.h:381
HouseholderSequenceType householderQ() const
This method returns an expression of the unitary matrix Q as a sequence of Householder transformation...
Definition: HouseholderQR.h:136
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:221
Definition: ForwardDeclarations.h:125
const internal::solve_retval< 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:122
HouseholderQR & compute(const MatrixType &matrix)
Performs the QR factorization of the given matrix matrix.
Definition: HouseholderQR.h:356
HouseholderQR()
Default Constructor.
Definition: HouseholderQR.h:68
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:127
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Definition: osvr_print_tree.cpp:52
double Scalar
Common scalar type.
Definition: FlexibleKalmanBase.h:48
const HCoeffsType & hCoeffs() const
Definition: HouseholderQR.h:189