cisst-saw
Loading...
Searching...
No Matches
nmrLUSolver Class Reference

#include <nmrLUSolver.h>

Public Member Functions

 nmrLUSolver (void)
 nmrLUSolver (CISSTNETLIB_INTEGER m, CISSTNETLIB_INTEGER n, bool allocateLU=false, bool allocateP=false)
Constructor with memory allocation.

This constructor allocates the memory based on the actual input of the Solve() method. It relies on the method Allocate(). The next call to the Solve() method will check that the input matches the dimension.

Parameters
AThe matrix to be factorized (or any matrix of the same size)
allocateLUAllocates memory to maintain a usable copy of L and U
allocatePAllocates memory to maintain a usable copy of P
 nmrLUSolver (const vctDynamicMatrix< CISSTNETLIB_DOUBLE > &A, bool allocateLU=false, bool allocateP=false)
template<vct::size_type _rows, vct::size_type _cols>
 nmrLUSolver (const vctFixedSizeMatrix< CISSTNETLIB_DOUBLE, _rows, _cols, VCT_COL_MAJOR > &A, bool allocateLU=false, bool allocateP=false)
void Allocate (CISSTNETLIB_INTEGER m, CISSTNETLIB_INTEGER n, bool allocateLU=false, bool allocateP=false)
Allocate memory to solve this problem.

This method provides a convenient way to extract the required sizes from the input containers. The next call to the Solve() method will check that the input matches the dimension.

Parameters
AThe matrix to be factorized (or any matrix of the same size)
allocateLUAllocates memory to maintain a usable copy of L and U
allocatePAllocates memory to maintain a usable copy of P
void Allocate (const vctDynamicMatrix< CISSTNETLIB_DOUBLE > &A, bool allocateLU=false, bool allocateP=false)
template<vct::size_type _rows, vct::size_type _cols>
void Allocate (const vctFixedSizeMatrix< CISSTNETLIB_DOUBLE, _rows, _cols, VCT_COL_MAJOR > &A, bool allocateLU=false, bool allocateP=false)
template<class _matrixOwnerType>
void Solve (vctDynamicMatrixBase< _matrixOwnerType, CISSTNETLIB_DOUBLE > &A) throw (std::runtime_error)
template<vct::size_type _rows, vct::size_type _cols>
void Solve (vctFixedSizeMatrix< CISSTNETLIB_DOUBLE, _rows, _cols, VCT_COL_MAJOR > &A)
const vctDynamicVector< CISSTNETLIB_INTEGER > & GetIpiv (void) const
CISSTNETLIB_INTEGER GetInfo (void) const
const vctDynamicMatrix< CISSTNETLIB_DOUBLE > & GetP (void) const throw (std::runtime_error)
const vctDynamicMatrix< CISSTNETLIB_DOUBLE > & GetL (void) const throw (std::runtime_error)
const vctDynamicMatrix< CISSTNETLIB_DOUBLE > & GetU (void) const throw (std::runtime_error)

Protected Member Functions

void AllocateP (void)
void AllocateLU (void)
template<class _matrixOwnerType>
void UpdateLU (const vctDynamicConstMatrixBase< _matrixOwnerType, CISSTNETLIB_DOUBLE > &A)
void UpdateP (void)

Protected Attributes

CISSTNETLIB_INTEGER M
CISSTNETLIB_INTEGER N
CISSTNETLIB_INTEGER Lda
CISSTNETLIB_INTEGER MinMN
CISSTNETLIB_INTEGER MaxMN
vctDynamicVector< CISSTNETLIB_INTEGER > Ipiv
CISSTNETLIB_INTEGER Info
bool AllocatePFlag
bool AllocateLUFlag
vctDynamicMatrix< CISSTNETLIB_DOUBLE > P
vctDynamicMatrix< CISSTNETLIB_DOUBLE > L
vctDynamicMatrix< CISSTNETLIB_DOUBLE > U

Detailed Description

Algorithm LU: LU factorization of a general M by N matrix

The class is a wrapper for the LAPACK function dgetrf. It computes an LU factorization of a general M-by-N matrix A using partial pivoting with row interchanges.

The factorization has the form \( A = P * L * U \) where P is a permutation matrix, L is lower triangular with unit diagonal elements (lower trapezoidal if m > n), and U is upper triangular (upper trapezoidal if m < n).

The data members of this class are:

  • M: The number of rows of the input matrix A. M >= 0.
  • N: The number of columns of the input matrix A. N >= 0.
  • Lda: The leading dimension of the array A. \( Lda \geq \mbox{max}(1,M) \).
  • MinMN: Lenght of diagonal \( MinMN = \mbox{min}(M,N)\)
  • Ipiv: The pivot indices, from 1 to min(M, N).

The LAPACK function modifies the input matrix in place. The matrices L and U are stored in the same place which is pretty inconvenient to use. To reconstruct both L and U, the user can set the AllocateLU flag to true. This will allocate the correct amount of memory for L and U and the method UpdateLU will run automatically after each Solve.

Similarly, the flag AllocateP will allocate some extra memory and built the permutation matrix P based on the pivots used (IPiv).

Note
The input matrices of this class must be column major. To select the storage order, use VCT_COL_MAJOR whenever you declare a matrix.
The input matrix must be compact (see vctDynamicMatrix::IsCompact() or vctFixedSizeMatrix::IsCompact()).
This code relies on the ERC CISST cnetlib library. Since cnetlib is optional, make sure that CISST_HAS_CNETLIB has been turned ON during the configuration with CMake.
Deprecated
This class has been replaced by nmrLU, nmrLUDynamicData and nmrLUFixedSizeData.

Constructor & Destructor Documentation

◆ nmrLUSolver() [1/4]

nmrLUSolver::nmrLUSolver ( void )
inline

Default constructor. This constructor doesn't allocate any memory. If you use this constructor, you will need to use one of the Allocate() methods before you can use the Solve method.

◆ nmrLUSolver() [2/4]

nmrLUSolver::nmrLUSolver ( CISSTNETLIB_INTEGER m,
CISSTNETLIB_INTEGER n,
bool allocateLU = false,
bool allocateP = false )
inline

Constructor with memory allocation. This constructor allocates the memory based on M and N. It relies on the method Allocate(). The next call to the Solve() method will check that the input matches the dimension.

Parameters
mNumber of rows of A
nNumber of columns of A
allocateLUAllocates memory to maintain a usable copy of L and U
allocatePAllocates memory to maintain a usable copy of P

◆ nmrLUSolver() [3/4]

nmrLUSolver::nmrLUSolver ( const vctDynamicMatrix< CISSTNETLIB_DOUBLE > & A,
bool allocateLU = false,
bool allocateP = false )
inline

◆ nmrLUSolver() [4/4]

template<vct::size_type _rows, vct::size_type _cols>
nmrLUSolver::nmrLUSolver ( const vctFixedSizeMatrix< CISSTNETLIB_DOUBLE, _rows, _cols, VCT_COL_MAJOR > & A,
bool allocateLU = false,
bool allocateP = false )
inline

Member Function Documentation

◆ Allocate() [1/3]

void nmrLUSolver::Allocate ( CISSTNETLIB_INTEGER m,
CISSTNETLIB_INTEGER n,
bool allocateLU = false,
bool allocateP = false )
inline

This method allocates the memory based on M and N. The next call to the Solve() method will check that the input matches the dimension.

Parameters
mNumber of rows of A
nNumber of columns of A
allocateLUAllocates memory to maintain a usable copy of L and U
allocatePAllocates memory to maintain a usable copy of P

◆ Allocate() [2/3]

void nmrLUSolver::Allocate ( const vctDynamicMatrix< CISSTNETLIB_DOUBLE > & A,
bool allocateLU = false,
bool allocateP = false )
inline

◆ Allocate() [3/3]

template<vct::size_type _rows, vct::size_type _cols>
void nmrLUSolver::Allocate ( const vctFixedSizeMatrix< CISSTNETLIB_DOUBLE, _rows, _cols, VCT_COL_MAJOR > & A,
bool allocateLU = false,
bool allocateP = false )
inline

◆ AllocateLU()

void nmrLUSolver::AllocateLU ( void )
inlineprotected

Allocates memory for usable copies of L and U.

◆ AllocateP()

void nmrLUSolver::AllocateP ( void )
inlineprotected

Allocates memory for the permutation matrix P.

◆ GetInfo()

CISSTNETLIB_INTEGER nmrLUSolver::GetInfo ( void ) const
inline

The status returned by the dgetrf function.

◆ GetIpiv()

const vctDynamicVector< CISSTNETLIB_INTEGER > & nmrLUSolver::GetIpiv ( void ) const
inline

Get the vector of pivots. Since the pivots are defined in Fortran, they go from 1 to \(min(M, N)\) included. To use these as C/C++ values, subtract 1.

◆ GetL()

const vctDynamicMatrix< CISSTNETLIB_DOUBLE > & nmrLUSolver::GetL ( void ) const
throw (std::runtime_error )
inline

Get the L matrix calculated from the output of the dgetrf function .

◆ GetP()

const vctDynamicMatrix< CISSTNETLIB_DOUBLE > & nmrLUSolver::GetP ( void ) const
throw (std::runtime_error )
inline

Get the permutation matrix calculated based on IPiv.

◆ GetU()

const vctDynamicMatrix< CISSTNETLIB_DOUBLE > & nmrLUSolver::GetU ( void ) const
throw (std::runtime_error )
inline

Get the U matrix calculated from the output of the dgetrf function .

◆ Solve() [1/2]

template<class _matrixOwnerType>
void nmrLUSolver::Solve ( vctDynamicMatrixBase< _matrixOwnerType, CISSTNETLIB_DOUBLE > & A)
throw (std::runtime_error )
inline

Performs the factorization. The result is stored in the modified input and the data member IPiv (vector of pivots).

To get a more convenient representation of the results, use turn allocateLU to true with Allocate() or the constructor. This method will then update the data members L and U (matrices). Then, one can use GetL and GetU to retrieve their content. Similarly, if one needs the complete factorization as \( P * L U \), the matrix P can be obtained when allocateP is set with the method GetP.

Note
This method requires a compact matrix with column major storage order. The size must match the dimension passed to the Allocate method or the constructor. An std::runtime_error exception will be thrown if these conditions are not met.

◆ Solve() [2/2]

template<vct::size_type _rows, vct::size_type _cols>
void nmrLUSolver::Solve ( vctFixedSizeMatrix< CISSTNETLIB_DOUBLE, _rows, _cols, VCT_COL_MAJOR > & A)
inline

◆ UpdateLU()

template<class _matrixOwnerType>
void nmrLUSolver::UpdateLU ( const vctDynamicConstMatrixBase< _matrixOwnerType, CISSTNETLIB_DOUBLE > & A)
inlineprotected

Update the content of the optional matrices L and U based on the matrix returned by the LAPACK function dgetrf.

◆ UpdateP()

void nmrLUSolver::UpdateP ( void )
inlineprotected

Update the content of the optional permutation matrix P based on the pivot vector IPiv.

Member Data Documentation

◆ AllocateLUFlag

bool nmrLUSolver::AllocateLUFlag
protected

◆ AllocatePFlag

bool nmrLUSolver::AllocatePFlag
protected

◆ Info

CISSTNETLIB_INTEGER nmrLUSolver::Info
protected

◆ Ipiv

vctDynamicVector<CISSTNETLIB_INTEGER> nmrLUSolver::Ipiv
protected

◆ L

vctDynamicMatrix<CISSTNETLIB_DOUBLE> nmrLUSolver::L
protected

◆ Lda

CISSTNETLIB_INTEGER nmrLUSolver::Lda
protected

◆ M

CISSTNETLIB_INTEGER nmrLUSolver::M
protected

◆ MaxMN

CISSTNETLIB_INTEGER nmrLUSolver::MaxMN
protected

◆ MinMN

CISSTNETLIB_INTEGER nmrLUSolver::MinMN
protected

◆ N

CISSTNETLIB_INTEGER nmrLUSolver::N
protected

◆ P

vctDynamicMatrix<CISSTNETLIB_DOUBLE> nmrLUSolver::P
protected

◆ U

vctDynamicMatrix<CISSTNETLIB_DOUBLE> nmrLUSolver::U
protected

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