cs.h
Go to the documentation of this file.
00001 #ifndef _CS_H
00002 #define _CS_H
00003 #include <stdlib.h>
00004 #include <limits.h>
00005 #include <math.h>
00006 #include <stdio.h>
00007 #ifdef MATLAB_MEX_FILE
00008 #include "mex.h"
00009 #endif
00010 #define CS_VER 2                    /* CSparse Version 2.2.3 */
00011 #define CS_SUBVER 2
00012 #define CS_SUBSUB 3
00013 #define CS_DATE "Jan 20, 2009"     /* CSparse release date */
00014 #define CS_COPYRIGHT "Copyright (c) Timothy A. Davis, 2006-2009"
00015 
00016 #ifdef __cplusplus
00017 extern "C" {
00018 #endif
00019 
00020 /* --- primary CSparse routines and data structures ------------------------- */
00021 typedef struct cs_sparse    /* matrix in compressed-column or triplet form */
00022 {
00023     int nzmax ;     /* maximum number of entries */
00024     int m ;         /* number of rows */
00025     int n ;         /* number of columns */
00026     int *p ;        /* column pointers (size n+1) or col indices (size nzmax) */
00027     int *i ;        /* row indices, size nzmax */
00028     double *x ;     /* numerical values, size nzmax */
00029     int nz ;        /* # of entries in triplet matrix, -1 for compressed-col */
00030 } cs ;
00031 
00032 cs *cs_add (const cs *A, const cs *B, double alpha, double beta) ;
00033 int cs_cholsol (int order, const cs *A, double *b) ;
00034 cs *cs_compress (const cs *T) ;
00035 int cs_dupl (cs *A) ;
00036 int cs_entry (cs *T, int i, int j, double x) ;
00037 int cs_gaxpy (const cs *A, const double *x, double *y) ;
00038 cs *cs_load (FILE *f) ;
00039 int cs_lusol (int order, const cs *A, double *b, double tol) ;
00040 cs *cs_multiply (const cs *A, const cs *B) ;
00041 double cs_norm (const cs *A) ;
00042 int cs_print (const cs *A, int brief) ;
00043 int cs_qrsol (int order, const cs *A, double *b) ;
00044 cs *cs_transpose (const cs *A, int values) ;
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 *leftmost ; /* leftmost[i] = min(find(A(i,:))), for QR */
00062     int m2 ;        /* # of rows for QR, after adding fictitious rows */
00063     double lnz ;    /* # entries in L for LU or Cholesky; in V for QR */
00064     double unz ;    /* # entries in U for LU; in R for QR */
00065 } css ;
00066 
00067 typedef struct cs_numeric   /* numeric Cholesky, LU, or QR factorization */
00068 {
00069     cs *L ;         /* L for LU and Cholesky, V for QR */
00070     cs *U ;         /* U for LU, R for QR, not used for Cholesky */
00071     int *pinv ;     /* partial pivoting for LU */
00072     double *B ;     /* beta [0..n-1] for QR */
00073 } csn ;
00074 
00075 typedef struct cs_dmperm_results    /* cs_dmperm or cs_scc output */
00076 {
00077     int *p ;        /* size m, row permutation */
00078     int *q ;        /* size n, column permutation */
00079     int *r ;        /* size nb+1, block k is rows r[k] to r[k+1]-1 in A(p,q) */
00080     int *s ;        /* size nb+1, block k is cols s[k] to s[k+1]-1 in A(p,q) */
00081     int nb ;        /* # of blocks in fine dmperm decomposition */
00082     int rr [5] ;    /* coarse row decomposition */
00083     int cc [5] ;    /* coarse column decomposition */
00084 } csd ;
00085 
00086 int *cs_amd (int order, const cs *A) ;
00087 csn *cs_chol (const cs *A, const css *S) ;
00088 csd *cs_dmperm (const cs *A, int seed) ;
00089 int cs_droptol (cs *A, double tol) ;
00090 int cs_dropzeros (cs *A) ;
00091 int cs_happly (const cs *V, int i, double beta, double *x) ;
00092 int cs_ipvec (const int *p, const double *b, double *x, int n) ;
00093 int cs_lsolve (const cs *L, double *x) ;
00094 int cs_ltsolve (const cs *L, double *x) ;
00095 csn *cs_lu (const cs *A, const css *S, double tol) ;
00096 cs *cs_permute (const cs *A, const int *pinv, const int *q, int values) ;
00097 int *cs_pinv (const int *p, int n) ;
00098 int cs_pvec (const int *p, const double *b, double *x, int n) ;
00099 csn *cs_qr (const cs *A, const css *S) ;
00100 css *cs_schol (int order, const cs *A) ;
00101 css *cs_sqr (int order, const cs *A, int qr) ;
00102 cs *cs_symperm (const cs *A, const int *pinv, int values) ;
00103 int cs_updown (cs *L, int sigma, const cs *C, const int *parent) ;
00104 int cs_usolve (const cs *U, double *x) ;
00105 int cs_utsolve (const cs *U, double *x) ;
00106 /* utilities */
00107 css *cs_sfree (css *S) ;
00108 csn *cs_nfree (csn *N) ;
00109 csd *cs_dfree (csd *D) ;
00110 
00111 /* --- tertiary CSparse routines -------------------------------------------- */
00112 int *cs_counts (const cs *A, const int *parent, const int *post, int ata) ;
00113 double cs_cumsum (int *p, int *c, int n) ;
00114 int cs_dfs (int j, cs *G, int top, int *xi, int *pstack, const int *pinv) ;
00115 int cs_ereach (const cs *A, int k, const int *parent, int *s, int *w) ;
00116 int *cs_etree (const cs *A, int ata) ;
00117 int cs_fkeep (cs *A, int (*fkeep) (int, int, double, void *), void *other) ;
00118 double cs_house (double *x, double *beta, int n) ;
00119 int cs_leaf (int i, int j, const int *first, int *maxfirst, int *prevleaf,
00120     int *ancestor, int *jleaf) ;
00121 int *cs_maxtrans (const cs *A, int seed) ;
00122 int *cs_post (const int *parent, int n) ;
00123 int *cs_randperm (int n, int seed) ;
00124 int cs_reach (cs *G, const cs *B, int k, int *xi, const int *pinv) ;
00125 int cs_scatter (const cs *A, int j, double beta, int *w, double *x, int mark,
00126     cs *C, int nz) ;
00127 csd *cs_scc (cs *A) ;
00128 int cs_spsolve (cs *G, const cs *B, int k, int *xi, double *x,
00129     const int *pinv, int lo) ;
00130 int cs_tdfs (int j, int k, int *head, const int *next, int *post,
00131     int *stack) ;
00132 /* utilities */
00133 
00134 csd *cs_dalloc (int m, int n) ;
00135 csd *cs_ddone (csd *D, cs *C, void *w, int ok) ;
00136 cs *cs_done (cs *C, void *w, void *x, int ok) ;
00137 int *cs_idone (int *p, cs *C, void *w, int ok) ;
00138 csn *cs_ndone (csn *N, cs *C, void *w, void *x, int ok) ;
00139 
00140 #define CS_MAX(a,b) (((a) > (b)) ? (a) : (b))
00141 #define CS_MIN(a,b) (((a) < (b)) ? (a) : (b))
00142 #define CS_FLIP(i) (-(i)-2)
00143 #define CS_UNFLIP(i) (((i) < 0) ? CS_FLIP(i) : (i))
00144 #define CS_MARKED(w,j) (w [j] < 0)
00145 #define CS_MARK(w,j) { w [j] = CS_FLIP (w [j]) ; }
00146 #define CS_CSC(A) (A && (A->nz == -1))
00147 #define CS_TRIPLET(A) (A && (A->nz >= 0))
00148 
00149 #ifdef __cplusplus
00150 }
00151 #endif
00152 
00153 #endif


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:30:59