File: cs_reach_mex.c

package info (click to toggle)
ufsparse 1.2-7
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 27,536 kB
  • ctags: 5,848
  • sloc: ansic: 89,328; makefile: 4,721; fortran: 1,991; csh: 207; sed: 162; awk: 33; java: 30; sh: 8
file content (39 lines) | stat: -rw-r--r-- 1,001 bytes parent folder | download
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "cs_mex.h"
/* find nonzero pattern of x=L\sparse(b).  L must be sparse, real, and lower
 * triangular.  b must be a real sparse vector. */

void mexFunction
(
    int nargout,
    mxArray *pargout [ ],
    int nargin,
    const mxArray *pargin [ ]
)
{
    cs Lmatrix, Bmatrix, *L, *B ;
    double *x ;
    int k, i, j, top, *xi, *perm ;

    if (nargout > 1 || nargin != 2)
    {
	mexErrMsgTxt ("Usage: x = cs_reach(L,b)") ;
    }

    /* get inputs */
    L = cs_get_sparse (&Lmatrix, 1, 1, pargin [0]) ;
    B = cs_get_sparse (&Bmatrix, 0, 1, pargin [1]) ;
    cs_check (0, L->n, 1, 0, 1, 1, pargin [1]) ;
    perm = cs_malloc (L->n, sizeof (int)) ;
    for (k = 0 ; k < L->n ; k++) perm [k] = k ;

    xi = cs_calloc (3*L->n, sizeof (int)) ;

    top = cs_reach (L, B, 0, xi, perm) ;

    pargout [0] = mxCreateDoubleMatrix (L->n - top, 1, mxREAL) ;
    x = mxGetPr (pargout [0]) ;
    for (j = 0, i = top ; i < L->n ; i++, j++) x [j] = xi [i] ;

    cs_free (xi) ;
    cs_free (perm) ;
}