EVSL  1.1.0
EigenValues Slicing Library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
cs_dupl.c
Go to the documentation of this file.
1 #include "cs.h"
2 /* remove duplicate entries from A */
4 {
5  CS_INT i, j, p, q, nz = 0, n, m, *Ap, *Ai, *w ;
6  CS_ENTRY *Ax ;
7  if (!CS_CSC (A)) return (0) ; /* check inputs */
8  m = A->m ; n = A->n ; Ap = A->p ; Ai = A->i ; Ax = A->x ;
9  w = cs_malloc (m, sizeof (CS_INT)) ; /* get workspace */
10  if (!w) return (0) ; /* out of memory */
11  for (i = 0 ; i < m ; i++) w [i] = -1 ; /* row i not yet seen */
12  for (j = 0 ; j < n ; j++)
13  {
14  q = nz ; /* column j will start at q */
15  for (p = Ap [j] ; p < Ap [j+1] ; p++)
16  {
17  i = Ai [p] ; /* A(i,j) is nonzero */
18  if (w [i] >= q)
19  {
20  Ax [w [i]] += Ax [p] ; /* A(i,j) is a duplicate */
21  }
22  else
23  {
24  w [i] = nz ; /* record where row i occurs */
25  Ai [nz] = i ; /* keep A(i,j) */
26  Ax [nz++] = Ax [p] ;
27  }
28  }
29  Ap [j] = q ; /* record start of column j */
30  }
31  Ap [n] = nz ; /* finalize A */
32  cs_free (w) ; /* free workspace */
33  return (cs_sprealloc (A, 0)) ; /* remove extra space from A */
34 }
void * cs_free(void *p)
Definition: cs_malloc.c:22
#define cs
Definition: cs.h:637
#define CS_ENTRY
Definition: cs.h:635
CS_INT cs_dupl(cs *A)
Definition: cs_dupl.c:3
#define CS_CSC(A)
Definition: cs.h:659
#define CS_INT
Definition: cs.h:627
CS_INT cs_sprealloc(cs *A, CS_INT nzmax)
Definition: cs_util.c:18
void * cs_malloc(CS_INT n, size_t size)
Definition: cs_malloc.c:10