STK++ 0.9.13
STK::lapack::Qr Class Reference

{ More...

#include <STK_lapack_Qr.h>

Inheritance diagram for STK::lapack::Qr:
Inheritance graph

Public Types

typedef IQr< QrBase
 

Public Member Functions

 Qr (ArrayXX const &data, bool ref=false)
 Default constructor.
 
template<class Derived >
 Qr (ArrayBase< Derived > const &data)
 Constructor.
 
 Qr (Qr const &decomp)
 Copy constructor.
 
virtual ~Qr ()
 virtual destructor
 
virtual Qrclone () const
 clone pattern
 
Qroperator= (Qr const &decomp)
 Operator = : overwrite the Qr with decomp.
 
bool runImpl ()
 Run qr decomposition Launch geqrf LAPACK routine to perform the qr decomposition.
 
- Public Member Functions inherited from STK::IQr< Qr >
virtual ~IQr ()
 virtual destructor
 
IQroperator= (IQr const &decomp)
 Operator = : overwrite the this with decomp.
 
bool isCompQ () const
 
int rank () const
 
Array constQ () const
 give the matrix Q of the QR decomposition.
 
ArrayUpperTriangularXX constR () const
 give the matrix R of the QR decomposition.
 
void setCompQ (bool compq)
 Set the compq_ flag.
 
virtual bool run ()
 Compute the QR decomposition.
 
void compQ ()
 Compute Q (to use after run).
 
void popBackCols (int n=1)
 Delete the n last columns and update the QR decomposition.
 
void eraseCol (int pos)
 Delete the column pos and update the QR decomposition.
 
void pushBackCol (ColVector_ const &T)
 Add a column with value T and update th QR decomposition.
 
void insertCol (ColVector_ const &T, int pos)
 Add a column with value T at the position pos and update the QR decomposition.
 
void setData (ExprBase< OtherDerived > const &data)
 overloading of setData.
 
- Public Member Functions inherited from STK::IRunnerBase
String consterror () const
 get the last error message.
 
- Public Member Functions inherited from STK::IRecursiveTemplate< Derived >
Derived & asDerived ()
 static cast : return a reference of this with a cast to the derived class.
 
Derived constasDerived () const
 static cast : return a const reference of this with a cast to the derived class.
 
Derived * asPtrDerived ()
 static cast : return a ptr on a Derived of this with a cast to the derived class.
 
Derived constasPtrDerived () const
 static cast : return a ptr on a constant Derived of this with a cast to the derived class.
 
Derived * clone () const
 create a leaf using the copy constructor of the Derived class.
 
Derived * clone (bool isRef) const
 create a leaf using the copy constructor of the Derived class and a flag determining if the clone is a reference or not.
 

Private Member Functions

bool computeQr (CArrayXX &a, CVectorX &tau)
 private method for computing the Qr decomposition using a CArrayXX array
 

Additional Inherited Members

- Protected Types inherited from STK::IQr< Qr >
typedef hidden::AlgebraTraits< Qr >::Array Array
 
typedef hidden::AlgebraTraits< Qr >::ColVector ColVector
 
typedef hidden::AlgebraTraits< Qr >::RowVector RowVector
 
- Protected Member Functions inherited from STK::IQr< Qr >
 IQr (Array const &Q, bool ref=false)
 Constructor.
 
 IQr (ExprBase< DerivedExpr > const &Q)
 Constructor.
 
 IQr (IQr const &decomp)
 Copy constructor.
 
- Protected Member Functions inherited from STK::IRunnerBase
 IRunnerBase ()
 default constructor
 
 IRunnerBase (IRunnerBase const &runner)
 copy constructor
 
virtual ~IRunnerBase ()
 destructor
 
virtual void update ()
 update the runner.
 
- Protected Member Functions inherited from STK::IRecursiveTemplate< Derived >
 IRecursiveTemplate ()
 constructor.
 
 ~IRecursiveTemplate ()
 destructor.
 
- Protected Attributes inherited from STK::IQr< Qr >
Array Q_
 Q Array of the QR decomposition.
 
ArrayUpperTriangularXX R_
 R Array of th QR decomposition.
 
bool compq_
 is Q computed ?
 
int rank_
 estimated rank_ of the matrix A
 
- Protected Attributes inherited from STK::IRunnerBase
String msg_error_
 String with the last error message.
 
bool hasRun_
 true if run has been used, false otherwise
 

Detailed Description

{

Qr computes the QR decomposition of a real matrix using the Lapack routine *geqrf.

  • Input: A matrix (nrow,ncol)
  • Output:

    1. Q matrix (nrow,ncol) with the Housholder vectors in the min(nrow, ncol) first columns.
    2. R matrix (nrow,ncol) upper triangular.
    See also
    STK::IQr

Definition at line 87 of file STK_lapack_Qr.h.

Member Typedef Documentation

◆ Base

Definition at line 90 of file STK_lapack_Qr.h.

Constructor & Destructor Documentation

◆ Qr() [1/3]

STK::lapack::Qr::Qr ( ArrayXX const data,
bool  ref = false 
)
inline

Default constructor.

Parameters
datathe matrix to decompose
reftrue if we overwrite A

Definition at line 97 of file STK_lapack_Qr.h.

97: Base(data, ref) {}

◆ Qr() [2/3]

template<class Derived >
STK::lapack::Qr::Qr ( ArrayBase< Derived > const data)
inline

Constructor.

Parameters
datareference on a matrix expression

Definition at line 102 of file STK_lapack_Qr.h.

102: Base(data){}

◆ Qr() [3/3]

STK::lapack::Qr::Qr ( Qr const decomp)
inline

Copy constructor.

Parameters
decompthe decomposition to copy

Definition at line 106 of file STK_lapack_Qr.h.

106: Base(decomp) {}

◆ ~Qr()

virtual STK::lapack::Qr::~Qr ( )
inlinevirtual

virtual destructor

Definition at line 108 of file STK_lapack_Qr.h.

108{}

Member Function Documentation

◆ clone()

virtual Qr * STK::lapack::Qr::clone ( ) const
inlinevirtual

clone pattern

Definition at line 110 of file STK_lapack_Qr.h.

110{ return new Qr(*this);}
Qr(ArrayXX const &data, bool ref=false)
Default constructor.

◆ computeQr()

bool STK::lapack::Qr::computeQr ( CArrayXX a,
CVectorX tau 
)
inlineprivate

private method for computing the Qr decomposition using a CArrayXX array

Definition at line 130 of file STK_lapack_Qr.h.

131{
132 // start qr iterations
133 int lWork =-1, m = a.sizeRows(), n= a.sizeCols();
134 int info;
135 Real iwork;
136 Real *p_work;
137
138 // get size for work
139 info = geqrf(m, n, a.p_data(), m, tau.p_data(), &iwork, lWork);
140 // check any error
141 if (info!=0)
142 {
143 if (info>0)
145 return false;
146 }
147 this->msg_error_= STKERROR_1ARG(lapack::Qr::computeQr get,-info,error parameter);
148 return false;
149 }
150 // create
151 lWork = (int)iwork;
152 p_work = new Real[lWork];
153 info = geqrf(m, n, a.p_data(), m, tau.p_data(), p_work, lWork);
154 // release working set
155 delete[] p_work;
156 // check any error
157 if (info!=0)
158 {
159 if (info>0)
161 return false;
162 }
163 this->msg_error_= STKERROR_1ARG(lapack::Qr::computeQr get,-info,error parameter);
164 return false;
165 }
166 return true;
167}
#define STKERROR_NO_ARG(Where, Error)
Definition STK_Macros.h:49
#define STKERROR_1ARG(Where, Arg, Error)
Definition STK_Macros.h:61
String msg_error_
String with the last error message.
Definition STK_IRunner.h:96
String const & error() const
get the last error message.
Definition STK_IRunner.h:82
bool computeQr(CArrayXX &a, CVectorX &tau)
private method for computing the Qr decomposition using a CArrayXX array
int geqrf(int m, int n, Real *a, int lda, Real *tau, Real *work, int lWork)
wrapper of the LAPACK DGEQRF routine: computes the Qr decomposition of a matrix.
double Real
STK fundamental type of Real values.

References computeQr(), STK::IRunnerBase::error(), STK::lapack::geqrf(), STK::IRunnerBase::msg_error_, STK::ICArray< Derived >::p_data(), STKERROR_1ARG, and STKERROR_NO_ARG.

Referenced by computeQr(), and runImpl().

◆ operator=()

Qr & STK::lapack::Qr::operator= ( Qr const decomp)
inline

Operator = : overwrite the Qr with decomp.

Definition at line 112 of file STK_lapack_Qr.h.

113 {
114 Base::operator =(decomp);
115 return *this;
116 }
IQr & operator=(IQr const &decomp)
Operator = : overwrite the this with decomp.
Definition STK_IQr.h:139

References STK::IQr< Qr >::operator=().

◆ runImpl()

bool STK::lapack::Qr::runImpl ( )
inline

Run qr decomposition Launch geqrf LAPACK routine to perform the qr decomposition.

Returns
true if no error occur, false otherwise

Definition at line 169 of file STK_lapack_Qr.h.

170{
171 int begin = Q_.beginRows(); // same first index checked at construction of QR
172 int end = std::min(Q_.endRows(), Q_.endCols());
173 // compute results
174 CArrayXX a = Q_;
175 CVectorX tau(std::min(Q_.sizeRows(), Q_.sizeCols()));
176 a.shift(0, 0);
177 tau.shift(0);
178 if (!computeQr(a, tau)) { return false;};
179 // get results
180 a.shift(begin, begin);
181 tau.shift(begin);
182 R_.resize(Q_.rows(), Q_.cols());
183 for (int i=Q_.beginRows(); i< Q_.endRows(); ++i)
184 {
185 int jmax = std::min(i, Q_.endCols());
186 for (int j=Q_.beginCols(); j< jmax; ++j) { Q_(i,j) = a(i,j);}
187 for (int j=i; j< Q_.endCols(); ++j) { R_(i,j) = a(i,j);}
188 }
189 for (int j=Q_.beginCols(); j<end; ++j) { Q_(j,j) = -tau[j];}
190 return true;
191}
Derived & resize(Range const &I, Range const &J)
resize the array.
ArrayUpperTriangularXX R_
R Array of th QR decomposition.
Definition STK_IQr.h:219
Array Q_
Q Array of the QR decomposition.
Definition STK_IQr.h:217
CArray< Real, UnknownSize, UnknownSize, Arrays::by_col_ > CArrayXX
Definition STK_CArray.h:50
CArrayVector< Real, UnknownSize, Arrays::by_col_ > CVectorX

References computeQr(), STK::IQr< Qr >::Q_, STK::IQr< Qr >::R_, STK::IArray2D< Derived >::resize(), and STK::ICArray< Derived >::shift().


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