HermesCommon  3.0
Hermes::Algebra::DenseMatrixOperations Namespace Reference

Contains operation on dense matrices. More...

Functions

template<typename T >
T ** new_matrix (unsigned int m, unsigned int n=0)
 
template<typename T >
T ** new_matrix_malloc (unsigned int m, unsigned int n=0)
 
template<typename T >
void copy_matrix (T **dest, T **src, unsigned int m, unsigned int n=0)
 
template<typename T >
void save_matrix_octave (const std::string &matrix_name, T **matrix, unsigned int m, unsigned int n=0, const std::string &filename=std::string())
 Saves a dense matrix to a octave file format. More...
 
template<typename T >
void save_sparse_matrix_octave (const std::string &matrix_name, const T *Ax, const int *Ap, const int *Ai, unsigned int m, const std::string &filename=std::string())
 Saves MxM sparse matrix to a octave file format.
 
template<typename T >
void transpose (T **matrix, unsigned int m, unsigned int n)
 
template<typename T >
void transpose (T *matrix, unsigned int m, unsigned int n, unsigned int size)
 
template<typename T >
void change_sign (T **matrix, unsigned int m, unsigned int n)
 Changes the sign of a matrix.
 
template<typename T >
void change_sign (T *matrix, unsigned int m, unsigned int n, unsigned int size)
 Changes the sign of an array.
 
template<typename T , typename Int >
HERMES_API void ludcmp (T **a, Int n, Int *indx, double *d)
 
template<typename T , typename S , typename Int >
HERMES_API void lubksb (T **a, Int n, Int *indx, S *b)
 
template<typename T , typename Int >
HERMES_API void choldc (T **a, Int n, T p[])
 
template<typename T , typename Int >
void cholsl (double **a, Int n, double p[], T b[], T x[])
 
template<typename T , typename Int >
void ludcmp (T **a, Int n, Int *indx, double *d)
 
template<typename T , typename S , typename Int >
void lubksb (T **a, Int n, Int *indx, S *b)
 
template<typename T , typename Int >
void choldc (T **a, Int n, T p[])
 
template HERMES_API void ludcmp< double, int > (double **a, int n, int *indx, double *d)
 
template HERMES_API void ludcmp< std::complex< double >, int > (std::complex< double > **a, int n, int *indx, double *d)
 
template HERMES_API void ludcmp< double, unsigned short > (double **a, unsigned short n, unsigned short *indx, double *d)
 
template HERMES_API void ludcmp< std::complex< double >, unsigned short > (std::complex< double > **a, unsigned short n, unsigned short *indx, double *d)
 
template HERMES_API void ludcmp< double, unsigned char > (double **a, unsigned char n, unsigned char *indx, double *d)
 
template HERMES_API void ludcmp< std::complex< double >, unsigned char > (std::complex< double > **a, unsigned char n, unsigned char *indx, double *d)
 
template HERMES_API void lubksb< double, std::complex< double >, int > (double **a, int n, int *indx, std::complex< double > *d)
 
template HERMES_API void lubksb< double, double, int > (double **a, int n, int *indx, double *d)
 
template HERMES_API void lubksb< double, std::complex< double >, unsigned short > (double **a, unsigned short n, unsigned short *indx, std::complex< double > *d)
 
template HERMES_API void lubksb< double, double, unsigned short > (double **a, unsigned short n, unsigned short *indx, double *d)
 
template HERMES_API void lubksb< double, std::complex< double >, unsigned char > (double **a, unsigned char n, unsigned char *indx, std::complex< double > *d)
 
template HERMES_API void lubksb< double, double, unsigned char > (double **a, unsigned char n, unsigned char *indx, double *d)
 
template HERMES_API void choldc< double, int > (double **a, int n, double p[])
 
template HERMES_API void choldc< std::complex< double >, int > (std::complex< double > **a, int n, std::complex< double > p[])
 
template HERMES_API void choldc< double, unsigned short > (double **a, unsigned short n, double p[])
 
template HERMES_API void choldc< std::complex< double >, unsigned short > (std::complex< double > **a, unsigned short n, std::complex< double > p[])
 
template HERMES_API void choldc< double, unsigned char > (double **a, unsigned char n, double p[])
 
template HERMES_API void choldc< std::complex< double >, unsigned char > (std::complex< double > **a, unsigned char n, std::complex< double > p[])
 

Detailed Description

Contains operation on dense matrices.

Function Documentation

template<typename T , typename Int >
void Hermes::Algebra::DenseMatrixOperations::choldc ( T **  a,
Int  n,
p[] 
)

Given a positive-definite symmetric matrix a[n][n], this routine constructs its Cholesky decomposition, A = L*L^T . On input, only the upper triangle of a need be given; it is not modified. The Cholesky factor L is returned in the lower triangle of a, except for its diagonal elements which are returned in p[n].

Definition at line 125 of file dense_matrix_operations.cpp.

template<typename T , typename Int >
HERMES_API void Hermes::Algebra::DenseMatrixOperations::choldc ( T **  a,
Int  n,
p[] 
)

Given a positive-definite symmetric matrix a[n][n], this routine constructs its Cholesky decomposition, A = L*L^T . On input, only the upper triangle of a need be given; it is not modified. The Cholesky factor L is returned in the lower triangle of a, except for its diagonal elements which are returned in p[n].

Definition at line 125 of file dense_matrix_operations.cpp.

template<typename T , typename Int >
void Hermes::Algebra::DenseMatrixOperations::cholsl ( double **  a,
Int  n,
double  p[],
b[],
x[] 
)

Solves the set of n linear equations A*x = b, where a is a positive-definite symmetric matrix. a[n][n] and p[n] are input as the output of the routine choldc. Only the lower subdiagonal portion of a is accessed. b[n] is input as the right-hand side vector. The solution vector is returned in x[n]. a, n, and p are not modified and can be left in place for successive calls with different right-hand sides b. b is not modified unless you identify b and x in the calling sequence, which is allowed. The right-hand side b can be complex, in which case the solution x is also complex.

Definition at line 250 of file dense_matrix_operations.h.

template<typename T >
void Hermes::Algebra::DenseMatrixOperations::copy_matrix ( T **  dest,
T **  src,
unsigned int  m,
unsigned int  n = 0 
)

Copies a matrix. Both matrices has to be equal to or larger than provided sizes. Size compatibility check is not done.

Definition at line 66 of file dense_matrix_operations.h.

template<typename T , typename S , typename Int >
void Hermes::Algebra::DenseMatrixOperations::lubksb ( T **  a,
Int  n,
Int *  indx,
S *  b 
)

Solves the set of n linear equations AX = B. Here a[n][n] is input, not as the matrix A but rather as its LU decomposition, determined by the routine ludcmp. indx[n] is input as the permutation vector returned by ludcmp. b[n] is input as the right-hand side vector B, and returns with the solution vector X. a, n, and indx are not modified by this routine and can be left in place for successive calls with different right-hand sides b. This routine takes into account the possibility that b will begin with many zero elements, so it is efficient for use in matrix inversion.

Definition at line 100 of file dense_matrix_operations.cpp.

template<typename T , typename S , typename Int >
HERMES_API void Hermes::Algebra::DenseMatrixOperations::lubksb ( T **  a,
Int  n,
Int *  indx,
S *  b 
)

Solves the set of n linear equations AX = B. Here a[n][n] is input, not as the matrix A but rather as its LU decomposition, determined by the routine ludcmp. indx[n] is input as the permutation vector returned by ludcmp. b[n] is input as the right-hand side vector B, and returns with the solution vector X. a, n, and indx are not modified by this routine and can be left in place for successive calls with different right-hand sides b. This routine takes into account the possibility that b will begin with many zero elements, so it is efficient for use in matrix inversion.

Definition at line 100 of file dense_matrix_operations.cpp.

template<typename T , typename Int >
void Hermes::Algebra::DenseMatrixOperations::ludcmp ( T **  a,
Int  n,
Int *  indx,
double *  d 
)

Given a matrix a[n][n], this routine replaces it by the LU decomposition of a rowwise permutation of itself. a and n are input. a is output, arranged as in equation (2.3.14) above; indx[n] is an output vector that records the row permutation effected by the partial pivoting; d is output as +-1 depending on whether the number of row interchanges was even or odd, respectively. This routine is used in combination with lubksb to solve linear equations or invert a matrix.

Definition at line 33 of file dense_matrix_operations.cpp.

Referenced by Hermes::Solvers::PicardMatrixSolver< Scalar >::calculate_anderson_coeffs().

template<typename T , typename Int >
HERMES_API void Hermes::Algebra::DenseMatrixOperations::ludcmp ( T **  a,
Int  n,
Int *  indx,
double *  d 
)

Given a matrix a[n][n], this routine replaces it by the LU decomposition of a rowwise permutation of itself. a and n are input. a is output, arranged as in equation (2.3.14) above; indx[n] is an output vector that records the row permutation effected by the partial pivoting; d is output as +-1 depending on whether the number of row interchanges was even or odd, respectively. This routine is used in combination with lubksb to solve linear equations or invert a matrix.

Definition at line 33 of file dense_matrix_operations.cpp.

Referenced by Hermes::Solvers::PicardMatrixSolver< Scalar >::calculate_anderson_coeffs().

template<typename T >
T** Hermes::Algebra::DenseMatrixOperations::new_matrix ( unsigned int  m,
unsigned int  n = 0 
)

Creates a new_ (full) matrix with m rows and n columns with entries of the type T. The entries can be accessed by matrix[i][j]. To delete the matrix, just do "delete matrix".

Definition at line 42 of file dense_matrix_operations.h.

Referenced by Hermes::Algebra::CSCMatrix< Scalar >::duplicate(), and Hermes::Algebra::CSRMatrix< Scalar >::duplicate().

template<typename T >
void Hermes::Algebra::DenseMatrixOperations::save_matrix_octave ( const std::string &  matrix_name,
T **  matrix,
unsigned int  m,
unsigned int  n = 0,
const std::string &  filename = std::string() 
)

Saves a dense matrix to a octave file format.

Parameters
[in]matrix_nameA name of a matrix in Octave. It can be used to create an output filename.
[in]matrixA pointer to an array of pointers to a rows of the matrix. Such a structure can be generated using new_matrix() or it can be a pointer to an 1D C-array.
[in]mA number of rows of the matrix. Set to 1 if the matrix is a pointer to a 1D C-array.
[in]nA number of columns of the matrix. If zero, it is assumed to be equal to m.
[in]filenameAn output filename. If not specified, matrix_name will be used by concatenating it with a suffix '.mat'.

Definition at line 82 of file dense_matrix_operations.h.

template<typename T >
void Hermes::Algebra::DenseMatrixOperations::transpose ( T **  matrix,
unsigned int  m,
unsigned int  n 
)

Transposes an m by n matrix. If m != n, the array matrix in fact has to be a square matrix of the size max(m, n) in order for the transpose to fit inside it.

Definition at line 154 of file dense_matrix_operations.h.

template<typename T >
void Hermes::Algebra::DenseMatrixOperations::transpose ( T *  matrix,
unsigned int  m,
unsigned int  n,
unsigned int  size 
)

Transposes an m by n matrix. If m != n, the array matrix in fact has to be a square matrix of the size max(m, n) in order for the transpose to fit inside it.

Definition at line 174 of file dense_matrix_operations.h.