EVSL  1.1.0 EigenValues Slicing Library
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 CS_INT cs_fkeep (cs *A, CS_INT (*fkeep) (CS_INT, CS_INT, CS_ENTRY, void *), void *other)
4 {
5  CS_INT j, p, nz = 0, n, *Ap, *Ai ;
6  CS_ENTRY *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 }
#define cs
Definition: cs.h:637
#define CS_ENTRY
Definition: cs.h:635
#define CS_CSC(A)
Definition: cs.h:659
CS_INT cs_fkeep(cs *A, CS_INT(*fkeep)(CS_INT, CS_INT, CS_ENTRY, void *), void *other)
Definition: cs_fkeep.c:3
#define CS_INT
Definition: cs.h:627
CS_INT cs_sprealloc(cs *A, CS_INT nzmax)
Definition: cs_util.c:18