CColMatrix Class Reference

Compressed column sparse matrix class. More...

#include <ccolmatrix.hpp>

Inheritance diagram for CColMatrix:

Matrix List of all members.

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 (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_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.
CColMatrixoperator= (const CColMatrix &mat)
 Assignment operator.
CColMatrixoperator= (const class CRowMatrix &mat)
 Assignment operator for conversion from compressed row matrix.
CColMatrixoperator= (const class CoordMatrix &mat)
 Assignment operator for conversion from coordinate matrix.
CColMatrixoperator= (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.

Friends

class CRowMatrix
class CoordMatrix
class Vector
class HBIO

Detailed Description

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

      | 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:
  ptr[] = {0, 3,  6, 8,  9, 12}
  val[] = {1, 4, 11, 2,  5,  7, 6, 8, 10, 3, 9, 12}
  row[] = {0, 1,  4, 0,  1,  2, 1, 2,  3, 0, 2,  4}


Constructor & Destructor Documentation

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.


Member Function Documentation

int CColMatrix::capacity ( void   )  const [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.

void CColMatrix::clear ( int  i,
int  j 
) [inline]

Clear matrix element (i,j).

Removes element (i,j) from the list of non-zero matrix elements.

void CColMatrix::clear ( void   )  [virtual]

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

Implements Matrix.

int CColMatrix::columns ( void   )  const [inline, virtual]

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

Prints the values of all internal data to std::cout.

double CColMatrix::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.

void CColMatrix::lower_unit_solve ( Vector x,
const Vector b 
) const [virtual]

Solves A*x = b for lower unit diagonal matrix.

Matrix has to have elements only in the lower triangle. Unit diagonal is implied, it is not to be saved to matrix.

Implements Matrix.

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.

Parameters:
mat Matrix to copy from.

void CColMatrix::multiply_by_vector ( Vector x,
const Vector b 
) const [virtual]

Implements Matrix.

int CColMatrix::nz_elements ( void   )  const [inline]

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

CColMatrix& CColMatrix::operator= ( const Matrix mat  ) 

Assignment operator for conversion from unknown matrix type.

CColMatrix& CColMatrix::operator= ( const class CoordMatrix mat  ) 

Assignment operator for conversion from coordinate matrix.

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 CColMatrix mat  ) 

Assignment operator.

void CColMatrix::order_ascending ( void   ) 

Order (sort) matrix data in ascending row index order within each column.

const int& CColMatrix::ptr ( int  i  )  const [inline]

Returns a const reference to the to the internal pointer index data ptr of the matrix.

int& CColMatrix::ptr ( int  i  )  [inline]

Returns a reference to the to the internal pointer index data ptr of the matrix.

void CColMatrix::reserve ( int  size  ) 

Reserve memory for size matrix elements.

void CColMatrix::resize ( int  n,
int  m 
) [virtual]

Resizes the matrix to size n x m.

All existing non-zero elements are cleared.

Implements Matrix.

const int& CColMatrix::row ( int  i  )  const [inline]

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

int& CColMatrix::row ( int  i  )  [inline]

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

int CColMatrix::rows ( void   )  const [inline, virtual]

Returns the number of rows in the matrix.

Implements Matrix.

double & CColMatrix::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.

Reimplemented from Matrix.

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.

void CColMatrix::size ( int &  n,
int &  m 
) const [inline, virtual]

Returns the number of columns and number of columns in n and m.

Implements Matrix.

void CColMatrix::upper_diag_solve ( Vector x,
const Vector b 
) const [virtual]

Solves A*x = b for upper diagonal matrix.

Matrix has to have only upper diagonal elements. The diagonal element has to be the first entry on each column (sorted ascending order).

Implements Matrix.

const double& CColMatrix::val ( int  i  )  const [inline]

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

double& CColMatrix::val ( int  i  )  [inline]

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


Friends And Related Function Documentation

friend class CoordMatrix [friend]

friend class CRowMatrix [friend]

friend class HBIO [friend]

friend class Vector [friend]

Reimplemented from Matrix.


The documentation for this class was generated from the following file:
Generated on Thu Apr 21 13:39:59 2011 for IBSimu by  doxygen 1.4.7