#include "common.h"#include <fstream>Go to the source code of this file.
Classes | |
| class | _Matrix |
| class | SparseMatrix |
| struct | SparseMatrix::Page |
| class | Vector |
Enumerations | |
| enum | EMatrixDumpFormat { DF_MATLAB_SPARSE, DF_PLAIN_ASCII, DF_HERMES_BIN, DF_NATIVE } |
Functions | |
| template<typename T > | |
| T ** | new_matrix (int m, 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". | |
| template<typename T > | |
| void | copy_matrix (T **dest, T **src, int m, int n=0) |
| Copies a matrix. Both matrices has to be equal to or larger than provideded sizes. Size compatibility check is not done. | |
| template<typename T > | |
| void | save_matrix_octave (const std::string &matrix_name, T **matrix, int m, int n=0, const std::string &filename=std::string()) |
| Saves a dense matrix to a octave file format. | |
| template<typename T > | |
| void | save_sparse_matrix_octave (const std::string &matrix_name, const T *Ax, const int *Ap, const int *Ai, int m, const std::string &filename=std::string()) |
| Saves MxM sparse matrix to a octave file format. | |
| template<typename T > | |
| void | transpose (T **matrix, int m, 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. | |
| template<typename T > | |
| void | chsgn (T **matrix, int m, int n) |
| Changes the sign of a matrix. | |
| H2D_API void | ludcmp (double **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. | |
| template<typename T > | |
| void | lubksb (double **a, int n, int *indx, T *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. | |
| H2D_API void | choldc (double **a, int n, double 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]. | |
| template<typename T > | |
| void | cholsl (double **a, int n, double p[], T b[], T 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. | |
| enum EMatrixDumpFormat |
| H2D_API void choldc | ( | double ** | a, | |
| int | n, | |||
| double | 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].
| void cholsl | ( | double ** | a, | |
| int | n, | |||
| double | p[], | |||
| T | b[], | |||
| T | x[] | |||
| ) | [inline] |
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.
| void chsgn | ( | T ** | matrix, | |
| int | m, | |||
| int | n | |||
| ) | [inline] |
Changes the sign of a matrix.
| void copy_matrix | ( | T ** | dest, | |
| T ** | src, | |||
| int | m, | |||
| int | n = 0 | |||
| ) | [inline] |
Copies a matrix. Both matrices has to be equal to or larger than provideded sizes. Size compatibility check is not done.
| void lubksb | ( | double ** | a, | |
| int | n, | |||
| int * | indx, | |||
| T * | b | |||
| ) | [inline] |
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.
| H2D_API void ludcmp | ( | double ** | 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.
| T** new_matrix | ( | int | m, | |
| int | n = 0 | |||
| ) | [inline] |
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".
| void save_matrix_octave | ( | const std::string & | matrix_name, | |
| T ** | matrix, | |||
| int | m, | |||
| int | n = 0, |
|||
| const std::string & | filename = std::string() | |||
| ) | [inline] |
Saves a dense matrix to a octave file format.
| [in] | matrix_name | A name of a matrix in Octave. It can be used to create an output filename. |
| [in] | matrix | A 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] | m | A number of rows of the matrix. Set to 1 if the matrix is a pointer to a 1D C-array. |
| [in] | n | A number of columns of the matrix. If zero, it is assumed to be equal to m. |
| [in] | filename | An output filename. If not specified, matrix_name will be used by concatenating it with a suffix '.mat'. |
| void save_sparse_matrix_octave | ( | const std::string & | matrix_name, | |
| const T * | Ax, | |||
| const int * | Ap, | |||
| const int * | Ai, | |||
| int | m, | |||
| const std::string & | filename = std::string() | |||
| ) | [inline] |
Saves MxM sparse matrix to a octave file format.
| void transpose | ( | T ** | matrix, | |
| int | m, | |||
| int | n | |||
| ) | [inline] |
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.
1.6.3