Public Member Functions | Friends | List of all members
CoordMatrix Class Reference

Coordinate sparse matrix class. More...

#include <coordmatrix.hpp>

Inheritance diagram for CoordMatrix:
Matrix

Public Member Functions

 CoordMatrix ()
 Default constructor. More...
 
 CoordMatrix (int n, int m)
 Constructor to make empty n x m matrix. More...
 
 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. More...
 
 CoordMatrix (const CoordMatrix &mat)
 Copy constructor. More...
 
 CoordMatrix (const class CRowMatrix &mat)
 Constructor for conversion from compressed row matrix. More...
 
 CoordMatrix (const class CColMatrix &mat)
 Constructor for conversion from compressed column matrix. More...
 
 CoordMatrix (const class Matrix &mat)
 Constructor for conversion from unknown matrix type. More...
 
 ~CoordMatrix ()
 Destructor. More...
 
int columns (void) const
 Returns the number of columns in the matrix. More...
 
int rows (void) const
 Returns the number of rows in the matrix. More...
 
void size (int &n, int &m) const
 Returns the number of columns and number of columns in nn and mm. More...
 
int nz_elements (void) const
 Returns the number of non-zero elements in the matrix. More...
 
int capacity (void) const
 Returns the number of elements allocated for matrix. More...
 
void resize (int n, int m)
 Resizes the matrix to size n x m. More...
 
void merge (CoordMatrix &mat)
 Merges matrix mat into the matrix leaving mat empty. More...
 
void clear (void)
 Clear non-zero matrix elements, set all elements to zero. More...
 
void clear (int i, int j)
 Clear matrix element (i,j). More...
 
void reserve (int size)
 Reserve memory for size matrix elements. More...
 
void order_ascending_row_column (void)
 Order (sort) matrix data in ascending (row,column) index order. More...
 
void order_ascending_column_row (void)
 Order (sort) matrix data in ascending (column,row) index order. More...
 
void debug_print (std::ostream &os) const
 Print debugging information to os. More...
 
double get (int i, int j) const
 Function to get a matrix element value at (i,j). More...
 
double & set (int i, int j)
 Function to get a reference to matrix element value at (i,j). More...
 
void set_no_duplicate_check (int i, int j, double vval)
 Set element with no checks. More...
 
int & row (int i)
 Returns a reference to the to the internal row data of the matrix. More...
 
int & col (int i)
 Returns a reference to the to the internal column data ptr of the matrix. More...
 
double & val (int i)
 Returns a reference to the to the internal value data of the matrix. More...
 
const int & row (int i) const
 Returns a const reference to the to the internal row data of the matrix. More...
 
const int & col (int i) const
 Returns a const reference to the to the internal column data ptr of the matrix. More...
 
const double & val (int i) const
 Returns a const reference to the to the internal value data of the matrix. More...
 
void set_nz (int nz)
 Set number of non-zero elements in the matrix. More...
 
CoordMatrixoperator= (const CoordMatrix &mat)
 
CoordMatrixoperator= (const CColMatrix &mat)
 
CoordMatrixoperator= (const CRowMatrix &mat)
 
CoordMatrixoperator= (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
 
- Public Member Functions inherited from Matrix
virtual ~Matrix ()
 Virtual destructor. More...
 
double get (int i, int j) const
 Function to get a matrix element value at (i,j). More...
 
double & set (int i, int j)
 Function to get a reference to matrix element value at (i,j). More...
 
MatrixMulVec operator* (const class Vector &vec) const
 Operator for matrix-vector multiplication. More...
 

Friends

class CRowMatrix
 
class CColMatrix
 

Detailed Description

Coordinate sparse matrix class.

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|
*

is represented in compressed column sparse matrix class as:

* 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}
*

Constructor & Destructor Documentation

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.

Member Function Documentation

int CoordMatrix::capacity ( void  ) const
inline

Returns the number of elements allocated for matrix.

void CoordMatrix::clear ( void  )
virtual

Clear non-zero matrix elements, set all elements to zero.

Implements 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.

int& CoordMatrix::col ( int  i)
inline

Returns a reference to the to the internal column data ptr of the matrix.

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::columns ( void  ) const
inlinevirtual

Returns the number of columns in the matrix.

Implements Matrix.

void CoordMatrix::debug_print ( std::ostream &  os) const

Print debugging information to os.

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.

void CoordMatrix::lower_unit_solve ( Vector y,
const Vector b 
) const
virtual

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.

Parameters
matMatrix to copy from.
void CoordMatrix::multiply_by_vector ( Vector res,
const Vector rhs 
) const
virtual

Implements Matrix.

int CoordMatrix::nz_elements ( void  ) const
inline

Returns the number of non-zero elements in the matrix.

CoordMatrix& CoordMatrix::operator= ( const CoordMatrix mat)
CoordMatrix& CoordMatrix::operator= ( const CColMatrix mat)
CoordMatrix& CoordMatrix::operator= ( const CRowMatrix mat)
CoordMatrix& CoordMatrix::operator= ( const Matrix 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

Resizes the matrix to size n x m.

All existing non-zero elements are cleared.

Implements Matrix.

int& CoordMatrix::row ( int  i)
inline

Returns a reference to the to the internal row data of the matrix.

const int& CoordMatrix::row ( int  i) const
inline

Returns a const reference to the to the internal row data of the matrix.

int CoordMatrix::rows ( void  ) const
inlinevirtual

Returns the number of rows in the matrix.

Implements Matrix.

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
*

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

* A.set(0,0) = A.set(0,1) = A.set(0,2) = 5.0
*

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 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
inlinevirtual

Returns the number of columns and number of columns in nn and mm.

Implements Matrix.

void CoordMatrix::upper_diag_solve ( Vector x,
const Vector y 
) const
virtual

Implements Matrix.

double& CoordMatrix::val ( int  i)
inline

Returns a reference to the to the internal value data of the matrix.

const double& CoordMatrix::val ( int  i) const
inline

Returns a const reference to the to the internal value data of the matrix.

Friends And Related Function Documentation

friend class CColMatrix
friend
friend class CRowMatrix
friend

The documentation for this class was generated from the following file: