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