1 #include "cs.h"
2 /* ordering and symbolic analysis for a Cholesky factorization */
cs_schol(CS_INT order,const cs * A)3 css *cs_schol (CS_INT order, const cs *A)
4 {
5 CS_INT n, *c, *post, *P ;
6 cs *C ;
7 css *S ;
8 if (!CS_CSC (A)) return (NULL) ; /* check inputs */
9 n = A->n ;
10 S = cs_calloc (1, sizeof (css)) ; /* allocate result S */
11 if (!S) return (NULL) ; /* out of memory */
12 P = cs_amd (order, A) ; /* P = amd(A+A'), or natural */
13 S->pinv = cs_pinv (P, n) ; /* find inverse permutation */
14 cs_free (P) ;
15 if (order && !S->pinv) return (cs_sfree (S)) ;
16 C = cs_symperm (A, S->pinv, 0) ; /* C = spones(triu(A(P,P))) */
17 S->parent = cs_etree (C, 0) ; /* find etree of C */
18 post = cs_post (S->parent, n) ; /* postorder the etree */
19 c = cs_counts (C, S->parent, post, 0) ; /* find column counts of chol(C) */
20 cs_free (post) ;
21 cs_spfree (C) ;
22 S->cp = cs_malloc (n+1, sizeof (CS_INT)) ; /* allocate result S->cp */
23 S->unz = S->lnz = cs_cumsum (S->cp, c, n) ; /* find column pointers for L */
24 cs_free (c) ;
25 return ((S->lnz >= 0) ? S : cs_sfree (S)) ;
26 }
27