Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Eigen::HouseholderQR< _MatrixType > Class Template Reference

Householder QR decomposition of a matrix. More...

#include <src/eigen/Eigen/src/QR/HouseholderQR.h>

+ Inheritance diagram for Eigen::HouseholderQR< _MatrixType >:
+ Collaboration diagram for Eigen::HouseholderQR< _MatrixType >:

Public Types

enum  { RowsAtCompileTime = MatrixType::RowsAtCompileTime , ColsAtCompileTime = MatrixType::ColsAtCompileTime , MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime , MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime }
 
typedef _MatrixType MatrixType
 
typedef MatrixType::Scalar Scalar
 
typedef MatrixType::RealScalar RealScalar
 
typedef MatrixType::StorageIndex StorageIndex
 
typedef Matrix< Scalar, RowsAtCompileTime, RowsAtCompileTime,(MatrixType::Flags &RowMajorBit) ? RowMajor :ColMajor, MaxRowsAtCompileTime, MaxRowsAtCompileTimeMatrixQType
 
typedef internal::plain_diag_type< MatrixType >::type HCoeffsType
 
typedef internal::plain_row_type< MatrixType >::type RowVectorType
 
typedef HouseholderSequence< MatrixType, typename internal::remove_all< typename HCoeffsType::ConjugateReturnType >::type > HouseholderSequenceType
 

Public Member Functions

 HouseholderQR ()
 Default Constructor.
 
 HouseholderQR (Index rows, Index cols)
 Default Constructor with memory preallocation.
 
template<typename InputType >
 HouseholderQR (const EigenBase< InputType > &matrix)
 Constructs a QR factorization from a given matrix.
 
template<typename InputType >
 HouseholderQR (EigenBase< InputType > &matrix)
 Constructs a QR factorization from a given matrix.
 
template<typename Rhs >
const Solve< HouseholderQR, Rhs > solve (const MatrixBase< Rhs > &b) const
 
HouseholderSequenceType householderQ () const
 
const MatrixTypematrixQR () const
 
template<typename InputType >
HouseholderQRcompute (const EigenBase< InputType > &matrix)
 
MatrixType::RealScalar absDeterminant () const
 
MatrixType::RealScalar logAbsDeterminant () const
 
Index rows () const
 
Index cols () const
 
const HCoeffsTypehCoeffs () const
 
template<typename RhsType , typename DstType >
EIGEN_DEVICE_FUNC void _solve_impl (const RhsType &rhs, DstType &dst) const
 
template<typename RhsType , typename DstType >
void _solve_impl (const RhsType &rhs, DstType &dst) const
 

Protected Member Functions

void computeInPlace ()
 

Static Protected Member Functions

static void check_template_parameters ()
 

Protected Attributes

MatrixType m_qr
 
HCoeffsType m_hCoeffs
 
RowVectorType m_temp
 
bool m_isInitialized
 

Detailed Description

template<typename _MatrixType>
class Eigen::HouseholderQR< _MatrixType >

Householder QR decomposition of a matrix.

Template Parameters
_MatrixTypethe type of the matrix of which we are computing the QR decomposition

This class performs a QR decomposition of a matrix A into matrices Q and R such that

\[
 \mathbf{A} = \mathbf{Q} \, \mathbf{R}
\]

by using Householder transformations. Here, Q a unitary matrix and R an upper triangular matrix. The result is stored in a compact way compatible with LAPACK.

Note that no pivoting is performed. This is not a rank-revealing decomposition. If you want that feature, use FullPivHouseholderQR or ColPivHouseholderQR instead.

This Householder QR decomposition is faster, but less numerically stable and less feature-full than FullPivHouseholderQR or ColPivHouseholderQR.

This class supports the inplace decomposition mechanism.

See also
MatrixBase::householderQr()

Member Typedef Documentation

◆ HCoeffsType

template<typename _MatrixType >
typedef internal::plain_diag_type<MatrixType>::type Eigen::HouseholderQR< _MatrixType >::HCoeffsType

◆ HouseholderSequenceType

template<typename _MatrixType >
typedef HouseholderSequence<MatrixType,typename internal::remove_all<typename HCoeffsType::ConjugateReturnType>::type> Eigen::HouseholderQR< _MatrixType >::HouseholderSequenceType

◆ MatrixQType

template<typename _MatrixType >
typedef Matrix<Scalar, RowsAtCompileTime, RowsAtCompileTime, (MatrixType::Flags&RowMajorBit) ? RowMajor : ColMajor, MaxRowsAtCompileTime, MaxRowsAtCompileTime> Eigen::HouseholderQR< _MatrixType >::MatrixQType

◆ MatrixType

template<typename _MatrixType >
typedef _MatrixType Eigen::HouseholderQR< _MatrixType >::MatrixType

◆ RealScalar

template<typename _MatrixType >
typedef MatrixType::RealScalar Eigen::HouseholderQR< _MatrixType >::RealScalar

◆ RowVectorType

template<typename _MatrixType >
typedef internal::plain_row_type<MatrixType>::type Eigen::HouseholderQR< _MatrixType >::RowVectorType

◆ Scalar

template<typename _MatrixType >
typedef MatrixType::Scalar Eigen::HouseholderQR< _MatrixType >::Scalar

◆ StorageIndex

template<typename _MatrixType >
typedef MatrixType::StorageIndex Eigen::HouseholderQR< _MatrixType >::StorageIndex

Member Enumeration Documentation

◆ anonymous enum

template<typename _MatrixType >
anonymous enum
Enumerator
RowsAtCompileTime 
ColsAtCompileTime 
MaxRowsAtCompileTime 
MaxColsAtCompileTime 
49 {
50 RowsAtCompileTime = MatrixType::RowsAtCompileTime,
51 ColsAtCompileTime = MatrixType::ColsAtCompileTime,
52 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
53 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
54 };
@ MaxColsAtCompileTime
Definition HouseholderQR.h:53
@ ColsAtCompileTime
Definition HouseholderQR.h:51
@ MaxRowsAtCompileTime
Definition HouseholderQR.h:52
@ RowsAtCompileTime
Definition HouseholderQR.h:50

Constructor & Destructor Documentation

◆ HouseholderQR() [1/4]

template<typename _MatrixType >
Eigen::HouseholderQR< _MatrixType >::HouseholderQR ( )
inline

Default Constructor.

The default constructor is useful in cases in which the user intends to perform decompositions via HouseholderQR::compute(const MatrixType&).

70: m_qr(), m_hCoeffs(), m_temp(), m_isInitialized(false) {}
RowVectorType m_temp
Definition HouseholderQR.h:231
bool m_isInitialized
Definition HouseholderQR.h:232
HCoeffsType m_hCoeffs
Definition HouseholderQR.h:230
MatrixType m_qr
Definition HouseholderQR.h:229

◆ HouseholderQR() [2/4]

template<typename _MatrixType >
Eigen::HouseholderQR< _MatrixType >::HouseholderQR ( Index  rows,
Index  cols 
)
inline

Default Constructor with memory preallocation.

Like the default constructor but with preallocation of the internal data according to the specified problem size.

See also
HouseholderQR()
79 : m_qr(rows, cols),
80 m_hCoeffs((std::min)(rows,cols)),
81 m_temp(cols),
82 m_isInitialized(false) {}
Index cols() const
Definition HouseholderQR.h:206
Index rows() const
Definition HouseholderQR.h:205

◆ HouseholderQR() [3/4]

template<typename _MatrixType >
template<typename InputType >
Eigen::HouseholderQR< _MatrixType >::HouseholderQR ( const EigenBase< InputType > &  matrix)
inlineexplicit

Constructs a QR factorization from a given matrix.

This constructor computes the QR factorization of the matrix matrix by calling the method compute(). It is a short cut for:

HouseholderQR<MatrixType> qr(matrix.rows(), matrix.cols());
qr.compute(matrix);
Householder QR decomposition of a matrix.
Definition HouseholderQR.h:45
See also
compute()
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)
102 {
103 compute(matrix.derived());
104 }
HouseholderQR & compute(const EigenBase< InputType > &matrix)
Definition HouseholderQR.h:170

References Eigen::HouseholderQR< _MatrixType >::compute(), and Eigen::EigenBase< Derived >::derived().

+ Here is the call graph for this function:

◆ HouseholderQR() [4/4]

template<typename _MatrixType >
template<typename InputType >
Eigen::HouseholderQR< _MatrixType >::HouseholderQR ( EigenBase< InputType > &  matrix)
inlineexplicit

Constructs a QR factorization from a given matrix.

This overloaded constructor is provided for inplace decomposition when MatrixType is a Eigen::Ref.

See also
HouseholderQR(const EigenBase&)
116 : m_qr(matrix.derived()),
117 m_hCoeffs((std::min)(matrix.rows(),matrix.cols())),
118 m_temp(matrix.cols()),
119 m_isInitialized(false)
120 {
122 }
void computeInPlace()
Definition HouseholderQR.h:379

References Eigen::HouseholderQR< _MatrixType >::computeInPlace().

+ Here is the call graph for this function:

Member Function Documentation

◆ _solve_impl() [1/2]

template<typename _MatrixType >
template<typename RhsType , typename DstType >
EIGEN_DEVICE_FUNC void Eigen::HouseholderQR< _MatrixType >::_solve_impl ( const RhsType &  rhs,
DstType &  dst 
) const

◆ _solve_impl() [2/2]

template<typename _MatrixType >
template<typename RhsType , typename DstType >
void Eigen::HouseholderQR< _MatrixType >::_solve_impl ( const RhsType &  rhs,
DstType &  dst 
) const
351{
352 const Index rank = (std::min)(rows(), cols());
353 eigen_assert(rhs.rows() == rows());
354
355 typename RhsType::PlainObject c(rhs);
356
357 // Note that the matrix Q = H_0^* H_1^*... so its inverse is Q^* = (H_0 H_1 ...)^T
358 c.applyOnTheLeft(householderSequence(
359 m_qr.leftCols(rank),
360 m_hCoeffs.head(rank)).transpose()
361 );
362
363 m_qr.topLeftCorner(rank, rank)
364 .template triangularView<Upper>()
365 .solveInPlace(c.topRows(rank));
366
367 dst.topRows(rank) = c.topRows(rank);
368 dst.bottomRows(cols()-rank).setZero();
369}
#define eigen_assert(x)
Definition Macros.h:579
HouseholderSequence< VectorsType, CoeffsType > householderSequence(const VectorsType &v, const CoeffsType &h)
Convenience function for constructing a Householder sequence.
Definition HouseholderSequence.h:451
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:33

◆ absDeterminant()

template<typename MatrixType >
MatrixType::RealScalar Eigen::HouseholderQR< MatrixType >::absDeterminant
Returns
the absolute value of the determinant of the matrix of which *this is the QR decomposition. It has only linear complexity (that is, O(n) where n is the dimension of the square matrix) as the QR decomposition has already been computed.
Note
This is only for square matrices.
Warning
a determinant can be very big or small, so for matrices of large enough dimension, there is a risk of overflow/underflow. One way to work around that is to use logAbsDeterminant() instead.
See also
logAbsDeterminant(), MatrixBase::determinant()
237{
238 using std::abs;
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());
242}
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half abs(const half &a)
Definition Half.h:445

References eigen_assert.

◆ check_template_parameters()

template<typename _MatrixType >
static void Eigen::HouseholderQR< _MatrixType >::check_template_parameters ( )
inlinestaticprotected
223 {
225 }
#define EIGEN_STATIC_ASSERT_NON_INTEGER(TYPE)
Definition StaticAssert.h:184
MatrixType::Scalar Scalar
Definition HouseholderQR.h:55

References EIGEN_STATIC_ASSERT_NON_INTEGER.

◆ cols()

template<typename _MatrixType >
Index Eigen::HouseholderQR< _MatrixType >::cols ( ) const
inline
206{ return m_qr.cols(); }

References Eigen::HouseholderQR< _MatrixType >::m_qr.

◆ compute()

template<typename _MatrixType >
template<typename InputType >
HouseholderQR & Eigen::HouseholderQR< _MatrixType >::compute ( const EigenBase< InputType > &  matrix)
inline
170 {
171 m_qr = matrix.derived();
173 return *this;
174 }

References Eigen::HouseholderQR< _MatrixType >::computeInPlace(), Eigen::EigenBase< Derived >::derived(), and Eigen::HouseholderQR< _MatrixType >::m_qr.

Referenced by Eigen::HouseholderQR< _MatrixType >::HouseholderQR().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ computeInPlace()

template<typename MatrixType >
void Eigen::HouseholderQR< MatrixType >::computeInPlace
protected

Performs the QR factorization of the given matrix matrix. The result of the factorization is stored into *this, and a reference to *this is returned.

See also
class HouseholderQR, HouseholderQR(const MatrixType&)
380{
382
383 Index rows = m_qr.rows();
384 Index cols = m_qr.cols();
385 Index size = (std::min)(rows,cols);
386
387 m_hCoeffs.resize(size);
388
389 m_temp.resize(cols);
390
392
393 m_isInitialized = true;
394}
static void check_template_parameters()
Definition HouseholderQR.h:222
constexpr auto size(const C &c) -> decltype(c.size())
Definition span.hpp:183
static void run(MatrixQR &mat, HCoeffs &hCoeffs, Index maxBlockSize=32, typename MatrixQR::Scalar *tempData=0)
Definition HouseholderQR.h:296

References Eigen::internal::householder_qr_inplace_blocked< MatrixQR, HCoeffs, MatrixQRScalar, InnerStrideIsOne >::run().

Referenced by Eigen::HouseholderQR< _MatrixType >::HouseholderQR(), and Eigen::HouseholderQR< _MatrixType >::compute().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hCoeffs()

template<typename _MatrixType >
const HCoeffsType & Eigen::HouseholderQR< _MatrixType >::hCoeffs ( ) const
inline
Returns
a const reference to the vector of Householder coefficients used to represent the factor Q.

For advanced uses only.

212{ return m_hCoeffs; }

References Eigen::HouseholderQR< _MatrixType >::m_hCoeffs.

◆ householderQ()

template<typename _MatrixType >
HouseholderSequenceType Eigen::HouseholderQR< _MatrixType >::householderQ ( ) const
inline

This method returns an expression of the unitary matrix Q as a sequence of Householder transformations.

The returned expression can directly be used to perform matrix products. It can also be assigned to a dense Matrix object. Here is an example showing how to recover the full or thin matrix Q, as well as how to perform matrix products using operator*:

Example:

Output:

 
155 {
156 eigen_assert(m_isInitialized && "HouseholderQR is not initialized.");
157 return HouseholderSequenceType(m_qr, m_hCoeffs.conjugate());
158 }
HouseholderSequence< MatrixType, typename internal::remove_all< typename HCoeffsType::ConjugateReturnType >::type > HouseholderSequenceType
Definition HouseholderQR.h:62

References eigen_assert, Eigen::HouseholderQR< _MatrixType >::m_hCoeffs, Eigen::HouseholderQR< _MatrixType >::m_isInitialized, and Eigen::HouseholderQR< _MatrixType >::m_qr.

Referenced by Eigen::RealQZ< _MatrixType >::hessenbergTriangular(), and igl::per_vertex_point_to_plane_quadrics().

+ Here is the caller graph for this function:

◆ logAbsDeterminant()

template<typename MatrixType >
MatrixType::RealScalar Eigen::HouseholderQR< MatrixType >::logAbsDeterminant
Returns
the natural log of the absolute value of the determinant of the matrix of which *this is the QR decomposition. It has only linear complexity (that is, O(n) where n is the dimension of the square matrix) as the QR decomposition has already been computed.
Note
This is only for square matrices.
This method is useful to work around the risk of overflow/underflow that's inherent to determinant computation.
See also
absDeterminant(), MatrixBase::determinant()
246{
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();
250}

References eigen_assert.

◆ matrixQR()

template<typename _MatrixType >
const MatrixType & Eigen::HouseholderQR< _MatrixType >::matrixQR ( ) const
inline
Returns
a reference to the matrix where the Householder QR decomposition is stored in a LAPACK-compatible way.
164 {
165 eigen_assert(m_isInitialized && "HouseholderQR is not initialized.");
166 return m_qr;
167 }

References eigen_assert, Eigen::HouseholderQR< _MatrixType >::m_isInitialized, and Eigen::HouseholderQR< _MatrixType >::m_qr.

Referenced by Eigen::RealQZ< _MatrixType >::hessenbergTriangular().

+ Here is the caller graph for this function:

◆ rows()

template<typename _MatrixType >
Index Eigen::HouseholderQR< _MatrixType >::rows ( ) const
inline
205{ return m_qr.rows(); }

References Eigen::HouseholderQR< _MatrixType >::m_qr.

◆ solve()

template<typename _MatrixType >
template<typename Rhs >
const Solve< HouseholderQR, Rhs > Eigen::HouseholderQR< _MatrixType >::solve ( const MatrixBase< Rhs > &  b) const
inline

This method finds a solution x to the equation Ax=b, where A is the matrix of which *this is the QR decomposition, if any exists.

Parameters
bthe right-hand-side of the equation to solve.
Returns
a solution.

\note_about_checking_solutions

\note_about_arbitrary_choice_of_solution

Example:

Output:

 
141 {
142 eigen_assert(m_isInitialized && "HouseholderQR is not initialized.");
143 return Solve<HouseholderQR, Rhs>(*this, b.derived());
144 }

References eigen_assert, and Eigen::HouseholderQR< _MatrixType >::m_isInitialized.

Member Data Documentation

◆ m_hCoeffs

template<typename _MatrixType >
HCoeffsType Eigen::HouseholderQR< _MatrixType >::m_hCoeffs
protected

◆ m_isInitialized

◆ m_qr

◆ m_temp

template<typename _MatrixType >
RowVectorType Eigen::HouseholderQR< _MatrixType >::m_temp
protected

The documentation for this class was generated from the following files: