EVSL  1.1.0
EigenValues Slicing Library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
cs_compress.c
Go to the documentation of this file.
1 #include "cs.h"
2 /* C = compressed-column form of a triplet matrix T */
3 cs *cs_compress (const cs *T)
4 {
5  CS_INT m, n, nz, p, k, *Cp, *Ci, *w, *Ti, *Tj ;
6  CS_ENTRY *Cx, *Tx ;
7  cs *C ;
8  if (!CS_TRIPLET (T)) return (NULL) ; /* check inputs */
9  m = T->m ; n = T->n ; Ti = T->i ; Tj = T->p ; Tx = T->x ; nz = T->nz ;
10  C = cs_spalloc (m, n, nz, Tx != NULL, 0) ; /* allocate result */
11  w = cs_calloc (n, sizeof (CS_INT)) ; /* get workspace */
12  if (!C || !w) return (cs_done (C, w, NULL, 0)) ; /* out of memory */
13  Cp = C->p ; Ci = C->i ; Cx = C->x ;
14  for (k = 0 ; k < nz ; k++) w [Tj [k]]++ ; /* column counts */
15  cs_cumsum (Cp, w, n) ; /* column pointers */
16  for (k = 0 ; k < nz ; k++)
17  {
18  Ci [p = w [Tj [k]]++] = Ti [k] ; /* A(i,j) is the pth entry in C */
19  if (Cx) Cx [p] = Tx [k] ;
20  }
21  return (cs_done (C, w, NULL, 1)) ; /* success; free w and return C */
22 }
#define cs
Definition: cs.h:637
double cs_cumsum(CS_INT *p, CS_INT *c, CS_INT n)
Definition: cs_cumsum.c:3
#define CS_ENTRY
Definition: cs.h:635
cs * cs_spalloc(CS_INT m, CS_INT n, CS_INT nzmax, CS_INT values, CS_INT triplet)
Definition: cs_util.c:3
void * cs_calloc(CS_INT n, size_t size)
Definition: cs_malloc.c:16
#define CS_INT
Definition: cs.h:627
cs * cs_compress(const cs *T)
Definition: cs_compress.c:3
cs * cs_done(cs *C, void *w, void *x, CS_INT ok)
Definition: cs_util.c:90
#define CS_TRIPLET(A)
Definition: cs.h:660