File: cs_sqr_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 (38 lines) | stat: -rw-r--r-- 1,147 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
#include "cs_mex.h"
/* cs_sqr: symbolic sparse QR factorization */
void mexFunction
(
    int nargout,
    mxArray *pargout [ ],
    int nargin,
    const mxArray *pargin [ ]
)
{
    css *S ;
    csn *N ;
    cs Amatrix, *A ;
    int m, n, order, *leftmost, *P ;
    if (nargout > 6 || nargin != 1)
    {
	mexErrMsgTxt ("Usage: [pinv,leftmost,q,parent,vnz,rnz] = cs_sqr(A)") ;
    }
    A = cs_get_sparse (&Amatrix, 0, 1, pargin [0]) ;	/* get A */
    m = A->m ;
    n = A->n ;

    order = (nargout == 5) ? 2 : -1 ;	    /* determine ordering */
    S = cs_sqr (A, order, 1) ;		    /* symbolic QR ordering & analysis*/

    if (!S) mexErrMsgTxt ("symbolic QR failed") ;

    leftmost = S->Pinv + m + n ;

    pargout [0] = cs_put_int (S->Pinv, S->m2, 1, 0) ;	/* return Pinv */
    pargout [1] = cs_put_int (leftmost, m, 1, 0) ;	/* return leftmost */
    pargout [2] = cs_put_int (S->Q, n, 1, 0) ;		/* return Q */
    pargout [3] = cs_put_int (S->parent, n, 1, 0) ;	/* return parent */
    pargout [4] = mxCreateDoubleScalar (S->lnz) ;	/* return nnz(V) */
    pargout [5] = mxCreateDoubleScalar (S->unz) ;	/* return nnz(R) */

    cs_sfree (S) ;
}