Public Member Functions | Private Attributes

LAPACKFullMatrix< number > Class Template Reference
[Basic matrices]

Inheritance diagram for LAPACKFullMatrix< number >:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 LAPACKFullMatrix (const unsigned int n=0)
 LAPACKFullMatrix (const unsigned int rows, const unsigned int cols)
 LAPACKFullMatrix (const LAPACKFullMatrix &)
LAPACKFullMatrix< number > & operator= (const LAPACKFullMatrix< number > &)
template<typename number2 >
LAPACKFullMatrix< number > & operator= (const FullMatrix< number2 > &)
LAPACKFullMatrix< number > & operator= (const double d)
template<class MATRIX >
void copy_from (const MATRIX &)
template<class MATRIX >
void fill (const MATRIX &src, const unsigned int dst_offset_i=0, const unsigned int dst_offset_j=0, const unsigned int src_offset_i=0, const unsigned int src_offset_j=0, const number factor=1., const bool transpose=false)
template<class VECTOR >
void vmult (VECTOR &dst, const VECTOR &src, const bool adding=false) const
template<class VECTOR >
void vmult_add (VECTOR &w, const VECTOR &v) const
template<class VECTOR >
void Tvmult (VECTOR &w, const VECTOR &v, const bool adding=false) const
template<class VECTOR >
void Tvmult_add (VECTOR &w, const VECTOR &v) const
void vmult (Vector< number > &w, const Vector< number > &v, const bool adding=false) const
void vmult_add (Vector< number > &w, const Vector< number > &v) const
void Tvmult (Vector< number > &w, const Vector< number > &v, const bool adding=false) const
void Tvmult_add (Vector< number > &w, const Vector< number > &v) const
void compute_lu_factorization ()
void invert ()
void apply_lu_factorization (Vector< number > &v, const bool transposed) const
void compute_eigenvalues (const bool right_eigenvectors=false, const bool left_eigenvectors=false)
void compute_generalized_eigenvalues_symmetric (LAPACKFullMatrix< number > &B, std::vector< Vector< number > > &eigenvectors, const int itype=1)
void compute_svd ()
void compute_inverse_svd (const double threshold=0.)
std::complex< number > eigenvalue (const unsigned int i) const
number singular_value (const unsigned int i) const
void print_formatted (std::ostream &out, const unsigned int presicion=3, const bool scientific=true, const unsigned int width=0, const char *zero_string=" ", const double denominator=1., const double threshold=0.) const

Private Attributes

LAPACKSupport::State state
LAPACKSupport::Properties properties
std::vector< number > work
std::vector< int > ipiv
std::vector< number > inv_work
std::vector< number > wr
std::vector< number > wi
std::vector< number > vl
std::vector< number > vr
std_cxx1x::shared_ptr
< LAPACKFullMatrix< number > > 
svd_u
std_cxx1x::shared_ptr
< LAPACKFullMatrix< number > > 
svd_vt

Detailed Description

template<typename number>
class LAPACKFullMatrix< number >

A variant of FullMatrix using LAPACK functions wherever possible. In order to do this, the matrix is stored in transposed order. The element access functions hide this fact by reverting the transposition.

Note:
In order to perform LAPACK functions, the class contains a lot of auxiliary data in the private section. The names of these data vectors are usually the names chosen for the arguments in the LAPACK documentation.
Author:
Guido Kanschat, 2005

Definition at line 49 of file lapack_full_matrix.h.


Constructor & Destructor Documentation

template<typename number>
LAPACKFullMatrix< number >::LAPACKFullMatrix ( const unsigned int  n = 0 ) [explicit]

Constructor. Initialize the matrix as a square matrix with dimension n.

In order to avoid the implicit conversion of integers and other types to a matrix, this constructor is declared explicit.

By default, no memory is allocated.

template<typename number>
LAPACKFullMatrix< number >::LAPACKFullMatrix ( const unsigned int  rows,
const unsigned int  cols 
)

Constructor. Initialize the matrix as a rectangular matrix.

template<typename number>
LAPACKFullMatrix< number >::LAPACKFullMatrix ( const LAPACKFullMatrix< number > &   )

Copy constructor. This constructor does a deep copy of the matrix. Therefore, it poses a possible efficiency problem, if for example, function arguments are passed by value rather than by reference. Unfortunately, we can't mark this copy constructor explicit, since that prevents the use of this class in containers, such as std::vector. The responsibility to check performance of programs must therefore remain with the user of this class.


Member Function Documentation

template<typename number>
LAPACKFullMatrix<number>& LAPACKFullMatrix< number >::operator= ( const LAPACKFullMatrix< number > &   )

Assignment operator.

template<typename number>
template<typename number2 >
LAPACKFullMatrix<number>& LAPACKFullMatrix< number >::operator= ( const FullMatrix< number2 > &   )

Assignment operator for a regular FullMatrix.

template<typename number>
LAPACKFullMatrix<number>& LAPACKFullMatrix< number >::operator= ( const double  d )

This operator assigns a scalar to a matrix. To avoid confusion with constructors, zero is the only value allowed for d

template<typename number >
template<class MATRIX >
void LAPACKFullMatrix< number >::copy_from ( const MATRIX M ) [inline]

Assignment from different matrix classes. This assignment operator uses iterators of the class MATRIX. Therefore, sparse matrices are possible sources.

Definition at line 613 of file lapack_full_matrix.h.

References LAPACKSupport::matrix, and internal::reinit().

template<typename number >
template<class MATRIX >
void LAPACKFullMatrix< number >::fill ( const MATRIX src,
const unsigned int  dst_offset_i = 0,
const unsigned int  dst_offset_j = 0,
const unsigned int  src_offset_i = 0,
const unsigned int  src_offset_j = 0,
const number  factor = 1.,
const bool  transpose = false 
) [inline]

Fill rectangular block.

A rectangular block of the matrix src is copied into this. The upper left corner of the block being copied is (src_offset_i,src_offset_j). The upper left corner of the copied block is (dst_offset_i,dst_offset_j). The size of the rectangular block being copied is the maximum size possible, determined either by the size of this or src.

The final two arguments allow to enter a multiple of the source or its transpose.

Definition at line 629 of file lapack_full_matrix.h.

References LAPACKSupport::matrix.

template<typename number >
template<class VECTOR >
void LAPACKFullMatrix< number >::vmult ( VECTOR &  dst,
const VECTOR &  src,
const bool  adding = false 
) const [inline]

Matrix-vector-multiplication.

The optional parameter adding determines, whether the result is stored in w or added to w.

if (adding) w += A*v

if (!adding) w = A*v

Source and destination must not be the same vector.

Note:
This template only exists for compile-time compatibility with FullMatrix. Implementation is only available for VECTOR=Vector<number>

Definition at line 658 of file lapack_full_matrix.h.

References Assert, and StandardExceptions::ExcNotImplemented().

template<typename number >
template<class VECTOR >
void LAPACKFullMatrix< number >::vmult_add ( VECTOR &  w,
const VECTOR &  v 
) const [inline]

Adding Matrix-vector-multiplication. w += A*v

Source and destination must not be the same vector.

Note:
This template only exists for compile-time compatibility with FullMatrix. Implementation is only available for VECTOR=Vector<number>

Definition at line 667 of file lapack_full_matrix.h.

References Assert, and StandardExceptions::ExcNotImplemented().

template<typename number >
template<class VECTOR >
void LAPACKFullMatrix< number >::Tvmult ( VECTOR &  w,
const VECTOR &  v,
const bool  adding = false 
) const [inline]

Transpose matrix-vector-multiplication.

The optional parameter adding determines, whether the result is stored in w or added to w.

if (adding) w += AT*v

if (!adding) w = AT*v

Source and destination must not be the same vector.

Note:
This template only exists for compile-time compatibility with FullMatrix. Implementation is only available for VECTOR=Vector<number>

Definition at line 676 of file lapack_full_matrix.h.

References Assert, and StandardExceptions::ExcNotImplemented().

template<typename number >
template<class VECTOR >
void LAPACKFullMatrix< number >::Tvmult_add ( VECTOR &  w,
const VECTOR &  v 
) const [inline]

Adding transpose matrix-vector-multiplication. w += AT*v

Source and destination must not be the same vector.

Note:
This template only exists for compile-time compatibility with FullMatrix. Implementation is only available for VECTOR=Vector<number>

Definition at line 685 of file lapack_full_matrix.h.

References Assert, and StandardExceptions::ExcNotImplemented().

template<typename number>
void LAPACKFullMatrix< number >::vmult ( Vector< number > &  w,
const Vector< number > &  v,
const bool  adding = false 
) const
template<typename number>
void LAPACKFullMatrix< number >::vmult_add ( Vector< number > &  w,
const Vector< number > &  v 
) const
template<typename number>
void LAPACKFullMatrix< number >::Tvmult ( Vector< number > &  w,
const Vector< number > &  v,
const bool  adding = false 
) const
template<typename number>
void LAPACKFullMatrix< number >::Tvmult_add ( Vector< number > &  w,
const Vector< number > &  v 
) const
template<typename number>
void LAPACKFullMatrix< number >::compute_lu_factorization (  )

Compute the LU factorization of the matrix using LAPACK function Xgetrf.

template<typename number>
void LAPACKFullMatrix< number >::invert (  )

Invert the matrix by first computing an LU factorization with the LAPACK function Xgetrf and then building the actual inverse using Xgetri.

template<typename number>
void LAPACKFullMatrix< number >::apply_lu_factorization ( Vector< number > &  v,
const bool  transposed 
) const

Solve the linear system with right hand side given by applying forward/backward substitution to the previously computed LU factorization. Uses LAPACK function Xgetrs.

template<typename number>
void LAPACKFullMatrix< number >::compute_eigenvalues ( const bool  right_eigenvectors = false,
const bool  left_eigenvectors = false 
)

Compute eigenvalues of the matrix. After this routine has been called, eigenvalues can be retrieved using the eigenvalue() function. The matrix itself will be LAPACKSupport::unusable after this operation.

The optional arguments allow to compute left and right eigenvectors as well.

Note that the function does not return the computed eigenvalues right away since that involves copying data around between the output arrays of the LAPACK functions and any return array. This is often unnecessary since one may not be interested in all eigenvalues at once, but for example only the extreme ones. In that case, it is cheaper to just have this function compute the eigenvalues and have a separate function that returns whatever eigenvalue is requested.

Note:
Calls the LAPACK function Xgeev.
template<typename number>
void LAPACKFullMatrix< number >::compute_generalized_eigenvalues_symmetric ( LAPACKFullMatrix< number > &  B,
std::vector< Vector< number > > &  eigenvectors,
const int  itype = 1 
)

Compute generalized eigenvalues and (optionally) eigenvectors of a real generalized symmetric eigenproblem of the form itype = 1: $Ax=\lambda B x$ itype = 2: $ABx=\lambda x$ itype = 3: $BAx=\lambda x$, where A is this matrix. A and B are assumed to be symmetric, and B has to be positive definite. After this routine has been called, eigenvalues can be retrieved using the eigenvalue() function. The matrix itself will be LAPACKSupport::unusable after this operation. The number of computed eigenvectors is equal to eigenvectors.size()

Note that the function does not return the computed eigenvalues right away since that involves copying data around between the output arrays of the LAPACK functions and any return array. This is often unnecessary since one may not be interested in all eigenvalues at once, but for example only the extreme ones. In that case, it is cheaper to just have this function compute the eigenvalues and have a separate function that returns whatever eigenvalue is requested.

Note:
Calls the LAPACK function Xsygv. For this to work, ./configure has to be told to use LAPACK.
template<typename number>
void LAPACKFullMatrix< number >::compute_svd (  )

Compute the singular value decomposition of the matrix using LAPACK function Xgesdd.

Requires that the state is LAPACKSupport::matrix, fills the data members wr, svd_u, and svd_vt, and leaves the object in the state LAPACKSupport::svd.

template<typename number>
void LAPACKFullMatrix< number >::compute_inverse_svd ( const double  threshold = 0. )

Compute the inverse of the matrix by singular value decomposition.

Requires that state is either LAPACKSupport::matrix or LAPACKSupport::svd. In the first case, this function calls compute_svd(). After this function, the object will have the state LAPACKSupport::inverse_svd.

For a singular value decomposition, the inverse is simply computed by replacing all singular values by their reciprocal values. If the matrix does not have maximal rank, singular values 0 are not touched, thus computing the minimal norm right inverse of the matrix.

The parameter threshold determines, when a singular value should be considered zero. It is the ratio of the smallest to the largest nonzero singular value smax. Thus, the inverses of all singular values less than smax/threshold will be set to zero.

template<typename number >
std::complex< number > LAPACKFullMatrix< number >::eigenvalue ( const unsigned int  i ) const [inline]
template<typename number >
number LAPACKFullMatrix< number >::singular_value ( const unsigned int  i ) const [inline]

Retrieve singular values after compute_svd() or compute_inverse_svd() was called.

Definition at line 706 of file lapack_full_matrix.h.

References Assert, AssertIndexRange, LAPACKSupport::ExcState(), LAPACKSupport::inverse_svd, and LAPACKSupport::svd.

template<typename number>
void LAPACKFullMatrix< number >::print_formatted ( std::ostream &  out,
const unsigned int  presicion = 3,
const bool  scientific = true,
const unsigned int  width = 0,
const char *  zero_string = " ",
const double  denominator = 1.,
const double  threshold = 0. 
) const

Print the matrix and allow formatting of entries.

The parameters allow for a flexible setting of the output format:

  • precision denotes the number of trailing digits.
  • scientific is used to determine the number format, where scientific = false means fixed point notation.
  • width denotes the with of each column. A zero entry for width makes the function compute a width, but it may be changed to a positive value, if output is crude.
  • zero_string specifies a string printed for zero entries.
  • denominator Multiply the whole matrix by this common denominator to get nicer numbers.
  • threshold: all entries with absolute value smaller than this are considered zero.

Member Data Documentation

template<typename number>
LAPACKSupport::State LAPACKFullMatrix< number >::state [private]

Since LAPACK operations notoriously change the meaning of the matrix entries, we record the current state after the last operation here.

Definition at line 505 of file lapack_full_matrix.h.

template<typename number>
LAPACKSupport::Properties LAPACKFullMatrix< number >::properties [private]

Additional properties of the matrix which may help to select more efficient LAPACK functions.

Definition at line 512 of file lapack_full_matrix.h.

template<typename number>
std::vector<number> LAPACKFullMatrix< number >::work [mutable, private]

The working array used for some LAPACK functions.

Definition at line 518 of file lapack_full_matrix.h.

template<typename number>
std::vector<int> LAPACKFullMatrix< number >::ipiv [private]

The vector storing the permutations applied for pivoting in the LU-factorization.

Also used as the scratch array IWORK for LAPACK functions needing it.

Definition at line 530 of file lapack_full_matrix.h.

template<typename number>
std::vector<number> LAPACKFullMatrix< number >::inv_work [private]

Workspace for calculating the inverse matrix from an LU factorization.

Definition at line 537 of file lapack_full_matrix.h.

template<typename number>
std::vector<number> LAPACKFullMatrix< number >::wr [private]

Real parts of eigenvalues or the singular values. Filled by compute_eigenvalues() or compute_svd().

Definition at line 544 of file lapack_full_matrix.h.

template<typename number>
std::vector<number> LAPACKFullMatrix< number >::wi [private]

Imaginary parts of eigenvalues. Filled by compute_eigenvalues.

Definition at line 551 of file lapack_full_matrix.h.

template<typename number>
std::vector<number> LAPACKFullMatrix< number >::vl [private]

Space where left eigenvectors can be stored.

Definition at line 557 of file lapack_full_matrix.h.

template<typename number>
std::vector<number> LAPACKFullMatrix< number >::vr [private]

Space where right eigenvectors can be stored.

Definition at line 563 of file lapack_full_matrix.h.

template<typename number>
std_cxx1x::shared_ptr<LAPACKFullMatrix<number> > LAPACKFullMatrix< number >::svd_u [private]

The matrix U in the singular value decomposition USVT.

Definition at line 570 of file lapack_full_matrix.h.

template<typename number>
std_cxx1x::shared_ptr<LAPACKFullMatrix<number> > LAPACKFullMatrix< number >::svd_vt [private]

The matrix VT in the singular value decomposition USVT.

Definition at line 577 of file lapack_full_matrix.h.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

deal.II documentation generated on Fri Feb 3 2012 06:04:09 by doxygen 1.7.2