cs_fkeep.c
Go to the documentation of this file.
00001 #include "cs.h"
00002 /* drop entries for which fkeep(A(i,j)) is false; return nz if OK, else -1 */
00003 int cs_fkeep (cs *A, int (*fkeep) (int, int, double, void *), void *other)
00004 {
00005     int j, p, nz = 0, n, *Ap, *Ai ;
00006     double *Ax ;
00007     if (!CS_CSC (A) || !fkeep) return (-1) ;    /* check inputs */
00008     n = A->n ; Ap = A->p ; Ai = A->i ; Ax = A->x ;
00009     for (j = 0 ; j < n ; j++)
00010     {
00011         p = Ap [j] ;                        /* get current location of col j */
00012         Ap [j] = nz ;                       /* record new location of col j */
00013         for ( ; p < Ap [j+1] ; p++)
00014         {
00015             if (fkeep (Ai [p], j, Ax ? Ax [p] : 1, other))
00016             {
00017                 if (Ax) Ax [nz] = Ax [p] ;  /* keep A(i,j) */
00018                 Ai [nz++] = Ai [p] ;
00019             }
00020         }
00021     }
00022     Ap [n] = nz ;                           /* finalize A */
00023     cs_sprealloc (A, 0) ;                   /* remove extra space from A */
00024     return (nz) ;
00025 }


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Thu Aug 27 2015 11:58:04