MBSim

Project Page
csparse.h
00001 #ifndef _CS_H
00002 #define _CS_H
00003 
00004 #ifdef __cplusplus
00005 extern "C" {
00006 #endif
00007 
00008 #include <stdio.h>
00009 
00010 #ifdef MATLAB_MEX_FILE
00011 #include "mex.h"
00012 #endif
00013 #define CS_VER 1                    /* CSparse Version 1.2.0 */
00014 #define CS_SUBVER 2
00015 #define CS_SUBSUB 0
00016 #define CS_DATE "Mar 6, 2006"       /* CSparse release date */
00017 #define CS_COPYRIGHT "Copyright (c) Timothy A. Davis, 2006"
00018 
00019 /* --- primary CSparse routines and data structures ------------------------- */
00020 typedef struct cs_sparse    /* matrix in compressed-column or triplet form */
00021 {
00022     int nzmax ;     /* maximum number of entries */
00023     int m ;         /* number of rows */
00024     int n ;         /* number of columns */
00025     int *p ;        /* column pointers (size n+1) or col indices (size nzmax) */
00026     int *i ;        /* row indices, size nzmax */
00027     double *x ;     /* numerical values, size nzmax */
00028     int nz ;        /* # of entries in triplet matrix, -1 for compressed-col */
00029 } cs ;
00030 
00031 cs *cs_add (const cs *A, const cs *B, double alpha, double beta) ;
00032 int cs_cholsol (const cs *A, double *b, int order) ;
00033 int cs_dupl (cs *A) ;
00034 int cs_entry (cs *T, int i, int j, double x) ;
00035 int cs_lusol (const cs *A, double *b, int order, double tol) ;
00036 int cs_gaxpy (const cs *A, const double *x, double *y) ;
00037 cs *cs_multiply (const cs *A, const cs *B) ;
00038 int cs_qrsol (const cs *A, double *b, int order) ;
00039 cs *cs_transpose (const cs *A, int values) ;
00040 cs *cs_triplet (const cs *T) ;
00041 cs *cs_compress_LLM(const double *ele, const int lda, const int m, const int n, const int nz, const int I1, const int TwoD);
00042 double cs_norm (const cs *A) ;
00043 int cs_print (const cs *A, int brief) ;
00044 cs *cs_load (FILE *f) ;
00045 /* utilities */
00046 void *cs_calloc (int n, size_t size) ;
00047 void *cs_free (void *p) ;
00048 void *cs_realloc (void *p, int n, size_t size, int *ok) ;
00049 cs *cs_spalloc (int m, int n, int nzmax, int values, int triplet) ;
00050 cs *cs_spfree (cs *A) ;
00051 int cs_sprealloc (cs *A, int nzmax) ;
00052 void *cs_malloc (int n, size_t size) ;
00053 
00054 /* --- secondary CSparse routines and data structures ----------------------- */
00055 typedef struct cs_symbolic  /* symbolic Cholesky, LU, or QR analysis */
00056 {
00057     int *Pinv ;     /* inverse row perm. for QR, fill red. perm for Chol */
00058     int *Q ;        /* fill-reducing column permutation for LU and QR */
00059     int *parent ;   /* elimination tree for Cholesky and QR */
00060     int *cp ;       /* column pointers for Cholesky, row counts for QR */
00061     int m2 ;        /* # of rows for QR, after adding fictitious rows */
00062     int lnz ;       /* # entries in L for LU or Cholesky; in V for QR */
00063     int unz ;       /* # entries in U for LU; in R for QR */
00064 } css ;
00065 
00066 typedef struct cs_numeric   /* numeric Cholesky, LU, or QR factorization */
00067 {
00068     cs *L ;         /* L for LU and Cholesky, V for QR */
00069     cs *U ;         /* U for LU, R for QR, not used for Cholesky */
00070     int *Pinv ;     /* partial pivoting for LU */
00071     double *B ;     /* beta [0..n-1] for QR */
00072 } csn ;
00073 
00074 typedef struct cs_dmperm_results    /* cs_dmperm or cs_scc output */
00075 {
00076     int *P ;        /* size m, row permutation */
00077     int *Q ;        /* size n, column permutation */
00078     int *R ;        /* size nb+1, block k is rows R[k] to R[k+1]-1 in A(P,Q) */
00079     int *S ;        /* size nb+1, block k is cols S[k] to S[k+1]-1 in A(P,Q) */
00080     int nb ;        /* # of blocks in fine dmperm decomposition */
00081     int rr [5] ;    /* coarse row decomposition */
00082     int cc [5] ;    /* coarse column decomposition */
00083 } csd ;
00084 
00085 int *cs_amd (const cs *A, int order) ;
00086 csn *cs_chol (const cs *A, const css *S) ;
00087 csd *cs_dmperm (const cs *A) ;
00088 int cs_droptol (cs *A, double tol) ;
00089 int cs_dropzeros (cs *A) ;
00090 int cs_happly (const cs *V, int i, double beta, double *x) ;
00091 int cs_ipvec (int n, const int *P, const double *b, double *x) ;
00092 int cs_lsolve (const cs *L, double *x) ;
00093 int cs_ltsolve (const cs *L, double *x) ;
00094 csn *cs_lu (const cs *A, const css *S, double tol) ;
00095 cs *cs_permute (const cs *A, const int *P, const int *Q, int values) ;
00096 int *cs_pinv (const int *P, int n) ;
00097 int cs_pvec (int n, const int *P, const double *b, double *x) ;
00098 csn *cs_qr (const cs *A, const css *S) ;
00099 css *cs_schol (const cs *A, int order) ;
00100 css *cs_sqr (const cs *A, int order, int qr) ;
00101 cs *cs_symperm (const cs *A, const int *Pinv, int values) ;
00102 int cs_usolve (const cs *U, double *x) ;
00103 int cs_utsolve (const cs *U, double *x) ;
00104 int cs_updown (cs *L, int sigma, const cs *C, const int *parent) ;
00105 /* utilities */
00106 css *cs_sfree (css *S) ;
00107 csn *cs_nfree (csn *N) ;
00108 csd *cs_dfree (csd *D) ;
00109 
00110 /* --- tertiary CSparse routines -------------------------------------------- */
00111 int *cs_counts (const cs *A, const int *parent, const int *post, int ata) ;
00112 int cs_cumsum (int *p, int *c, int n) ;
00113 int cs_dfs (int j, cs *L, int top, int *xi, int *pstack, const int *Pinv) ;
00114 int *cs_etree (const cs *A, int ata) ;
00115 int cs_fkeep (cs *A, int (*fkeep) (int, int, double, void *), void *other) ;
00116 double cs_house (double *x, double *beta, int n) ;
00117 int *cs_maxtrans (const cs *A) ;
00118 int *cs_post (int n, const int *parent) ;
00119 int cs_reach (cs *L, const cs *B, int k, int *xi, const int *Pinv) ;
00120 csd *cs_scc (cs *A) ;
00121 int cs_scatter (const cs *A, int j, double beta, int *w, double *x, int mark,
00122     cs *C, int nz) ;
00123 int cs_splsolve (cs *L, const cs *B, int k, int *xi, double *x,
00124     const int *Pinv) ;
00125 int cs_tdfs (int j, int k, int *head, const int *next, int *post,
00126     int *stack) ;
00127 /* utilities */
00128 csd *cs_dalloc (int m, int n) ;
00129 cs *cs_done (cs *C, void *w, void *x, int ok) ;
00130 int *cs_idone (int *p, cs *C, void *w, int ok) ;
00131 csn *cs_ndone (csn *N, cs *C, void *w, void *x, int ok) ;
00132 csd *cs_ddone (csd *D, cs *C, void *w, int ok) ;
00133 
00134 #define CS_MAX(a,b) (((a) > (b)) ? (a) : (b))
00135 #define CS_MIN(a,b) (((a) < (b)) ? (a) : (b))
00136 #define CS_FLIP(i) (-(i)-2)
00137 #define CS_UNFLIP(i) (((i) < 0) ? CS_FLIP(i) : (i))
00138 #define CS_MARKED(Ap,j) (Ap [j] < 0)
00139 #define CS_MARK(Ap,j) { Ap [j] = CS_FLIP (Ap [j]) ; }
00140 #define CS_OVERFLOW(n,size) (n > INT_MAX / (int) size)
00141 
00142 #ifdef __cplusplus
00143 }
00144 #endif
00145 
00146 #endif
00147