CSparse:获取稀疏矩阵的元素

时间:2012-06-04 17:04:56

标签: c++ sparse-matrix

是否可以在CSparse cs对象中请求元素(i,j)并获取其值,如果未填充则为零?我应该自己编写这个函数还是在CSparse中有解决方案?

缺乏文件令我感到难过。

以下是代码的参考:

蒂莫西戴维斯,     稀疏线性系统的直接方法,     SIAM,费城,2006年。 Here is the source

1 个答案:

答案 0 :(得分:2)

你是对的。文档很差。让我们看看我们是否不能生成一些我们自己的粗略文档。

将目录http://www.cise.ufl.edu/research/sparse/CSparse/CSparse/Source/复制到自己的PC,输入目录,然后发出命令sed '/^[^[:space:]#{}]/!d;/^\//!a\\' *.c

/* C = alpha*A + beta*B */
cs *cs_add (const cs *A, const cs *B, double alpha, double beta)

/* clear w */
static csi cs_wclear (csi mark, csi lemax, csi *w, csi n)

/* keep off-diagonal entries; drop diagonal entries */
static csi cs_diag (csi i, csi j, double aij, void *other) { return (i != j) ; }

/* p = amd(A+A') if symmetric is true, or amd(A'A) otherwise */
csi *cs_amd (csi order, const cs *A)  /* order 0:natural, 1:Chol, 2:LU, 3:QR */

/* L = chol (A, [pinv parent cp]), pinv is optional */
csn *cs_chol (const cs *A, const css *S)

/* x=A\b where A is symmetric positive definite; b overwritten with solution */
csi cs_cholsol (csi order, const cs *A, double *b)

/* C = compressed-column form of a triplet matrix T */
cs *cs_compress (const cs *T)

/* column counts of LL'=A or LL'=A'A, given parent & post ordering */
static void init_ata (cs *AT, const csi *post, csi *w, csi **head, csi **next)

csi *cs_counts (const cs *A, const csi *parent, const csi *post, csi ata)

/* p [0..n] = cumulative sum of c [0..n-1], and then copy p [0..n-1] into c */
double cs_cumsum (csi *p, csi *c, csi n)

/* depth-first-search of the graph of a matrix, starting at node j */
csi cs_dfs (csi j, cs *G, csi top, csi *xi, csi *pstack, const csi *pinv)

/* breadth-first search for coarse decomposition (C0,C1,R1 or R0,R3,C3) */
static csi cs_bfs (const cs *A, csi n, csi *wi, csi *wj, csi *queue,

/* collect matched rows and columns into p and q */
static void cs_matched (csi n, const csi *wj, const csi *imatch, csi *p, csi *q,

/* collect unmatched rows into the permutation vector p */
static void cs_unmatched (csi m, const csi *wi, csi *p, csi *rr, csi set)

/* return 1 if row i is in R2 */
static csi cs_rprune (csi i, csi j, double aij, void *other)

/* Given A, compute coarse and then fine dmperm */
csd *cs_dmperm (const cs *A, csi seed)

static csi cs_tol (csi i, csi j, double aij, void *tol)

csi cs_droptol (cs *A, double tol)

static csi cs_nonzero (csi i, csi j, double aij, void *other)

csi cs_dropzeros (cs *A)

/* remove duplicate entries from A */
csi cs_dupl (cs *A)

/* add an entry to a triplet matrix; return 1 if ok, 0 otherwise */
csi cs_entry (cs *T, csi i, csi j, double x)

/* find nonzero pattern of Cholesky L(k,1:k-1) using etree and triu(A(:,k)) */
csi cs_ereach (const cs *A, csi k, const csi *parent, csi *s, csi *w)

/* compute the etree of A (using triu(A), or A'A without forming A'A */
csi *cs_etree (const cs *A, csi ata)

/* drop entries for which fkeep(A(i,j)) is false; return nz if OK, else -1 */
csi cs_fkeep (cs *A, csi (*fkeep) (csi, csi, double, void *), void *other)

/* y = A*x+y */
csi cs_gaxpy (const cs *A, const double *x, double *y)

/* apply the ith Householder vector to x */
csi cs_happly (const cs *V, csi i, double beta, double *x)

/* create a Householder reflection [v,beta,s]=house(x), overwrite x with v,
double cs_house (double *x, double *beta, csi n)

/* x(p) = b, for dense vectors x and b; p=NULL denotes identity */
csi cs_ipvec (const csi *p, const double *b, double *x, csi n)

/* consider A(i,j), node j in ith row subtree and return lca(jprev,j) */
csi cs_leaf (csi i, csi j, const csi *first, csi *maxfirst, csi *prevleaf,

/* load a triplet matrix from a file */
cs *cs_load (FILE *f)

/* solve Lx=b where x and b are dense.  x=b on input, solution on output. */
csi cs_lsolve (const cs *L, double *x)

/* solve L'x=b where x and b are dense.  x=b on input, solution on output. */
csi cs_ltsolve (const cs *L, double *x)

/* [L,U,pinv]=lu(A, [q lnz unz]). lnz and unz can be guess */
csn *cs_lu (const cs *A, const css *S, double tol)

/* x=A\b where A is unsymmetric; b overwritten with solution */
csi cs_lusol (csi order, const cs *A, double *b, double tol)

/* wrapper for malloc */
void *cs_malloc (csi n, size_t size)

/* wrapper for calloc */
void *cs_calloc (csi n, size_t size)

/* wrapper for free */
void *cs_free (void *p)

/* wrapper for realloc */
void *cs_realloc (void *p, csi n, size_t size, csi *ok)

/* find an augmenting path starting at column k and extend the match if found */
static void cs_augment (csi k, const cs *A, csi *jmatch, csi *cheap, csi *w,

/* find a maximum transveral */
csi *cs_maxtrans (const cs *A, csi seed)  /*[jmatch [0..m-1]; imatch [0..n-1]]*/

/* C = A*B */
cs *cs_multiply (const cs *A, const cs *B)

/* 1-norm of a sparse matrix = max (sum (abs (A))), largest column sum */
double cs_norm (const cs *A)

/* C = A(p,q) where p and q are permutations of 0..m-1 and 0..n-1. */
cs *cs_permute (const cs *A, const csi *pinv, const csi *q, csi values)

/* pinv = p', or p = pinv' */
csi *cs_pinv (csi const *p, csi n)

/* post order a forest */
csi *cs_post (const csi *parent, csi n)

/* print a sparse matrix; use %g for integers to avoid differences with csi */
csi cs_print (const cs *A, csi brief)

/* x = b(p), for dense vectors x and b; p=NULL denotes identity */
csi cs_pvec (const csi *p, const double *b, double *x, csi n)

/* sparse QR factorization [V,beta,pinv,R] = qr (A) */
csn *cs_qr (const cs *A, const css *S)

/* x=A\b where A can be rectangular; b overwritten with solution */
csi cs_qrsol (csi order, const cs *A, double *b)

/* return a random permutation vector, the identity perm, or p = n-1:-1:0.
csi *cs_randperm (csi n, csi seed)

/* xi [top...n-1] = nodes reachable from graph of G*P' via nodes in B(:,k).
csi cs_reach (cs *G, const cs *B, csi k, csi *xi, const csi *pinv)

/* x = x + beta * A(:,j), where x is a dense vector and A(:,j) is sparse */
csi cs_scatter (const cs *A, csi j, double beta, csi *w, double *x, csi mark,

/* find the strongly connected components of a square matrix */
csd *cs_scc (cs *A)     /* matrix A temporarily modified, then restored */

/* ordering and symbolic analysis for a Cholesky factorization */
css *cs_schol (csi order, const cs *A)

/* solve Gx=b(:,k), where G is either upper (lo=0) or lower (lo=1) triangular */
csi cs_spsolve (cs *G, const cs *B, csi k, csi *xi, double *x, const csi *pinv,

/* compute nnz(V) = S->lnz, S->pinv, S->leftmost, S->m2 from A and S->parent */
static csi cs_vcount (const cs *A, css *S)

/* symbolic ordering and analysis for QR or LU */
css *cs_sqr (csi order, const cs *A, csi qr)

/* C = A(p,p) where A and C are symmetric the upper part stored; pinv not p */
cs *cs_symperm (const cs *A, const csi *pinv, csi values)

/* depth-first search and postorder of a tree rooted at node j */
csi cs_tdfs (csi j, csi k, csi *head, const csi *next, csi *post, csi *stack)

/* C = A' */
cs *cs_transpose (const cs *A, csi values)

/* sparse Cholesky update/downdate, L*L' + sigma*w*w' (sigma = +1 or -1) */
csi cs_updown (cs *L, csi sigma, const cs *C, const csi *parent)

/* solve Ux=b where x and b are dense.  x=b on input, solution on output. */
csi cs_usolve (const cs *U, double *x)

/* allocate a sparse matrix (triplet form or compressed-column form) */
cs *cs_spalloc (csi m, csi n, csi nzmax, csi values, csi triplet)

/* change the max # of entries sparse matrix */
csi cs_sprealloc (cs *A, csi nzmax)

/* free a sparse matrix */
cs *cs_spfree (cs *A)

/* free a numeric factorization */
csn *cs_nfree (csn *N)

/* free a symbolic factorization */
css *cs_sfree (css *S)

/* allocate a cs_dmperm or cs_scc result */
csd *cs_dalloc (csi m, csi n)

/* free a cs_dmperm or cs_scc result */
csd *cs_dfree (csd *D)

/* free workspace and return a sparse matrix result */
cs *cs_done (cs *C, void *w, void *x, csi ok)

/* free workspace and return csi array result */
csi *cs_idone (csi *p, cs *C, void *w, csi ok)

/* free workspace and return a numeric factorization (Cholesky, LU, or QR) */
csn *cs_ndone (csn *N, cs *C, void *w, void *x, csi ok)

/* free workspace and return a csd result */
csd *cs_ddone (csd *D, cs *C, void *w, csi ok)

/* solve U'x=b where x and b are dense.  x=b on input, solution on output. */
csi cs_utsolve (const cs *U, double *x)

你是否注意到那些看起来像你想要的东西?我不。基于以上所述,函数cs_print()似乎比大多数其他函数更有可能成为候选者。但是,当我查看cs_print()来源时,我似乎没有看到你想要的内容。相反,我看到一个似乎只对待非零元素的例程。