mbsim  4.0.0
MBSim Kernel
csparse.h
1#ifndef _CS_H
2#define _CS_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include <stdio.h>
9
10#ifdef MATLAB_MEX_FILE
11#include "mex.h"
12#endif
13#define CS_VER 1 /* CSparse Version 1.2.0 */
14#define CS_SUBVER 2
15#define CS_SUBSUB 0
16#define CS_DATE "Mar 6, 2006" /* CSparse release date */
17#define CS_COPYRIGHT "Copyright (c) Timothy A. Davis, 2006"
18
19/* --- primary CSparse routines and data structures ------------------------- */
20typedef struct cs_sparse /* matrix in compressed-column or triplet form */
21{
22 int nzmax ; /* maximum number of entries */
23 int m ; /* number of rows */
24 int n ; /* number of columns */
25 int *p ; /* column pointers (size n+1) or col indices (size nzmax) */
26 int *i ; /* row indices, size nzmax */
27 double *x ; /* numerical values, size nzmax */
28 int nz ; /* # of entries in triplet matrix, -1 for compressed-col */
29} cs ;
30
31cs *cs_add (const cs *A, const cs *B, double alpha, double beta) ;
32int cs_cholsol (const cs *A, double *b, int order) ;
33int cs_dupl (cs *A) ;
34int cs_entry (cs *T, int i, int j, double x) ;
35int cs_lusol (const cs *A, double *b, int order, double tol) ;
36int cs_gaxpy (const cs *A, const double *x, double *y) ;
37cs *cs_multiply (const cs *A, const cs *B) ;
38int cs_qrsol (const cs *A, double *b, int order) ;
39cs *cs_transpose (const cs *A, int values) ;
40cs *cs_triplet (const cs *T) ;
41cs *cs_compress_LLM(const double *ele, int lda, int m, int n, int nz, int I1, int TwoD);
42double cs_norm (const cs *A) ;
43int cs_print (const cs *A, int brief) ;
44cs *cs_load (FILE *f) ;
45/* utilities */
46void *cs_calloc (int n, size_t size) ;
47void *cs_free (void *p) ;
48void *cs_realloc (void *p, int n, size_t size, int *ok) ;
49cs *cs_spalloc (int m, int n, int nzmax, int values, int triplet) ;
50cs *cs_spfree (cs *A) ;
51int cs_sprealloc (cs *A, int nzmax) ;
52void *cs_malloc (int n, size_t size) ;
53
54/* --- secondary CSparse routines and data structures ----------------------- */
55typedef struct cs_symbolic /* symbolic Cholesky, LU, or QR analysis */
56{
57 int *Pinv ; /* inverse row perm. for QR, fill red. perm for Chol */
58 int *Q ; /* fill-reducing column permutation for LU and QR */
59 int *parent ; /* elimination tree for Cholesky and QR */
60 int *cp ; /* column pointers for Cholesky, row counts for QR */
61 int m2 ; /* # of rows for QR, after adding fictitious rows */
62 int lnz ; /* # entries in L for LU or Cholesky; in V for QR */
63 int unz ; /* # entries in U for LU; in R for QR */
64} css ;
65
66typedef struct cs_numeric /* numeric Cholesky, LU, or QR factorization */
67{
68 cs *L ; /* L for LU and Cholesky, V for QR */
69 cs *U ; /* U for LU, R for QR, not used for Cholesky */
70 int *Pinv ; /* partial pivoting for LU */
71 double *B ; /* beta [0..n-1] for QR */
72} csn ;
73
74typedef struct cs_dmperm_results /* cs_dmperm or cs_scc output */
75{
76 int *P ; /* size m, row permutation */
77 int *Q ; /* size n, column permutation */
78 int *R ; /* size nb+1, block k is rows R[k] to R[k+1]-1 in A(P,Q) */
79 int *S ; /* size nb+1, block k is cols S[k] to S[k+1]-1 in A(P,Q) */
80 int nb ; /* # of blocks in fine dmperm decomposition */
81 int rr [5] ; /* coarse row decomposition */
82 int cc [5] ; /* coarse column decomposition */
83} csd ;
84
85int *cs_amd (const cs *A, int order) ;
86csn *cs_chol (const cs *A, const css *S) ;
87csd *cs_dmperm (const cs *A) ;
88int cs_droptol (cs *A, double tol) ;
89int cs_dropzeros (cs *A) ;
90int cs_happly (const cs *V, int i, double beta, double *x) ;
91int cs_ipvec (int n, const int *P, const double *b, double *x) ;
92int cs_lsolve (const cs *L, double *x) ;
93int cs_ltsolve (const cs *L, double *x) ;
94csn *cs_lu (const cs *A, const css *S, double tol) ;
95cs *cs_permute (const cs *A, const int *Pinv, const int *Q, int values) ;
96int *cs_pinv (const int *P, int n) ;
97int cs_pvec (int n, const int *P, const double *b, double *x) ;
98csn *cs_qr (const cs *A, const css *S) ;
99css *cs_schol (const cs *A, int order) ;
100css *cs_sqr (const cs *A, int order, int qr) ;
101cs *cs_symperm (const cs *A, const int *Pinv, int values) ;
102int cs_usolve (const cs *U, double *x) ;
103int cs_utsolve (const cs *U, double *x) ;
104int cs_updown (cs *L, int sigma, const cs *C, const int *parent) ;
105/* utilities */
106css *cs_sfree (css *S) ;
107csn *cs_nfree (csn *N) ;
108csd *cs_dfree (csd *D) ;
109
110/* --- tertiary CSparse routines -------------------------------------------- */
111int *cs_counts (const cs *A, const int *parent, const int *post, int ata) ;
112int cs_cumsum (int *p, int *c, int n) ;
113int cs_dfs (int j, cs *L, int top, int *xi, int *pstack, const int *Pinv) ;
114int *cs_etree (const cs *A, int ata) ;
115int cs_fkeep (cs *A, int (*fkeep) (int, int, double, void *), void *other) ;
116double cs_house (double *x, double *beta, int n) ;
117int *cs_maxtrans (const cs *A) ;
118int *cs_post (int n, const int *parent) ;
119int cs_reach (cs *L, const cs *B, int k, int *xi, const int *Pinv) ;
120csd *cs_scc (cs *A) ;
121int cs_scatter (const cs *A, int j, double beta, int *w, double *x, int mark,
122 cs *C, int nz) ;
123int cs_splsolve (cs *L, const cs *B, int k, int *xi, double *x,
124 const int *Pinv) ;
125int cs_tdfs (int j, int k, int *head, const int *next, int *post,
126 int *stack) ;
127/* utilities */
128csd *cs_dalloc (int m, int n) ;
129cs *cs_done (cs *C, void *w, void *x, int ok) ;
130int *cs_idone (int *p, cs *C, void *w, int ok) ;
131csn *cs_ndone (csn *N, cs *C, void *w, void *x, int ok) ;
132csd *cs_ddone (csd *D, cs *C, void *w, int ok) ;
133
134#define CS_MAX(a,b) (((a) > (b)) ? (a) : (b))
135#define CS_MIN(a,b) (((a) < (b)) ? (a) : (b))
136#define CS_FLIP(i) (-(i)-2)
137#define CS_UNFLIP(i) (((i) < 0) ? CS_FLIP(i) : (i))
138#define CS_MARKED(Ap,j) ((Ap) [j] < 0)
139#define CS_MARK(Ap,j) { (Ap) [j] = CS_FLIP ((Ap) [j]) ; }
140#define CS_OVERFLOW(n,size) ((n) > INT_MAX / (int) (size))
141
142#ifdef __cplusplus
143}
144#endif
145
146#endif
147
Definition: csparse.h:75
Definition: csparse.h:67
Definition: csparse.h:21
Definition: csparse.h:56