cs_fkeep.c
Go to the documentation of this file.
1 #include "cs.h"
2 /* drop entries for which fkeep(A(i,j)) is false; return nz if OK, else -1 */
3 int cs_fkeep (cs *A, int (*fkeep) (int, int, double, void *), void *other)
4 {
5  int j, p, nz = 0, n, *Ap, *Ai ;
6  double *Ax ;
7  if (!CS_CSC (A) || !fkeep) return (-1) ; /* check inputs */
8  n = A->n ; Ap = A->p ; Ai = A->i ; Ax = A->x ;
9  for (j = 0 ; j < n ; j++)
10  {
11  p = Ap [j] ; /* get current location of col j */
12  Ap [j] = nz ; /* record new location of col j */
13  for ( ; p < Ap [j+1] ; p++)
14  {
15  if (fkeep (Ai [p], j, Ax ? Ax [p] : 1, other))
16  {
17  if (Ax) Ax [nz] = Ax [p] ; /* keep A(i,j) */
18  Ai [nz++] = Ai [p] ;
19  }
20  }
21  }
22  Ap [n] = nz ; /* finalize A */
23  cs_sprealloc (A, 0) ; /* remove extra space from A */
24  return (nz) ;
25 }
int n
Definition: cs.h:20
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
int cs_fkeep(cs *A, int(*fkeep)(int, int, double, void *), void *other)
Definition: cs_fkeep.c:3
double * x
Definition: cs.h:23


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