Fast Auxiliary Space Preconditioning  1.8.4 Feb/15/2016
sparse_csr.c File Reference

Sparse matrix operations for dCSRmat matrices. More...

#include <math.h>
#include <time.h>
#include "fasp.h"
#include "fasp_functs.h"

Go to the source code of this file.

Functions

dCSRmat fasp_dcsr_create (const INT m, const INT n, const INT nnz)
 Create CSR sparse matrix data memory space. More...
 
iCSRmat fasp_icsr_create (const INT m, const INT n, const INT nnz)
 Create CSR sparse matrix data memory space. More...
 
void fasp_dcsr_alloc (const INT m, const INT n, const INT nnz, dCSRmat *A)
 Allocate CSR sparse matrix memory space. More...
 
void fasp_dcsr_free (dCSRmat *A)
 Free CSR sparse matrix data memory space. More...
 
void fasp_icsr_free (iCSRmat *A)
 Free CSR sparse matrix data memory space. More...
 
void fasp_dcsr_null (dCSRmat *A)
 Initialize CSR sparse matrix. More...
 
void fasp_icsr_null (iCSRmat *A)
 Initialize CSR sparse matrix. More...
 
dCSRmat fasp_dcsr_perm (dCSRmat *A, INT *P)
 Apply permutation of A, i.e. Aperm=PAP' by the orders given in P. More...
 
void fasp_dcsr_sort (dCSRmat *A)
 Sort each row of A in ascending order w.r.t. column indices. More...
 
void fasp_dcsr_getdiag (INT n, dCSRmat *A, dvector *diag)
 Get first n diagonal entries of a CSR matrix A. More...
 
void fasp_dcsr_getcol (const INT n, dCSRmat *A, REAL *col)
 Get the n-th column of a CSR matrix A. More...
 
void fasp_dcsr_diagpref (dCSRmat *A)
 Re-order the column and data arrays of a CSR matrix, so that the first entry in each row is the diagonal. More...
 
SHORT fasp_dcsr_regdiag (dCSRmat *A, REAL value)
 Regularize diagonal entries of a CSR sparse matrix. More...
 
void fasp_icsr_cp (iCSRmat *A, iCSRmat *B)
 Copy a iCSRmat to a new one B=A. More...
 
void fasp_dcsr_cp (dCSRmat *A, dCSRmat *B)
 copy a dCSRmat to a new one B=A More...
 
void fasp_icsr_trans (iCSRmat *A, iCSRmat *AT)
 Find transpose of iCSRmat matrix A. More...
 
INT fasp_dcsr_trans (dCSRmat *A, dCSRmat *AT)
 Find transpose of dCSRmat matrix A. More...
 
void fasp_dcsr_transpose (INT *row[2], INT *col[2], REAL *val[2], INT *nn, INT *tniz)
 
void fasp_dcsr_compress (dCSRmat *A, dCSRmat *B, REAL dtol)
 Compress a CSR matrix A and store in CSR matrix B by dropping small entries abs(aij)<=dtol. More...
 
SHORT fasp_dcsr_compress_inplace (dCSRmat *A, REAL dtol)
 Compress a CSR matrix A IN PLACE by dropping small entries abs(aij)<=dtol. More...
 
void fasp_dcsr_shift (dCSRmat *A, INT offset)
 Re-index a REAL matrix in CSR format to make the index starting from 0 or 1. More...
 
void fasp_dcsr_symdiagscale (dCSRmat *A, dvector *diag)
 Symmetric diagonal scaling D^{-1/2}AD^{-1/2}. More...
 
dCSRmat fasp_dcsr_sympat (dCSRmat *A)
 Get symmetric part of a dCSRmat matrix. More...
 
void fasp_dcsr_multicoloring (dCSRmat *A, INT *flags, INT *groups)
 Use the greedy multi-coloring to get color groups of the adjacency graph of A. More...
 
void fasp_dcsr_transz (dCSRmat *A, INT *p, dCSRmat *AT)
 Generalized transpose of A: (n x m) matrix given in dCSRmat format. More...
 
dCSRmat fasp_dcsr_permz (dCSRmat *A, INT *p)
 Permute rows and cols of A, i.e. A=PAP' by the ordering in p. More...
 
void fasp_dcsr_sortz (dCSRmat *A, const SHORT isym)
 Sort each row of A in ascending order w.r.t. column indices. More...
 

Detailed Description

Sparse matrix operations for dCSRmat matrices.

Definition in file sparse_csr.c.

Function Documentation

void fasp_dcsr_alloc ( const INT  m,
const INT  n,
const INT  nnz,
dCSRmat A 
)

Allocate CSR sparse matrix memory space.

Parameters
mNumber of rows
nNumber of columns
nnzNumber of nonzeros
APointer to the dCSRmat matrix
Author
Chensong Zhang
Date
2010/04/06

Definition at line 125 of file sparse_csr.c.

void fasp_dcsr_compress ( dCSRmat A,
dCSRmat B,
REAL  dtol 
)

Compress a CSR matrix A and store in CSR matrix B by dropping small entries abs(aij)<=dtol.

Parameters
APointer to dCSRmat CSR matrix
BPointer to dCSRmat CSR matrix
dtolDrop tolerance
Author
Shiquan Zhang
Date
03/10/2010

Modified by Chunsheng Feng, Zheng Li on 08/25/2012

Definition at line 957 of file sparse_csr.c.

SHORT fasp_dcsr_compress_inplace ( dCSRmat A,
REAL  dtol 
)

Compress a CSR matrix A IN PLACE by dropping small entries abs(aij)<=dtol.

Parameters
APointer to dCSRmat CSR matrix
dtolDrop tolerance
Author
Xiaozhe Hu
Date
12/25/2010

Modified by Chensong Zhang on 02/21/2013

Note
This routine can be modified for filtering.

Definition at line 1037 of file sparse_csr.c.

void fasp_dcsr_cp ( dCSRmat A,
dCSRmat B 
)

copy a dCSRmat to a new one B=A

Parameters
APointer to the dCSRmat matrix
BPointer to the dCSRmat matrix
Author
Chensong Zhang
Date
04/06/2010

Modified by Chunsheng Feng, Xiaoqiang Yue on 05/23/2012

Definition at line 723 of file sparse_csr.c.

dCSRmat fasp_dcsr_create ( const INT  m,
const INT  n,
const INT  nnz 
)

Create CSR sparse matrix data memory space.

Parameters
mNumber of rows
nNumber of columns
nnzNumber of nonzeros
Returns
A the new dCSRmat matrix
Author
Chensong Zhang
Date
2010/04/06

Definition at line 34 of file sparse_csr.c.

void fasp_dcsr_diagpref ( dCSRmat A)

Re-order the column and data arrays of a CSR matrix, so that the first entry in each row is the diagonal.

Parameters
APointer to the matrix to be re-ordered
Author
Zhiyang Zhou
Date
09/09/2010
Author
Chunsheng Feng, Zheng Li
Date
09/02/2012
Note
Reordering is done in place.

Modified by Chensong Zhang on Dec/21/2012

Definition at line 553 of file sparse_csr.c.

void fasp_dcsr_free ( dCSRmat A)

Free CSR sparse matrix data memory space.

Parameters
APointer to the dCSRmat matrix
Author
Chensong Zhang
Date
2010/04/06

Definition at line 166 of file sparse_csr.c.

void fasp_dcsr_getcol ( const INT  n,
dCSRmat A,
REAL col 
)

Get the n-th column of a CSR matrix A.

Parameters
nIndex of a column of A (0 <= n <= A.col-1)
APointer to dCSRmat CSR matrix
colPointer to the column
Author
Xiaozhe Hu
Date
11/07/2009

Modified by Chunsheng Feng, Zheng Li on 07/08/2012

Definition at line 474 of file sparse_csr.c.

void fasp_dcsr_getdiag ( INT  n,
dCSRmat A,
dvector diag 
)

Get first n diagonal entries of a CSR matrix A.

Parameters
nNumber of diagonal entries to get (if n=0, then get all diagonal entries)
APointer to dCSRmat CSR matrix
diagPointer to the diagonal as a dvector
Author
Chensong Zhang
Date
05/20/2009

Modified by Chunsheng Feng, Xiaoqiang Yue on 05/23/2012

Definition at line 410 of file sparse_csr.c.

void fasp_dcsr_multicoloring ( dCSRmat A,
INT flags,
INT groups 
)

Use the greedy multi-coloring to get color groups of the adjacency graph of A.

Parameters
AInput dCSRmat
flagsflags for the independent group
groupsReturn group numbers
Author
Chunsheng Feng
Date
09/15/2012

Definition at line 1265 of file sparse_csr.c.

void fasp_dcsr_null ( dCSRmat A)

Initialize CSR sparse matrix.

Parameters
APointer to the dCSRmat matrix
Author
Chensong Zhang
Date
2010/04/03

Definition at line 204 of file sparse_csr.c.

dCSRmat fasp_dcsr_perm ( dCSRmat A,
INT P 
)

Apply permutation of A, i.e. Aperm=PAP' by the orders given in P.

Parameters
APointer to the original dCSRmat matrix
PPointer to orders
Returns
The new ordered dCSRmat matrix if succeed, NULL if fail
Author
Shiquan Zhang
Date
03/10/2010
Note
P[i] = k means k-th row and column become i-th row and column!
Deprecated! Will be replaced by fasp_dcsr_permz later. –Chensong

Modified by Chunsheng Feng, Zheng Li on 07/12/2012

Definition at line 247 of file sparse_csr.c.

dCSRmat fasp_dcsr_permz ( dCSRmat A,
INT p 
)

Permute rows and cols of A, i.e. A=PAP' by the ordering in p.

Parameters
APointer to the original dCSRmat matrix
pPointer to ordering
Note
This is just applying twice fasp_dcsr_transz(&A,p,At).
In matlab notation: Aperm=A(p,p);
Returns
The new ordered dCSRmat matrix if succeed, NULL if fail
Author
Ludmil Zikatanov
Date
19951219 (Fortran), 20150912 (C)

Definition at line 1486 of file sparse_csr.c.

SHORT fasp_dcsr_regdiag ( dCSRmat A,
REAL  value 
)

Regularize diagonal entries of a CSR sparse matrix.

Parameters
APointer to the dCSRmat matrix
valueSet a value on diag(A) which is too close to zero to "value"
Returns
FASP_SUCCESS if no diagonal entry is close to zero, else ERROR
Author
Shiquan Zhang
Date
11/07/2009

Definition at line 659 of file sparse_csr.c.

void fasp_dcsr_shift ( dCSRmat A,
INT  offset 
)

Re-index a REAL matrix in CSR format to make the index starting from 0 or 1.

Parameters
APointer to CSR matrix
offsetSize of offset (1 or -1)
Author
Chensong Zhang
Date
04/06/2010

Modified by Chunsheng Feng, Zheng Li on 07/11/2012

Definition at line 1085 of file sparse_csr.c.

void fasp_dcsr_sort ( dCSRmat A)

Sort each row of A in ascending order w.r.t. column indices.

Parameters
APointer to the dCSRmat matrix
Author
Shiquan Zhang
Date
06/10/2010

Definition at line 358 of file sparse_csr.c.

void fasp_dcsr_sortz ( dCSRmat A,
const SHORT  isym 
)

Sort each row of A in ascending order w.r.t. column indices.

Parameters
APointer to the dCSRmat matrix
isymFlag for symmetry, =[0/nonzero]=[general/symmetric] matrix
Note
Applying twice fasp_dcsr_transz(), if A is symmetric, then the transpose is applied only once and then AT copied on A.
Author
Ludmil Zikatanov
Date
19951219 (Fortran), 20150912 (C)

Definition at line 1518 of file sparse_csr.c.

void fasp_dcsr_symdiagscale ( dCSRmat A,
dvector diag 
)

Symmetric diagonal scaling D^{-1/2}AD^{-1/2}.

Parameters
APointer to the dCSRmat matrix
diagPointer to the diagonal entries
Author
Xiaozhe Hu
Date
01/31/2011

Modified by Chunsheng Feng, Zheng Li on 07/11/2012

Definition at line 1146 of file sparse_csr.c.

dCSRmat fasp_dcsr_sympat ( dCSRmat A)

Get symmetric part of a dCSRmat matrix.

Parameters
*Apointer to the dCSRmat matrix
Returns
symmetrized the dCSRmat matrix
Author
Xiaozhe Hu
Date
03/21/2011

Definition at line 1232 of file sparse_csr.c.

void fasp_dcsr_trans ( dCSRmat A,
dCSRmat AT 
)

Find transpose of dCSRmat matrix A.

Parameters
APointer to the dCSRmat matrix
ATPointer to the transpose of dCSRmat matrix A (output)
Author
Chensong Zhang
Date
04/06/2010

Modified by Chunsheng Feng, Zheng Li on 06/20/2012

Definition at line 826 of file sparse_csr.c.

void fasp_dcsr_transz ( dCSRmat A,
INT p,
dCSRmat AT 
)

Generalized transpose of A: (n x m) matrix given in dCSRmat format.

Parameters
APointer to matrix in dCSRmat for transpose, INPUT
pPermutation, INPUT
ATPointer to matrix AT = transpose(A) if p = NULL, OR AT = transpose(A)p if p is not NULL
Note
The storage for all pointers in AT should already be allocated, i.e. AT->IA, AT->JA and AT->val should be allocated before calling this function. If A.val=NULL, then AT->val[] is not changed.
performs AT=transpose(A)p, where p is a permutation. If p=NULL then p=I is assumed. Applying twice this procedure one gets At=transpose(transpose(A)p)p = transpose(p)Ap, which is the same A with rows and columns permutted according to p.
If A=NULL, then only transposes/permutes the structure of A.
For p=NULL, applying this two times A–>AT–>A orders all the row indices in A in increasing order.

Reference: Fred G. Gustavson. Two fast algorithms for sparse matrices: multiplication and permuted transposition. ACM Trans. Math. Software, 4(3):250–269, 1978.

Author
Ludmil Zikatanov
Date
19951219 (Fortran), 20150912 (C)

Definition at line 1366 of file sparse_csr.c.

void fasp_icsr_cp ( iCSRmat A,
iCSRmat B 
)

Copy a iCSRmat to a new one B=A.

Parameters
APointer to the iCSRmat matrix
BPointer to the iCSRmat matrix
Author
Chensong Zhang
Date
05/16/2013

Definition at line 698 of file sparse_csr.c.

iCSRmat fasp_icsr_create ( const INT  m,
const INT  n,
const INT  nnz 
)

Create CSR sparse matrix data memory space.

Parameters
mNumber of rows
nNumber of columns
nnzNumber of nonzeros
Returns
A the new iCSRmat matrix
Author
Chensong Zhang
Date
2010/04/06

Definition at line 80 of file sparse_csr.c.

void fasp_icsr_free ( iCSRmat A)

Free CSR sparse matrix data memory space.

Parameters
APointer to the iCSRmat matrix
Author
Chensong Zhang
Date
2010/04/06

Definition at line 185 of file sparse_csr.c.

void fasp_icsr_null ( iCSRmat A)

Initialize CSR sparse matrix.

Parameters
APointer to the iCSRmat matrix
Author
Chensong Zhang
Date
2010/04/03

Definition at line 221 of file sparse_csr.c.

void fasp_icsr_trans ( iCSRmat A,
iCSRmat AT 
)

Find transpose of iCSRmat matrix A.

Parameters
APointer to the iCSRmat matrix A
ATPointer to the iCSRmat matrix A'
Returns
The transpose of iCSRmat matrix A
Author
Chensong Zhang
Date
04/06/2010

Modified by Chunsheng Feng, Zheng Li on 06/20/2012

Definition at line 750 of file sparse_csr.c.