cs_symperm.c
Go to the documentation of this file.
00001 #include "cs.h"
00002 /* C = A(p,p) where A and C are symmetric the upper part stored; pinv not p */
00003 cs *cs_symperm (const cs *A, const int *pinv, int values)
00004 {
00005     int i, j, p, q, i2, j2, n, *Ap, *Ai, *Cp, *Ci, *w ;
00006     double *Cx, *Ax ;
00007     cs *C ;
00008     if (!CS_CSC (A)) return (NULL) ;                    /* check inputs */
00009     n = A->n ; Ap = A->p ; Ai = A->i ; Ax = A->x ;
00010     C = cs_spalloc (n, n, Ap [n], values && (Ax != NULL), 0) ; /* alloc result*/
00011     w = cs_calloc (n, sizeof (int)) ;                   /* get workspace */
00012     if (!C || !w) return (cs_done (C, w, NULL, 0)) ;    /* out of memory */
00013     Cp = C->p ; Ci = C->i ; Cx = C->x ;
00014     for (j = 0 ; j < n ; j++)           /* count entries in each column of C */
00015     {
00016         j2 = pinv ? pinv [j] : j ;      /* column j of A is column j2 of C */
00017         for (p = Ap [j] ; p < Ap [j+1] ; p++)
00018         {
00019             i = Ai [p] ;
00020             if (i > j) continue ;       /* skip lower triangular part of A */
00021             i2 = pinv ? pinv [i] : i ;  /* row i of A is row i2 of C */
00022             w [CS_MAX (i2, j2)]++ ;     /* column count of C */
00023         }
00024     }
00025     cs_cumsum (Cp, w, n) ;              /* compute column pointers of C */
00026     for (j = 0 ; j < n ; j++)
00027     {
00028         j2 = pinv ? pinv [j] : j ;      /* column j of A is column j2 of C */
00029         for (p = Ap [j] ; p < Ap [j+1] ; p++)
00030         {
00031             i = Ai [p] ;
00032             if (i > j) continue ;       /* skip lower triangular part of A*/
00033             i2 = pinv ? pinv [i] : i ;  /* row i of A is row i2 of C */
00034             Ci [q = w [CS_MAX (i2, j2)]++] = CS_MIN (i2, j2) ;
00035             if (Cx) Cx [q] = Ax [p] ;
00036         }
00037     }
00038     return (cs_done (C, w, NULL, 1)) ;  /* success; free workspace, return C */
00039 }


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