cs_dupl.c
Go to the documentation of this file.
1 #include "cs.h"
2 /* remove duplicate entries from A */
3 int cs_dupl (cs *A)
4 {
5  int i, j, p, q, nz = 0, n, m, *Ap, *Ai, *w ;
6  double *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 = (int*) cs_malloc (m, sizeof (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 }
int n
Definition: cs.h:20
int cs_dupl(cs *A)
Definition: cs_dupl.c:3
void * cs_free(void *p)
Definition: cs_malloc.c:22
int cs_sprealloc(cs *A, int nzmax)
Definition: cs_util.c:18
#define CS_CSC(A)
Definition: cs.h:140
int * p
Definition: cs.h:21
Definition: cs.h:16
int * i
Definition: cs.h:22
void * cs_malloc(int n, size_t size)
Definition: cs_malloc.c:10
double * x
Definition: cs.h:23
int m
Definition: cs.h:19


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:31