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 = (int*)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 }


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Thu Aug 27 2015 11:58:04