cs_compress.c
Go to the documentation of this file.
00001 #include "cs.h"
00002 /* C = compressed-column form of a triplet matrix T */
00003 cs *cs_compress (const cs *T)
00004 {
00005     int m, n, nz, p, k, *Cp, *Ci, *w, *Ti, *Tj ;
00006     double *Cx, *Tx ;
00007     cs *C ;
00008     if (!CS_TRIPLET (T)) return (NULL) ;                /* check inputs */
00009     m = T->m ; n = T->n ; Ti = T->i ; Tj = T->p ; Tx = T->x ; nz = T->nz ;
00010     C = cs_spalloc (m, n, nz, Tx != NULL, 0) ;          /* allocate 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 (k = 0 ; k < nz ; k++) w [Tj [k]]++ ;           /* column counts */
00015     cs_cumsum (Cp, w, n) ;                              /* column pointers */
00016     for (k = 0 ; k < nz ; k++)
00017     {
00018         Ci [p = w [Tj [k]]++] = Ti [k] ;    /* A(i,j) is the pth entry in C */
00019         if (Cx) Cx [p] = Tx [k] ;
00020     }
00021     return (cs_done (C, w, NULL, 1)) ;      /* success; free w and return C */
00022 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


hogman_minimal
Author(s): Maintained by Juergen Sturm
autogenerated on Wed Dec 26 2012 15:36:47