File: cs_fkeep.c

package info (click to toggle)
suitesparse-metis 3.1.0-2
  • links: PTS, VCS
  • area: contrib
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 36,560 kB
  • ctags: 7,484
  • sloc: ansic: 104,515; makefile: 5,984; fortran: 4,591; sh: 1,397; csh: 739; ruby: 603; perl: 219; sed: 164; awk: 18
file content (25 lines) | stat: -rw-r--r-- 789 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "cs.h"
/* drop entries for which fkeep(A(i,j)) is false; return nz if OK, else -1 */
int cs_fkeep (cs *A, int (*fkeep) (int, int, double, void *), void *other)
{
    int j, p, nz = 0, n, *Ap, *Ai ;
    double *Ax ;
    if (!CS_CSC (A) || !fkeep) return (-1) ;	/* check inputs */
    n = A->n ; Ap = A->p ; Ai = A->i ; Ax = A->x ;
    for (j = 0 ; j < n ; j++)
    {
	p = Ap [j] ;			    /* get current location of col j */
	Ap [j] = nz ;			    /* record new location of col j */
	for ( ; p < Ap [j+1] ; p++)
	{
	    if (fkeep (Ai [p], j, Ax ? Ax [p] : 1, other))
	    {
		if (Ax) Ax [nz] = Ax [p] ;  /* keep A(i,j) */
		Ai [nz++] = Ai [p] ;
	    }
	}
    }
    Ap [n] = nz ;			    /* finalize A */
    cs_sprealloc (A, 0) ;		    /* remove extra space from A */
    return (nz) ;
}