Eigen::HouseholderQR< MatrixType_ > Class Template Reference

Householder QR decomposition of a matrix. More...

#include <HouseholderQR.h>

+ Inheritance diagram for Eigen::HouseholderQR< MatrixType_ >:

Public Types

enum  { MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime , MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime }
 
typedef MatrixType_ MatrixType
 
typedef SolverBase< HouseholderQRBase
 
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, internal::remove_all_t< typename HCoeffsType::ConjugateReturnType > > HouseholderSequenceType
 
- Public Types inherited from Eigen::SolverBase< HouseholderQR< MatrixType_ > >
enum  
 
typedef EigenBase< HouseholderQR< MatrixType_ > > Base
 
typedef internal::traits< HouseholderQR< MatrixType_ > >::Scalar Scalar
 
typedef Scalar CoeffReturnType
 
typedef Transpose< const HouseholderQR< MatrixType_ > > ConstTransposeReturnType
 
typedef std::conditional_t< NumTraits< Scalar >::IsComplex, CwiseUnaryOp< internal::scalar_conjugate_op< Scalar >, const ConstTransposeReturnType >, const ConstTransposeReturnTypeAdjointReturnType
 
- Public Types inherited from Eigen::EigenBase< Derived >
typedef Eigen::Index Index
 The interface type of indices. More...
 
typedef internal::traits< Derived >::StorageKind StorageKind
 

Public Member Functions

 HouseholderQR ()
 Default Constructor. More...
 
 HouseholderQR (Index rows, Index cols)
 Default Constructor with memory preallocation. More...
 
template<typename InputType >
 HouseholderQR (const EigenBase< InputType > &matrix)
 Constructs a QR factorization from a given matrix. More...
 
template<typename InputType >
 HouseholderQR (EigenBase< InputType > &matrix)
 Constructs a QR factorization from a given matrix. More...
 
HouseholderSequenceType householderQ () const
 
const MatrixTypematrixQR () const
 
template<typename InputType >
HouseholderQRcompute (const EigenBase< InputType > &matrix)
 
MatrixType::Scalar determinant () const
 
MatrixType::RealScalar absDeterminant () const
 
MatrixType::RealScalar logAbsDeterminant () const
 
MatrixType::Scalar signDeterminant () const
 
Index rows () const
 
Index cols () const
 
const HCoeffsTypehCoeffs () const
 
template<typename RhsType , typename DstType >
void _solve_impl (const RhsType &rhs, DstType &dst) const
 
template<bool Conjugate, typename RhsType , typename DstType >
void _solve_impl_transposed (const RhsType &rhs, DstType &dst) const
 
- Public Member Functions inherited from Eigen::SolverBase< HouseholderQR< MatrixType_ > >
 SolverBase ()
 
 ~SolverBase ()
 
const Solve< HouseholderQR< MatrixType_ >, Rhs > solve (const MatrixBase< Rhs > &b) const
 
const ConstTransposeReturnType transpose () const
 
const AdjointReturnType adjoint () const
 
constexpr EIGEN_DEVICE_FUNC HouseholderQR< MatrixType_ > & derived ()
 
constexpr EIGEN_DEVICE_FUNC const HouseholderQR< MatrixType_ > & derived () const
 
- Public Member Functions inherited from Eigen::EigenBase< Derived >
constexpr EIGEN_DEVICE_FUNC Derived & derived ()
 
constexpr EIGEN_DEVICE_FUNC const Derived & derived () const
 
EIGEN_DEVICE_FUNC Derived & const_cast_derived () const
 
EIGEN_DEVICE_FUNC const Derived & const_derived () const
 
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows () const EIGEN_NOEXCEPT
 
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols () const EIGEN_NOEXCEPT
 
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index size () const EIGEN_NOEXCEPT
 
template<typename Dest >
EIGEN_DEVICE_FUNC void evalTo (Dest &dst) const
 
template<typename Dest >
EIGEN_DEVICE_FUNC void addTo (Dest &dst) const
 
template<typename Dest >
EIGEN_DEVICE_FUNC void subTo (Dest &dst) const
 
template<typename Dest >
EIGEN_DEVICE_FUNC void applyThisOnTheRight (Dest &dst) const
 
template<typename Dest >
EIGEN_DEVICE_FUNC void applyThisOnTheLeft (Dest &dst) const
 
template<typename Device >
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DeviceWrapper< Derived, Device > device (Device &device)
 
template<typename Device >
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DeviceWrapper< const Derived, Device > device (Device &device) const
 

Protected Member Functions

void computeInPlace ()
 
- Protected Member Functions inherited from Eigen::SolverBase< HouseholderQR< MatrixType_ > >
void _check_solve_assertion (const Rhs &b) const
 

Protected Attributes

MatrixType m_qr
 
HCoeffsType m_hCoeffs
 
RowVectorType m_temp
 
bool m_isInitialized
 

Friends

class SolverBase< HouseholderQR >
 

Detailed Description

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

Householder QR decomposition of a matrix.

Template Parameters
MatrixType_the 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

◆ Base

template<typename MatrixType_ >
typedef SolverBase<HouseholderQR> Eigen::HouseholderQR< MatrixType_ >::Base

◆ HCoeffsType

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

◆ HouseholderSequenceType

template<typename MatrixType_ >
typedef HouseholderSequence<MatrixType, internal::remove_all_t<typename HCoeffsType::ConjugateReturnType> > 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

◆ RowVectorType

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

Member Enumeration Documentation

◆ anonymous enum

template<typename MatrixType_ >
anonymous enum
Enumerator
MaxRowsAtCompileTime 
MaxColsAtCompileTime 
66  {
67  MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
68  MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
69  };
@ MaxRowsAtCompileTime
Definition: HouseholderQR.h:67
@ MaxColsAtCompileTime
Definition: HouseholderQR.h:68

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&).

84 : m_qr(), m_hCoeffs(), m_temp(), m_isInitialized(false) {}
MatrixType m_qr
Definition: HouseholderQR.h:270
HCoeffsType m_hCoeffs
Definition: HouseholderQR.h:271
bool m_isInitialized
Definition: HouseholderQR.h:273
RowVectorType m_temp
Definition: HouseholderQR.h:272

◆ 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()
Index rows() const
Definition: HouseholderQR.h:248
Index cols() const
Definition: HouseholderQR.h:249
#define min(a, b)
Definition: datatypes.h:22

◆ 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);
HouseholderQR< MatrixXf > qr(A)
Eigen::Map< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor >, 0, Eigen::OuterStride<> > matrix(T *data, int rows, int cols, int stride)
Definition: common.h:85
See also
compute()
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) {
113  compute(matrix.derived());
114  }
HouseholderQR & compute(const EigenBase< InputType > &matrix)
Definition: HouseholderQR.h:174

References Eigen::HouseholderQR< MatrixType_ >::compute(), and matrix().

◆ 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&)
125  : m_qr(matrix.derived()),
126  m_hCoeffs((std::min)(matrix.rows(), matrix.cols())),
127  m_temp(matrix.cols()),
128  m_isInitialized(false) {
129  computeInPlace();
130  }
void computeInPlace()
Definition: HouseholderQR.h:507

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

Member Function Documentation

◆ _solve_impl()

template<typename MatrixType_ >
template<typename RhsType , typename DstType >
void Eigen::HouseholderQR< MatrixType_ >::_solve_impl ( const RhsType &  rhs,
DstType &  dst 
) const
467  {
468  const Index rank = (std::min)(rows(), cols());
469 
470  typename RhsType::PlainObject c(rhs);
471 
472  c.applyOnTheLeft(householderQ().setLength(rank).adjoint());
473 
474  m_qr.topLeftCorner(rank, rank).template triangularView<Upper>().solveInPlace(c.topRows(rank));
475 
476  dst.topRows(rank) = c.topRows(rank);
477  dst.bottomRows(cols() - rank).setZero();
478 }
HouseholderSequenceType householderQ() const
Definition: HouseholderQR.h:160
const AdjointReturnType adjoint() const
Definition: SolverBase.h:136
int c
Definition: calibrate.py:100
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:43

References Eigen::SolverBase< HouseholderQR< MatrixType_ > >::adjoint(), calibrate::c, Eigen::HouseholderQR< MatrixType_ >::cols(), Eigen::HouseholderQR< MatrixType_ >::householderQ(), Eigen::HouseholderQR< MatrixType_ >::m_qr, min, and Eigen::HouseholderQR< MatrixType_ >::rows().

◆ _solve_impl_transposed()

template<typename MatrixType_ >
template<bool Conjugate, typename RhsType , typename DstType >
void Eigen::HouseholderQR< MatrixType_ >::_solve_impl_transposed ( const RhsType &  rhs,
DstType &  dst 
) const
482  {
483  const Index rank = (std::min)(rows(), cols());
484 
485  typename RhsType::PlainObject c(rhs);
486 
487  m_qr.topLeftCorner(rank, rank)
488  .template triangularView<Upper>()
489  .transpose()
490  .template conjugateIf<Conjugate>()
491  .solveInPlace(c.topRows(rank));
492 
493  dst.topRows(rank) = c.topRows(rank);
494  dst.bottomRows(rows() - rank).setZero();
495 
496  dst.applyOnTheLeft(householderQ().setLength(rank).template conjugateIf<!Conjugate>());
497 }

References calibrate::c, Eigen::HouseholderQR< MatrixType_ >::cols(), Eigen::HouseholderQR< MatrixType_ >::householderQ(), Eigen::HouseholderQR< MatrixType_ >::m_qr, min, and Eigen::HouseholderQR< MatrixType_ >::rows().

◆ 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. Also, do not rely on the determinant being exactly zero for testing singularity or rank-deficiency.
See also
determinant(), logAbsDeterminant(), MatrixBase::determinant()
319  {
320  using std::abs;
321  eigen_assert(m_isInitialized && "HouseholderQR is not initialized.");
322  eigen_assert(m_qr.rows() == m_qr.cols() && "You can't take the determinant of a non-square matrix!");
323  return abs(m_qr.diagonal().prod());
324 }
AnnoyingScalar abs(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:135
#define eigen_assert(x)
Definition: Macros.h:910

References abs(), eigen_assert, Eigen::HouseholderQR< MatrixType_ >::m_isInitialized, and Eigen::HouseholderQR< MatrixType_ >::m_qr.

◆ cols()

◆ compute()

template<typename MatrixType_ >
template<typename InputType >
HouseholderQR& Eigen::HouseholderQR< MatrixType_ >::compute ( const EigenBase< InputType > &  matrix)
inline

◆ 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&)
507  {
508  Index rows = m_qr.rows();
509  Index cols = m_qr.cols();
510  Index size = (std::min)(rows, cols);
511 
512  m_hCoeffs.resize(size);
513 
514  m_temp.resize(cols);
515 
517 
518  m_isInitialized = true;
519 }
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index size() const EIGEN_NOEXCEPT
Definition: EigenBase.h:64
static void run(MatrixQR &mat, HCoeffs &hCoeffs, Index maxBlockSize=32, typename MatrixQR::Scalar *tempData=0)
Definition: HouseholderQR.h:418

References Eigen::HouseholderQR< MatrixType_ >::cols(), Eigen::HouseholderQR< MatrixType_ >::m_hCoeffs, Eigen::HouseholderQR< MatrixType_ >::m_isInitialized, Eigen::HouseholderQR< MatrixType_ >::m_qr, Eigen::HouseholderQR< MatrixType_ >::m_temp, min, Eigen::HouseholderQR< MatrixType_ >::rows(), Eigen::internal::householder_qr_inplace_blocked< MatrixQR, HCoeffs, MatrixQRScalar, InnerStrideIsOne >::run(), and Eigen::EigenBase< Derived >::size().

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

◆ determinant()

template<typename MatrixType >
MatrixType::Scalar Eigen::HouseholderQR< MatrixType >::determinant
Returns
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. Also, do not rely on the determinant being exactly zero for testing singularity or rank-deficiency.
See also
absDeterminant(), logAbsDeterminant(), MatrixBase::determinant()
310  {
311  eigen_assert(m_isInitialized && "HouseholderQR is not initialized.");
312  eigen_assert(m_qr.rows() == m_qr.cols() && "You can't take the determinant of a non-square matrix!");
313  Scalar detQ;
315  return m_qr.diagonal().prod() * detQ;
316 }
SCALAR Scalar
Definition: bench_gemm.cpp:45
@ IsComplex
Definition: common.h:73
auto run(Kernel kernel, Args &&... args) -> decltype(kernel(args...))
Definition: gpu_test_helper.h:414

References eigen_assert, Eigen::HouseholderQR< MatrixType_ >::m_hCoeffs, Eigen::HouseholderQR< MatrixType_ >::m_isInitialized, Eigen::HouseholderQR< MatrixType_ >::m_qr, and Eigen::run().

◆ hCoeffs()

◆ householderQ()

template<typename MatrixType_ >
HouseholderSequenceType Eigen::HouseholderQR< MatrixType_ >::householderQ ( void  ) 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:

MatrixXf A(MatrixXf::Random(5, 3)), thinQ(MatrixXf::Identity(5, 3)), Q;
A.setRandom();
HouseholderQR<MatrixXf> qr(A);
Q = qr.householderQ();
thinQ = qr.householderQ() * thinQ;
std::cout << "The complete unitary matrix Q is:\n" << Q << "\n\n";
std::cout << "The thin matrix Q is:\n" << thinQ << "\n\n";
MatrixXf Q
Definition: HouseholderQR_householderQ.cpp:1
thinQ
Definition: HouseholderQR_householderQ.cpp:5
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:47

Output:

 
160  {
161  eigen_assert(m_isInitialized && "HouseholderQR is not initialized.");
162  return HouseholderSequenceType(m_qr, m_hCoeffs.conjugate());
163  }
HouseholderSequence< MatrixType, internal::remove_all_t< typename HCoeffsType::ConjugateReturnType > > HouseholderSequenceType
Definition: HouseholderQR.h:76

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

Referenced by Eigen::HouseholderQR< MatrixType_ >::_solve_impl(), Eigen::HouseholderQR< MatrixType_ >::_solve_impl_transposed(), Eigen::createRandomPIMatrixOfRank(), Eigen::RealQZ< MatrixType_ >::hessenbergTriangular(), qr(), randomMatrixWithRealEivals(), randomMatrixWithImagEivals< MatrixType, 0 >::run(), randomMatrixWithImagEivals< MatrixType, 1 >::run(), Eigen::HybridNonLinearSolver< FunctorType, Scalar >::solveNumericalDiffOneStep(), and Eigen::HybridNonLinearSolver< FunctorType, Scalar >::solveOneStep().

◆ 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.
Warning
Do not rely on the determinant being exactly zero for testing singularity or rank-deficiency.
See also
determinant(), absDeterminant(), MatrixBase::determinant()
327  {
328  eigen_assert(m_isInitialized && "HouseholderQR is not initialized.");
329  eigen_assert(m_qr.rows() == m_qr.cols() && "You can't take the determinant of a non-square matrix!");
330  return m_qr.diagonal().cwiseAbs().array().log().sum();
331 }

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

◆ 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.
168  {
169  eigen_assert(m_isInitialized && "HouseholderQR is not initialized.");
170  return m_qr;
171  }

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

Referenced by Eigen::RealQZ< MatrixType_ >::hessenbergTriangular(), qr(), Eigen::HybridNonLinearSolver< FunctorType, Scalar >::solveNumericalDiffOneStep(), and Eigen::HybridNonLinearSolver< FunctorType, Scalar >::solveOneStep().

◆ rows()

◆ signDeterminant()

template<typename MatrixType >
MatrixType::Scalar Eigen::HouseholderQR< MatrixType >::signDeterminant
Returns
the sign 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.
Warning
Do not rely on the determinant being exactly zero for testing singularity or rank-deficiency.
See also
determinant(), absDeterminant(), MatrixBase::determinant()
334  {
335  eigen_assert(m_isInitialized && "HouseholderQR is not initialized.");
336  eigen_assert(m_qr.rows() == m_qr.cols() && "You can't take the determinant of a non-square matrix!");
337  Scalar detQ;
339  return detQ * m_qr.diagonal().array().sign().prod();
340 }

References eigen_assert, Eigen::HouseholderQR< MatrixType_ >::m_hCoeffs, Eigen::HouseholderQR< MatrixType_ >::m_isInitialized, Eigen::HouseholderQR< MatrixType_ >::m_qr, and Eigen::run().

Friends And Related Function Documentation

◆ SolverBase< HouseholderQR >

template<typename MatrixType_ >
friend class SolverBase< HouseholderQR >
friend

Member Data Documentation

◆ m_hCoeffs

◆ 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: