Go to the documentation of this file.00001 #include "cs.h"
00002
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) ;
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) ;
00011 w = cs_calloc (n, sizeof (int)) ;
00012 if (!C || !w) return (cs_done (C, w, NULL, 0)) ;
00013 Cp = C->p ; Ci = C->i ; Cx = C->x ;
00014 for (k = 0 ; k < nz ; k++) w [Tj [k]]++ ;
00015 cs_cumsum (Cp, w, n) ;
00016 for (k = 0 ; k < nz ; k++)
00017 {
00018 Ci [p = w [Tj [k]]++] = Ti [k] ;
00019 if (Cx) Cx [p] = Tx [k] ;
00020 }
00021 return (cs_done (C, w, NULL, 1)) ;
00022 }