1 /* ========================================================================== */
2 /* === CHOLMOD/MATLAB/spsym mexFunction ===================================== */
3 /* ========================================================================== */
4 
5 /* -----------------------------------------------------------------------------
6  * CHOLMOD/MATLAB Module.  Copyright (C) 2005-2006, Timothy A. Davis
7  * http://www.suitesparse.com
8  * MATLAB(tm) is a Trademark of The MathWorks, Inc.
9  * -------------------------------------------------------------------------- */
10 
11 /* [result xmatched pmatched nzoffdiag nzdiag] = spsym (A, quick).
12  * See the spsym.m file for a description of what it computes.
13  */
14 
15 #include "cholmod_matlab.h"
16 
mexFunction(int nargout,mxArray * pargout[],int nargin,const mxArray * pargin[])17 void mexFunction
18 (
19     int	nargout,
20     mxArray *pargout [ ],
21     int	nargin,
22     const mxArray *pargin [ ]
23 )
24 {
25     double dummy = 0 ;
26     cholmod_sparse Amatrix, *A ;
27     cholmod_common Common, *cm ;
28     Long result, quick, option, xmatched, pmatched, nzoffdiag, nzdiag ;
29 
30     /* ---------------------------------------------------------------------- */
31     /* start CHOLMOD and set parameters */
32     /* ---------------------------------------------------------------------- */
33 
34     cm = &Common ;
35     cholmod_l_start (cm) ;
36     sputil_config (SPUMONI, cm) ;
37 
38     /* ---------------------------------------------------------------------- */
39     /* get inputs */
40     /* ---------------------------------------------------------------------- */
41 
42     if (nargin > 2 || nargin < 1 || nargout > 5)
43     {
44 	mexErrMsgTxt ("usage: [s xmatch pmatch nzoff nzd] = spsym (A,quick)") ;
45     }
46     if (!mxIsSparse (pargin [0]))
47     {
48     	mexErrMsgTxt ("A must be sparse and double") ;
49     }
50 
51     /* get sparse matrix A */
52     A = sputil_get_sparse (pargin [0], &Amatrix, &dummy, 0) ;
53 
54     /* get the "quick" parameter */
55     quick = (nargin > 1) ? (mxGetScalar (pargin [1]) != 0) : FALSE ;
56 
57     if (nargout > 1)
58     {
59 	option = 2 ;
60     }
61     else if (quick)
62     {
63 	option = 0 ;
64     }
65     else
66     {
67 	option = 1 ;
68     }
69 
70     /* ---------------------------------------------------------------------- */
71     /* determine symmetry */
72     /* ---------------------------------------------------------------------- */
73 
74     xmatched = 0 ;
75     pmatched = 0 ;
76     nzoffdiag = 0 ;
77     nzdiag = 0 ;
78 
79     result = cholmod_l_symmetry (A, option, &xmatched, &pmatched, &nzoffdiag,
80 	&nzdiag, cm) ;
81 
82     /* ---------------------------------------------------------------------- */
83     /* return results to MATLAB */
84     /* ---------------------------------------------------------------------- */
85 
86     pargout [0] = sputil_put_int (&result, 1, 0) ;
87 
88     if (nargout > 1) pargout [1] = sputil_put_int (&xmatched, 1, 0) ;
89     if (nargout > 2) pargout [2] = sputil_put_int (&pmatched, 1, 0) ;
90     if (nargout > 3) pargout [3] = sputil_put_int (&nzoffdiag, 1, 0) ;
91     if (nargout > 4) pargout [4] = sputil_put_int (&nzdiag, 1, 0) ;
92 
93     /* ---------------------------------------------------------------------- */
94     /* free workspace */
95     /* ---------------------------------------------------------------------- */
96 
97     cholmod_l_finish (cm) ;
98     cholmod_l_print_common (" ", cm) ;
99 }
100