cs_dupl.c
Go to the documentation of this file.
00001 #include "cs.h"
00002 /* remove duplicate entries from A */
00003 int cs_dupl (cs *A)
00004 {
00005     int i, j, p, q, nz = 0, n, m, *Ap, *Ai, *w ;
00006     double *Ax ;
00007     if (!CS_CSC (A)) return (0) ;               /* check inputs */
00008     m = A->m ; n = A->n ; Ap = A->p ; Ai = A->i ; Ax = A->x ;
00009     w = (int*) cs_malloc (m, sizeof (int)) ;           /* get workspace */
00010     if (!w) return (0) ;                        /* out of memory */
00011     for (i = 0 ; i < m ; i++) w [i] = -1 ;      /* row i not yet seen */
00012     for (j = 0 ; j < n ; j++)
00013     {
00014         q = nz ;                                /* column j will start at q */
00015         for (p = Ap [j] ; p < Ap [j+1] ; p++)
00016         {
00017             i = Ai [p] ;                        /* A(i,j) is nonzero */
00018             if (w [i] >= q)
00019             {
00020                 Ax [w [i]] += Ax [p] ;          /* A(i,j) is a duplicate */
00021             }
00022             else
00023             {
00024                 w [i] = nz ;                    /* record where row i occurs */
00025                 Ai [nz] = i ;                   /* keep A(i,j) */
00026                 Ax [nz++] = Ax [p] ;
00027             }
00028         }
00029         Ap [j] = q ;                            /* record start of column j */
00030     }
00031     Ap [n] = nz ;                               /* finalize A */
00032     cs_free (w) ;                               /* free workspace */
00033     return (cs_sprealloc (A, 0)) ;              /* remove extra space from A */
00034 }


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Sat Jun 8 2019 19:36:56