H2Lib  3.0
sparsematrix

Representation of a sparse matrix in compressed row format. More...

## Data Structures

struct  _sparsematrix
Representation of a sparse matrix in compressed row format. More...

## Typedefs

typedef struct _sparsematrix sparsematrix
Representation of a sparse matrix in compressed row format.

typedef sparsematrixpsparsematrix
Pointer to sparsematrix object.

typedef const sparsematrixpcsparsematrix
Pointer to constant sparsematrix object.

## Functions

psparsematrix new_raw_sparsematrix (uint rows, uint cols, uint nz)
Create a sparsematrix object without initializing its arrays. More...

psparsematrix new_identity_sparsematrix (uint rows, uint cols)
Creates a new sparsematrix object and initializes it to the idenity matrix . More...

psparsematrix new_zero_sparsematrix (psparsepattern sp)
Create a sparsematrix based on a sparsepattern. More...

void del_sparsematrix (psparsematrix a)
Delete a sparsematrix object. More...

field addentry_sparsematrix (psparsematrix a, uint row, uint col, field x)
Add to a matrix entry, . More...

void setentry_sparsematrix (psparsematrix a, uint row, uint col, field x)
Set a matrix entry, . More...

size_t getsize_sparsematrix (pcsparsematrix a)
Get size of a given sparsematrix object. More...

void sort_sparsematrix (psparsematrix a)
Sort non-zero entries to ensure that diagonal entries come first. More...

void clear_sparsematrix (psparsematrix a)
Set a matrix to zero. More...

void print_sparsematrix (pcsparsematrix a)
Print a sparse matrix. More...

void print_eps_sparsematrix (pcsparsematrix a, const char *filename, uint offset)
Print matrix to a Postscript file. More...

void addeval_sparsematrix_avector (field alpha, pcsparsematrix a, pcavector x, pavector y)
Multiply a matrix by a vector , . More...

void addevaltrans_sparsematrix_avector (field alpha, pcsparsematrix a, pcavector x, pavector y)
Multiply the adjoint of a matrix by a vector , . More...

void mvm_sparsematrix_avector (field alpha, bool trans, pcsparsematrix a, pcavector x, pavector y)
Multiply a matrix or its adjoint by a vector, or . More...

real norm2_sparsematrix (pcsparsematrix S)
Approximate the spectral norm of a matrix . More...

real norm2diff_sparsematrix (pcsparsematrix a, pcsparsematrix b)
Approximate the spectral norm of the difference of two matrices and . More...

void add_sparsematrix_amatrix (field alpha, bool atrans, pcsparsematrix a, pamatrix b)
Add a sparsematrix to an amatrix, or . More...

## Detailed Description

Representation of a sparse matrix in compressed row format.

The sparsematrix class is used to store sparse matrices efficiently by avoiding to store zero entries. The internal representation is the compressed row format: the -th row is described by the entries row[i] to row[i+1]-1 in the arrays col and coeff. For each there is exactly one such that row[i]<=k<row[i+1], col[k]=j and coeff[k] .

## Function Documentation

 void add_sparsematrix_amatrix ( field alpha, bool atrans, pcsparsematrix a, pamatrix b )

Add a sparsematrix to an amatrix, or .

Parameters
 alpha Scaling factor . atrans Set if is to be added instead of . a Source matrix . b Target matrix .
 field addentry_sparsematrix ( psparsematrix a, uint row, uint col, field x )

Add to a matrix entry, .

Only entries appearing in the sparsity pattern of the matrix are allowed.

Parameters
 a Target matrix . row Row index . col Column index . x Summand.
Returns
New value of .
 void addeval_sparsematrix_avector ( field alpha, pcsparsematrix a, pcavector x, pavector y )

Multiply a matrix by a vector , .

The matrix is multiplied by the source vector , the result is scaled by and added to the target vector .

Parameters
 alpha Scaling factor . a Matrix . x Source vector . y Target vector .
 void addevaltrans_sparsematrix_avector ( field alpha, pcsparsematrix a, pcavector x, pavector y )

Multiply the adjoint of a matrix by a vector , .

The adjoint is multiplied by the source vector , the result is scaled by and added to the target vector .

Parameters
 alpha Scaling factor . a Matrix . x Source vector . y Target vector .
 void clear_sparsematrix ( psparsematrix a )

Set a matrix to zero.

Parameters
 a Target matrix.
 void del_sparsematrix ( psparsematrix a )

Delete a sparsematrix object.

Releases the storage corresponding to the object.

Parameters
 a Object to be deleted.
 size_t getsize_sparsematrix ( pcsparsematrix a )

Get size of a given sparsematrix object.

Computes the size of the sparsematrix object and the storage allocated for the coefficients.

Parameters
 a Target matrix.
Returns
Size of allocated storage in bytes.
 void mvm_sparsematrix_avector ( field alpha, bool trans, pcsparsematrix a, pcavector x, pavector y )

Multiply a matrix or its adjoint by a vector, or .

The matrix or its adjoint is multiplied by the source vector , the result is scaled by and added to the target vector .

Parameters
 alpha Scaling factor . trans Set if is to be used instead of . a Matrix . x Source vector . y Target vector .
 psparsematrix new_identity_sparsematrix ( uint rows, uint cols )

Creates a new sparsematrix object and initializes it to the idenity matrix .

Parameters
 rows Number of rows is equal to cols Number of columns is equal to
Returns
New identity sparsematrix
 psparsematrix new_raw_sparsematrix ( uint rows, uint cols, uint nz )

Create a sparsematrix object without initializing its arrays.

Remarks
Should always be matched by a call to del_sparsematrix.
Parameters
 rows Number of rows. cols Number of columns. nz Number of non-zero entries.
Returns
Allocated sparsematrix object, arrays row, col and coeff are uninitialized.
 psparsematrix new_zero_sparsematrix ( psparsepattern sp )

Create a sparsematrix based on a sparsepattern.

Remarks
Should always be matched by a call to del_sparsematrix.
Parameters
 sp Description of matrix graph in a sparsepattern object.
Returns
Fully initialized sparsematrix object with given sparsity pattern and zero coefficients.
 real norm2_sparsematrix ( pcsparsematrix S )

Approximate the spectral norm of a matrix .

The spectral norm is approximated by applying a few steps of the power iteration to the matrix and computing the square root of the resulting eigenvalue approximation.

Parameters
 S Sparse matrix .
Returns
Approximation of .
 real norm2diff_sparsematrix ( pcsparsematrix a, pcsparsematrix b )

Approximate the spectral norm of the difference of two matrices and .

The spectral norm is approximated by applying a few steps of the power iteration to the matrix and computing the square root of the resulting eigenvalue approximation.

Parameters
 a Sparse matrix . b Sparse matrix .
Returns
Approximation of .
 void print_eps_sparsematrix ( pcsparsematrix a, const char * filename, uint offset )

Print matrix to a Postscript file.

Parameters
 a Source matrix. filename Name of the target file. offset Offset added to all coordinates, e.g., to avoid boundary clipping with some printers.
 void print_sparsematrix ( pcsparsematrix a )

Print a sparse matrix.

Parameters
 a Source matrix.
 void setentry_sparsematrix ( psparsematrix a, uint row, uint col, field x )

Set a matrix entry, .

Only entries appearing in the sparsity pattern of the matirx are allowed.

Parameters
 a Target matrix . row Row index . col Column index . x New value of .
 void sort_sparsematrix ( psparsematrix a )

Sort non-zero entries to ensure that diagonal entries come first.

Reorder the entries of each row in col and coeff to place the diagonal entry first. Since many iterative solvers require us to handle this entry differently from all others, this optimization can improve the performance.

Parameters
 a Target matrix.