#include <coordmatrix.hpp>
Inheritance diagram for CoordMatrix:
Public Member Functions | |
CoordMatrix () | |
Default constructor. | |
CoordMatrix (int n, int m) | |
Constructor to make empty n x m matrix. | |
CoordMatrix (int n, int m, int nz, const int *row, const int *col, const int *val) | |
Constructor to make n x m matrix from row, column and data triplets. | |
CoordMatrix (const CoordMatrix &mat) | |
Copy constructor. | |
CoordMatrix (const class CRowMatrix &mat) | |
Constructor for conversion from compressed row matrix. | |
CoordMatrix (const class CColMatrix &mat) | |
Constructor for conversion from compressed column matrix. | |
CoordMatrix (const class Matrix &mat) | |
Constructor for conversion from unknown matrix type. | |
~CoordMatrix () | |
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 nn and mm. | |
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 (CoordMatrix &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_row_column (void) |
Order (sort) matrix data in ascending (row,column) index order. | |
void | order_ascending_column_row (void) |
Order (sort) matrix data in ascending (column,row) index order. | |
void | debug_print (void) const |
Prints the values of all internal data to std::cout. | |
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_no_duplicate_check (int i, int j, double vval) |
Set element with no checks. | |
int & | row (int i) |
Returns a reference to the to the internal row data of the matrix. | |
int & | col (int i) |
Returns a reference to the to the internal column data ptr of the matrix. | |
double & | val (int i) |
Returns a reference to the to the internal value data of the matrix. | |
const int & | row (int i) const |
Returns a const reference to the to the internal row data of the matrix. | |
const int & | col (int i) const |
Returns a const reference to the to the internal column data ptr 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. | |
CoordMatrix & | operator= (const CoordMatrix &mat) |
CoordMatrix & | operator= (const CColMatrix &mat) |
CoordMatrix & | operator= (const CRowMatrix &mat) |
CoordMatrix & | operator= (const Matrix &mat) |
void | multiply_by_vector (Vector &res, const Vector &rhs) const |
void | lower_unit_solve (Vector &y, const Vector &b) const |
void | upper_diag_solve (Vector &x, const Vector &y) const |
Friends | |
class | CRowMatrix |
class | CColMatrix |
The matrix is stored in the standard coordinate sparse matrix storage mode. In coordinate storage method all non-zero matrix elements are stored in array as triplets (row, column, val). The format itself does not require a certain ordering of elements, but some implementation might need/be faster on some ordering. Our example matrix
| 1 2 0 0 3| | 4 5 6 0 0| A = | 0 7 8 0 9| | 0 0 0 10 0| |11 0 0 0 12|
val[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12} row[] = {0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 4, 4} col[] = {0, 1, 4, 0, 1, 2, 1, 2, 4, 3, 0, 4}
CoordMatrix::CoordMatrix | ( | ) | [inline] |
Default constructor.
CoordMatrix::CoordMatrix | ( | int | n, | |
int | m | |||
) |
Constructor to make empty n x m matrix.
CoordMatrix::CoordMatrix | ( | int | n, | |
int | m, | |||
int | nz, | |||
const int * | row, | |||
const int * | col, | |||
const int * | val | |||
) |
Constructor to make n x m matrix from row, column and data triplets.
The constructed matrix uses row, col and val as its internal data. The arrays are not copied! For memory allocation compatibility reasons, arrays row, col and val should be allocated using malloc and/or realloc.
CoordMatrix::CoordMatrix | ( | const CoordMatrix & | mat | ) |
Copy constructor.
CoordMatrix::CoordMatrix | ( | const class CRowMatrix & | mat | ) |
Constructor for conversion from compressed row matrix.
CoordMatrix::CoordMatrix | ( | const class CColMatrix & | mat | ) |
Constructor for conversion from compressed column matrix.
CoordMatrix::CoordMatrix | ( | const class Matrix & | mat | ) |
Constructor for conversion from unknown matrix type.
CoordMatrix::~CoordMatrix | ( | ) |
Destructor.
int CoordMatrix::capacity | ( | void | ) | const [inline] |
Returns the number of elements allocated for matrix.
void CoordMatrix::clear | ( | int | i, | |
int | j | |||
) | [inline] |
Clear matrix element (i,j).
Removes element (i,j) from the list of non-zero matrix elements.
void CoordMatrix::clear | ( | void | ) | [virtual] |
const int& CoordMatrix::col | ( | int | i | ) | const [inline] |
Returns a const reference to the to the internal column data ptr of the matrix.
int& CoordMatrix::col | ( | int | i | ) | [inline] |
Returns a reference to the to the internal column data ptr of the matrix.
int CoordMatrix::columns | ( | void | ) | const [inline, virtual] |
void CoordMatrix::debug_print | ( | void | ) | const |
Prints the values of all internal data to std::cout.
double CoordMatrix::get | ( | int | i, | |
int | j | |||
) | const [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.
Reimplemented from Matrix.
Implements Matrix.
void CoordMatrix::merge | ( | CoordMatrix & | 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.
int CoordMatrix::nz_elements | ( | void | ) | const [inline] |
Returns the number of non-zero elements in the matrix.
CoordMatrix& CoordMatrix::operator= | ( | const Matrix & | mat | ) |
CoordMatrix& CoordMatrix::operator= | ( | const CRowMatrix & | mat | ) |
CoordMatrix& CoordMatrix::operator= | ( | const CColMatrix & | mat | ) |
CoordMatrix& CoordMatrix::operator= | ( | const CoordMatrix & | mat | ) |
void CoordMatrix::order_ascending_column_row | ( | void | ) |
Order (sort) matrix data in ascending (column,row) index order.
void CoordMatrix::order_ascending_row_column | ( | void | ) |
Order (sort) matrix data in ascending (row,column) index order.
void CoordMatrix::reserve | ( | int | size | ) |
Reserve memory for size matrix elements.
void CoordMatrix::resize | ( | int | n, | |
int | m | |||
) | [virtual] |
const int& CoordMatrix::row | ( | int | i | ) | const [inline] |
Returns a const reference to the to the internal row data of the matrix.
int& CoordMatrix::row | ( | int | i | ) | [inline] |
Returns a reference to the to the internal row data of the matrix.
int CoordMatrix::rows | ( | void | ) | const [inline, virtual] |
double & CoordMatrix::set | ( | int | i, | |
int | j | |||
) | [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:
A.set(0,0) = 1.2 A.set(0,1) *= 2 A.set(0,1) += 0.1
A.set(0,0) = A.set(0,1) = A.set(0,2) = 5.0
Range checking is done for i and j if SPM_RANGE_CHECK
is defined. Throws ErrorRange exception on range checking errors.
Reimplemented from Matrix.
void CoordMatrix::set_no_duplicate_check | ( | int | i, | |
int | j, | |||
double | vval | |||
) |
Set element with no checks.
Sets element (i, j) to value vval. No checks are performed. User must be certain that duplicate entries are not made.
void CoordMatrix::set_nz | ( | int | nz | ) |
Set number of non-zero elements in the matrix.
This function is to be used with low level access functions. Internal arrays are resized if nz is larger than the allocated size.
void CoordMatrix::size | ( | int & | n, | |
int & | m | |||
) | const [inline, virtual] |
Implements Matrix.
const double& CoordMatrix::val | ( | int | i | ) | const [inline] |
Returns a const reference to the to the internal value data of the matrix.
double& CoordMatrix::val | ( | int | i | ) | [inline] |
Returns a reference to the to the internal value data of the matrix.
friend class CColMatrix [friend] |
friend class CRowMatrix [friend] |