Teuchos - Trilinos Tools Package Version of the Day
Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType > Class Template Reference

A class for solving dense linear problems. More...

`#include <Teuchos_SerialQRDenseSolver.hpp>`

Inheritance diagram for Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >:

List of all members.

## Public Member Functions

Constructor/Destructor Methods
SerialQRDenseSolver ()
Default constructor; matrix should be set using setMatrix(), LHS and RHS set with setVectors().
virtual ~SerialQRDenseSolver ()
SerialQRDenseSolver destructor.
Set Methods
int setMatrix (const RCP< SerialDenseMatrix< OrdinalType, ScalarType > > &A)
Sets the pointers for coefficient matrix.
int setVectors (const RCP< SerialDenseMatrix< OrdinalType, ScalarType > > &X, const RCP< SerialDenseMatrix< OrdinalType, ScalarType > > &B)
Sets the pointers for left and right hand side vector(s).
Strategy Modifying Methods
void factorWithEquilibration (bool flag)
Causes equilibration to be called just before the matrix factorization as part of the call to `factor`.
void solveWithTranspose (bool flag)
If `flag` is true, causes all subsequent function calls to work with the adjoint of this matrix, otherwise not.
void solveWithTransposeFlag (Teuchos::ETransp trans)
All subsequent function calls will work with the transpose-type set by this method (`Teuchos::NO_TRANS` or Teuchos::CONJ_TRANS).
Factor/Solve/Invert Methods
int factor ()
Computes the in-place QR factorization of the matrix using the LAPACK routine _GETRF or the Eigen class HouseholderQR.
int solve ()
Computes the solution X to AX = B for the this matrix and the B provided to SetVectors()..
int computeEquilibrateScaling ()
Determines if this matrix should be scaled.
int equilibrateMatrix ()
Equilibrates the this matrix.
int equilibrateRHS ()
Equilibrates the current RHS.
int unequilibrateLHS ()
Unscales the solution vectors if equilibration was used to solve the system.
int formQ ()
Explicitly forms the unitary matrix Q.
int formR ()
Explicitly forms the upper triangular matrix R.
int multiplyQ (ETransp transq, SerialDenseMatrix< OrdinalType, ScalarType > &C)
Left multiply the input matrix by the unitary matrix Q or its adjoint.
int solveR (ETransp transr, SerialDenseMatrix< OrdinalType, ScalarType > &C)
Solve input matrix on the left with the upper triangular matrix R or its adjoint.
Query methods
bool transpose ()
Returns true if adjoint of this matrix has and will be used.
bool factored ()
Returns true if matrix is factored (factor available via getFactoredMatrix()).
bool equilibratedA ()
Returns true if factor is equilibrated (factor available via getFactoredMatrix()).
bool equilibratedB ()
Returns true if RHS is equilibrated (RHS available via getRHS()).
bool shouldEquilibrate ()
Returns true if the LAPACK general rules for equilibration suggest you should equilibrate the system.
bool solved ()
Returns true if the current set of vectors has been solved.
bool formedQ ()
Returns true if Q has been formed explicitly.
bool formedR ()
Returns true if R has been formed explicitly.
Data Accessor methods
RCP< SerialDenseMatrix
< OrdinalType, ScalarType > >
getMatrix () const
Returns pointer to current matrix.
RCP< SerialDenseMatrix
< OrdinalType, ScalarType > >
getFactoredMatrix () const
Returns pointer to factored matrix (assuming factorization has been performed).
RCP< SerialDenseMatrix
< OrdinalType, ScalarType > >
getQ () const
Returns pointer to Q (assuming factorization has been performed).
RCP< SerialDenseMatrix
< OrdinalType, ScalarType > >
getR () const
Returns pointer to R (assuming factorization has been performed).
RCP< SerialDenseMatrix
< OrdinalType, ScalarType > >
getLHS () const
Returns pointer to current LHS.
RCP< SerialDenseMatrix
< OrdinalType, ScalarType > >
getRHS () const
Returns pointer to current RHS.
OrdinalType numRows () const
Returns row dimension of system.
OrdinalType numCols () const
Returns column dimension of system.
std::vector< ScalarType > tau () const
Returns pointer to pivot vector (if factorization has been computed), zero otherwise.
MagnitudeType ANORM () const
Returns the absolute value of the largest element of this matrix (returns -1 if not yet computed).
I/O methods
void Print (std::ostream &os) const
Print service methods; defines behavior of ostream << operator.

## Detailed Description

### template<typename OrdinalType, typename ScalarType> class Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >

A class for solving dense linear problems.

The Teuchos::SerialQRDenseSolver class enables the definition, in terms of Teuchos::SerialDenseMatrix and Teuchos::SerialDenseVector objects, of a dense linear problem, followed by the solution of that problem via the most sophisticated techniques available in LAPACK.

The Teuchos::SerialQRDenseSolver class is intended to provide full-featured support for solving linear problems for general dense rectangular (or square) matrices. It is written on top of BLAS and LAPACK and thus has excellent performance and numerical capabilities. Using this class, one can either perform simple factorizations and solves or apply all the tricks available in LAPACK to get the best possible solution for very ill-conditioned problems.

Teuchos::SerialQRDenseSolver vs. Teuchos::LAPACK

The Teuchos::LAPACK class provides access to most of the same functionality as Teuchos::SerialQRDenseSolver. The primary difference is that Teuchos::LAPACK is a "thin" layer on top of LAPACK and Teuchos::SerialQRDenseSolver attempts to provide easy access to the more sophisticated aspects of solving dense linear and eigensystems.

Constructing Teuchos::SerialQRDenseSolver Objects

There is a single Teuchos::SerialQRDenseSolver constructor. However, the matrix, right hand side and solution vectors must be set prior to executing most methods in this class.

Setting vectors used for linear solves

The matrix A, the left hand side X and the right hand side B (when solving AX = B, for X), can be set by appropriate set methods. Each of these three objects must be an Teuchos::SerialDenseMatrix or and Teuchos::SerialDenseVector object. The set methods are as follows:

Vector and Utility Functions

Once a Teuchos::SerialQRDenseSolver is constructed, several mathematical functions can be applied to the object. Specifically:

• Factorizations.
• Solves.
• Equilibration.
• Norms.

Strategies for Solving Linear Systems In many cases, linear least squares systems can be accurately solved by simply computing the QR factorization of the matrix and then performing a forward back solve with a given set of right hand side vectors. However, in some instances, the factorization may be very poorly conditioned and this simple approach may not work. In these situations, equilibration and iterative refinement may improve the accuracy, or prevent a breakdown in the factorization.

Teuchos::SerialQRDenseSolver will use equilibration with the factorization if, once the object is constructed and before it is factored, you call the function factorWithEquilibration(true) to force equilibration to be used. If you are uncertain if equilibration should be used, you may call the function shouldEquilibrate() which will return true if equilibration could possibly help. shouldEquilibrate() uses guidelines specified in the LAPACK User Guide to determine if equilibration might be useful.

Examples using Teuchos::SerialQRDenseSolver can be found in the Teuchos test directories.

Definition at line 132 of file Teuchos_SerialQRDenseSolver.hpp.

## Constructor & Destructor Documentation

template<typename OrdinalType , typename ScalarType >
 Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::SerialQRDenseSolver ( )

Default constructor; matrix should be set using setMatrix(), LHS and RHS set with setVectors().

Definition at line 400 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::~SerialQRDenseSolver ( ) ` [virtual]`

SerialQRDenseSolver destructor.

Definition at line 437 of file Teuchos_SerialQRDenseSolver.hpp.

## Member Function Documentation

template<typename OrdinalType , typename ScalarType >
 int Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::setMatrix ( const RCP< SerialDenseMatrix< OrdinalType, ScalarType > > & A )

Sets the pointers for coefficient matrix.

Row dimension of A must be greater than or equal to the column dimension of A.

Definition at line 483 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 int Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::setVectors ( const RCP< SerialDenseMatrix< OrdinalType, ScalarType > > & X, const RCP< SerialDenseMatrix< OrdinalType, ScalarType > > & B )

Sets the pointers for left and right hand side vector(s).

Row dimension of X must match column dimension of matrix A, row dimension of B must match row dimension of A.

Definition at line 510 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 void Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::factorWithEquilibration ( bool flag ) ` [inline]`

Causes equilibration to be called just before the matrix factorization as part of the call to `factor`.

Note:
This method must be called before the factorization is performed, otherwise it will have no effect.

Definition at line 186 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 void Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::solveWithTranspose ( bool flag ) ` [inline]`

If `flag` is true, causes all subsequent function calls to work with the adjoint of this matrix, otherwise not.

Definition at line 189 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 void Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::solveWithTransposeFlag ( Teuchos::ETransp trans ) ` [inline]`

All subsequent function calls will work with the transpose-type set by this method (`Teuchos::NO_TRANS` or Teuchos::CONJ_TRANS).

Definition at line 192 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 int Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::factor ( )

Computes the in-place QR factorization of the matrix using the LAPACK routine _GETRF or the Eigen class HouseholderQR.

Returns:
Integer error code, set to 0 if successful.

Definition at line 534 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 int Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::solve ( )

Computes the solution X to AX = B for the this matrix and the B provided to SetVectors()..

Returns:
Integer error code, set to 0 if successful.

Definition at line 576 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 int Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::computeEquilibrateScaling ( )

Determines if this matrix should be scaled.

Returns:
Integer error code, set to 0 if successful.

Definition at line 662 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 int Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::equilibrateMatrix ( )

Equilibrates the this matrix.

Note:
This method will be called automatically in solve() method if factorWithEquilibration( true ) is called.
Returns:
Integer error code, set to 0 if successful.

Definition at line 701 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 int Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::equilibrateRHS ( )

Equilibrates the current RHS.

Note:
This method will be called automatically in solve() method if factorWithEquilibration( true ) is called.
Returns:
Integer error code, set to 0 if successful.

Definition at line 747 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 int Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::unequilibrateLHS ( )

Unscales the solution vectors if equilibration was used to solve the system.

Note:
This method will be called automatically in solve() method if factorWithEquilibration( true ) is called.
Returns:
Integer error code, set to 0 if successful.

Definition at line 793 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 int Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::formQ ( )

Explicitly forms the unitary matrix Q.

Returns:
Integer error code, set to 0 if successful.

Definition at line 830 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 int Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::formR ( )

Explicitly forms the upper triangular matrix R.

Returns:
Integer error code, set to 0 if successful.

Definition at line 867 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 int Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::multiplyQ ( ETransp transq, SerialDenseMatrix< OrdinalType, ScalarType > & C )

Left multiply the input matrix by the unitary matrix Q or its adjoint.

Returns:
Integer error code, set to 0 if successful.

Definition at line 894 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 int Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::solveR ( ETransp transr, SerialDenseMatrix< OrdinalType, ScalarType > & C )

Solve input matrix on the left with the upper triangular matrix R or its adjoint.

Returns:
Integer error code, set to 0 if successful.

Definition at line 955 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 bool Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::transpose ( ) ` [inline]`

Returns true if adjoint of this matrix has and will be used.

Definition at line 267 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 bool Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::factored ( ) ` [inline]`

Returns true if matrix is factored (factor available via getFactoredMatrix()).

Definition at line 270 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 bool Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::equilibratedA ( ) ` [inline]`

Returns true if factor is equilibrated (factor available via getFactoredMatrix()).

Definition at line 273 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 bool Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::equilibratedB ( ) ` [inline]`

Returns true if RHS is equilibrated (RHS available via getRHS()).

Definition at line 276 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 bool Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::shouldEquilibrate ( ) ` [inline]`

Returns true if the LAPACK general rules for equilibration suggest you should equilibrate the system.

Definition at line 279 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 bool Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::solved ( ) ` [inline]`

Returns true if the current set of vectors has been solved.

Definition at line 282 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 bool Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::formedQ ( ) ` [inline]`

Returns true if Q has been formed explicitly.

Definition at line 285 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 bool Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::formedR ( ) ` [inline]`

Returns true if R has been formed explicitly.

Definition at line 288 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 RCP > Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::getMatrix ( ) const` [inline]`

Returns pointer to current matrix.

Definition at line 296 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 RCP > Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::getFactoredMatrix ( ) const` [inline]`

Returns pointer to factored matrix (assuming factorization has been performed).

Definition at line 299 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 RCP > Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::getQ ( ) const` [inline]`

Returns pointer to Q (assuming factorization has been performed).

Definition at line 302 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 RCP > Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::getR ( ) const` [inline]`

Returns pointer to R (assuming factorization has been performed).

Definition at line 305 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 RCP > Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::getLHS ( ) const` [inline]`

Returns pointer to current LHS.

Definition at line 308 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 RCP > Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::getRHS ( ) const` [inline]`

Returns pointer to current RHS.

Definition at line 311 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 OrdinalType Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::numRows ( ) const` [inline]`

Returns row dimension of system.

Definition at line 314 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 OrdinalType Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::numCols ( ) const` [inline]`

Returns column dimension of system.

Definition at line 317 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 std::vector Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::tau ( ) const` [inline]`

Returns pointer to pivot vector (if factorization has been computed), zero otherwise.

Definition at line 320 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 MagnitudeType Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::ANORM ( ) const` [inline]`

Returns the absolute value of the largest element of this matrix (returns -1 if not yet computed).

Definition at line 323 of file Teuchos_SerialQRDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
 void Teuchos::SerialQRDenseSolver< OrdinalType, ScalarType >::Print ( std::ostream & os ) const

Print service methods; defines behavior of ostream << operator.

Definition at line 1017 of file Teuchos_SerialQRDenseSolver.hpp.

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