Compressed column sparse matrix class. More...
#include <ccolmatrix.hpp>
Public Member Functions | |
CColMatrix () | |
Default constructor. | |
CColMatrix (int n, int m) | |
Constructor to make empty n x m matrix. | |
CColMatrix (int n, int m, int nz, int *ptr, int *row, double *val) | |
Constructor to make n x m matrix from compressed column matrix data. | |
CColMatrix (const CColMatrix &mat) | |
Copy constructor. | |
CColMatrix (const class CRowMatrix &mat) | |
Constructor for conversion from compressed row matrix. | |
CColMatrix (const class CoordMatrix &mat) | |
Constructor for conversion from coordinate matrix. | |
CColMatrix (const class Matrix &mat) | |
Constructor for conversion from unknown matrix type. | |
~CColMatrix () | |
Destructor. | |
int | columns (void) const |
Returns the number of columns in the matrix. | |
int | rows (void) const |
Returns the number of rows in the matrix. | |
void | size (int &n, int &m) const |
Returns the number of columns and number of columns in n and m. | |
int | nz_elements (void) const |
Returns the number of non-zero elements in the matrix. | |
int | capacity (void) const |
Returns the number of elements allocated for matrix. | |
void | resize (int n, int m) |
Resizes the matrix to size n x m. | |
void | merge (CColMatrix &mat) |
Merges matrix mat into the matrix leaving mat empty. | |
void | clear (void) |
Clear non-zero matrix elements, set all elements to zero. | |
void | clear (int i, int j) |
Clear matrix element (i,j). | |
void | reserve (int size) |
Reserve memory for size matrix elements. | |
void | order_ascending (void) |
Order (sort) matrix data in ascending row index order within each column. | |
bool | check_ascending (void) |
Check if matrix data is in ascending row index order within each column. | |
void | debug_print (std::ostream &os) const |
Print debugging information to os. | |
double | get (int i, int j) const |
Function to get a matrix element value at (i,j). | |
double & | set (int i, int j) |
Function to get a reference to matrix element value at (i,j). | |
void | set_column (int j, int N, const int *row, const double *val) |
Function to set matrix column elements. | |
void | construct_add (int i, int j, double val) |
Adds an element to matrix while constructing the whole matrix. | |
int & | ptr (int i) |
Returns a reference to the to the internal pointer index data ptr of the matrix. | |
int & | row (int i) |
Returns a reference to the to the internal column data of the matrix. | |
double & | val (int i) |
Returns a reference to the to the internal value data of the matrix. | |
const int & | ptr (int i) const |
Returns a const reference to the to the internal pointer index data ptr of the matrix. | |
const int & | row (int i) const |
Returns a const reference to the to the internal row data of the matrix. | |
const double & | val (int i) const |
Returns a const reference to the to the internal value data of the matrix. | |
void | set_nz (int nz) |
Set number of non-zero elements in the matrix. | |
CColMatrix & | operator= (const CColMatrix &mat) |
Assignment operator. | |
CColMatrix & | operator= (const class CRowMatrix &mat) |
Assignment operator for conversion from compressed row matrix. | |
CColMatrix & | operator= (const class CoordMatrix &mat) |
Assignment operator for conversion from coordinate matrix. | |
CColMatrix & | operator= (const Matrix &mat) |
Assignment operator for conversion from unknown matrix type. | |
void | multiply_by_vector (Vector &x, const Vector &b) const |
void | lower_unit_solve (Vector &x, const Vector &b) const |
Solves A*x = b for lower unit diagonal matrix. | |
void | upper_diag_solve (Vector &x, const Vector &b) const |
Solves A*x = b for upper diagonal matrix. | |
![]() | |
virtual | ~Matrix () |
Virtual destructor. | |
double | get (int i, int j) const |
Function to get a matrix element value at (i,j). | |
double & | set (int i, int j) |
Function to get a reference to matrix element value at (i,j). | |
MatrixMulVec | operator* (const class Vector &vec) const |
Operator for matrix-vector multiplication. | |
Friends | |
class | CRowMatrix |
class | CoordMatrix |
class | Vector |
class | HBIO |
Compressed column sparse matrix class.
The matrix is stored in the standard compressed column sparse matrix storage mode. In compressed column storage method all non-zero matrix elements are stored in array val in column-by-column order. The corresponding row indices are stored in another array row in the same order. The third array ptr contains "pointer" indices indicating start and end of each row in the first two arrays. The format itself does not require a certain ordering of elements, but some implementation might need/be faster on some ordering. Our example matrix
is represented in compressed column sparse matrix class as:
CColMatrix::CColMatrix | ( | ) |
Default constructor.
CColMatrix::CColMatrix | ( | int | n, |
int | m | ||
) |
Constructor to make empty n x m matrix.
CColMatrix::CColMatrix | ( | int | n, |
int | m, | ||
int | nz, | ||
int * | ptr, | ||
int * | row, | ||
double * | val | ||
) |
Constructor to make n x m matrix from compressed column matrix data.
The constructed matrix uses ptr, row and val as its internal data. The arrays are not copied! For memory allocation compatibility reasons, arrays ptr, row and val should be allocated using malloc and/or realloc.
CColMatrix::CColMatrix | ( | const CColMatrix & | mat | ) |
Copy constructor.
CColMatrix::CColMatrix | ( | const class CRowMatrix & | mat | ) |
Constructor for conversion from compressed row matrix.
The compressed column matrix will be built in ascending row index order.
CColMatrix::CColMatrix | ( | const class CoordMatrix & | mat | ) |
Constructor for conversion from coordinate matrix.
CColMatrix::CColMatrix | ( | const class Matrix & | mat | ) |
Constructor for conversion from unknown matrix type.
CColMatrix::~CColMatrix | ( | ) |
Destructor.
|
inline |
Returns the number of elements allocated for matrix.
bool CColMatrix::check_ascending | ( | void | ) |
Check if matrix data is in ascending row index order within each column.
|
virtual |
Clear non-zero matrix elements, set all elements to zero.
Implements Matrix.
|
inline |
Clear matrix element (i,j).
Removes element (i,j) from the list of non-zero matrix elements.
|
inlinevirtual |
Returns the number of columns in the matrix.
Implements Matrix.
void CColMatrix::construct_add | ( | int | i, |
int | j, | ||
double | val | ||
) |
Adds an element to matrix while constructing the whole matrix.
This is a special function for constructing the whole matrix column-by-column in ascending column order. The elements within a column can be defined in any order. With this function, every column of the matrix has to be defined. No checking of the definitions are made.
Using this function for defining a large matrix gains drasticly in speed. The function leaves all but the next column pointers unmodified. Therefore the matrix is unvalid and should not be accessed with other functions before all columns have been defined.
void CColMatrix::debug_print | ( | std::ostream & | os | ) | const |
Print debugging information to os.
|
inline |
Function to get a matrix element value at (i,j).
Range checking is done for i and j if SPM_RANGE_CHECK
is defined. Throws ErrorRange exception on range checking errors.
void CColMatrix::merge | ( | CColMatrix & | mat | ) |
Merges matrix mat into the matrix leaving mat empty.
Copies contents of matrix mat into the matrix and sets contents of matrix mat to n = 0 and m = 0.
mat | Matrix to copy from. |
Implements Matrix.
|
inline |
Returns the number of non-zero elements in the matrix.
CColMatrix& CColMatrix::operator= | ( | const CColMatrix & | mat | ) |
Assignment operator.
CColMatrix& CColMatrix::operator= | ( | const class CRowMatrix & | mat | ) |
Assignment operator for conversion from compressed row matrix.
The compressed column matrix will be built in ascending row index order.
CColMatrix& CColMatrix::operator= | ( | const class CoordMatrix & | mat | ) |
Assignment operator for conversion from coordinate matrix.
CColMatrix& CColMatrix::operator= | ( | const Matrix & | mat | ) |
Assignment operator for conversion from unknown matrix type.
void CColMatrix::order_ascending | ( | void | ) |
Order (sort) matrix data in ascending row index order within each column.
|
inline |
Returns a reference to the to the internal pointer index data ptr of the matrix.
|
inline |
Returns a const reference to the to the internal pointer index data ptr of the matrix.
void CColMatrix::reserve | ( | int | size | ) |
Reserve memory for size matrix elements.
|
virtual |
|
inline |
Returns a reference to the to the internal column data of the matrix.
|
inline |
Returns a const reference to the to the internal row data of the matrix.
|
inlinevirtual |
Returns the number of rows in the matrix.
Implements Matrix.
|
inline |
Function to get a reference to matrix element value at (i,j).
This function can be used to set or modify matrix element value. See following examples:
Note that a reference is actually a pointer to the memory location of the element and therefore unexpected things can happen if matrix is modified while using set, for example
does not do what you would expect it to do.
Range checking is done for i and j if SPM_RANGE_CHECK
is defined. Throws ErrorRange exception on range checking errors.
void CColMatrix::set_column | ( | int | j, |
int | N, | ||
const int * | row, | ||
const double * | val | ||
) |
Function to set matrix column elements.
The existing elements of the column j are replaced by N elements at row indices described in array row and with values described in array val. Range checking is always done for indexes i and j. Throws ErrorRange exception on range checking errors.
void CColMatrix::set_nz | ( | int | nz | ) |
Set number of non-zero elements in the matrix.
This function is to be used with low level access functions. The number of non-zero elements should be set to the same value as ptr[m]. Internal arrays are resized if nz is larger than the allocated size.
|
inlinevirtual |
Returns the number of columns and number of columns in n and m.
Implements Matrix.
|
inline |
Returns a reference to the to the internal value data of the matrix.
|
inline |
Returns a const reference to the to the internal value data of the matrix.
|
friend |
|
friend |
|
friend |
|
friend |