1 //------------------------------------------------------------------------------
2 // GB_mex_mis: s=mis(A), find a maximal independent set
3 //------------------------------------------------------------------------------
4 
5 // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
6 // SPDX-License-Identifier: Apache-2.0
7 
8 //------------------------------------------------------------------------------
9 
10 // s = mis (A) ; A must be symmetric
11 
12 #include "GB_mex.h"
13 
14 #define USAGE "iset = GB_mex_mis (A, seed)"
15 
16 #define FREE_ALL                        \
17 {                                       \
18     GrB_Matrix_free_(&A) ;              \
19     GB_mx_put_global (true) ;           \
20 }
21 
22 
mexFunction(int nargout,mxArray * pargout[],int nargin,const mxArray * pargin[])23 void mexFunction
24 (
25     int nargout,
26     mxArray *pargout [ ],
27     int nargin,
28     const mxArray *pargin [ ]
29 )
30 {
31 
32     bool malloc_debug = GB_mx_get_global (true) ;
33     GrB_Matrix A = NULL, Iset = NULL ;
34     GrB_Vector iset = NULL ;
35 
36     // check inputs
37     if (nargout > 1 || nargin < 1 || nargin > 2)
38     {
39         mexErrMsgTxt ("Usage: " USAGE) ;
40     }
41 
42     // get A
43     A = GB_mx_mxArray_to_Matrix (pargin [0], "A", false, true) ;
44     if (A == NULL)
45     {
46         FREE_ALL ;
47         mexErrMsgTxt ("A failed") ;
48     }
49 
50     // get seed; default is 1
51     uint64_t GET_SCALAR (1, uint64_t, seed, 1) ;
52 
53     // compute the independent set
54     GrB_Info info = mis_check (&iset, A, seed) ;
55     if (info != GrB_SUCCESS)
56     {
57         mexErrMsgTxt ("mis failed") ;
58     }
59 
60     // return iset to MATLAB
61     Iset = (GrB_Matrix) iset ;
62     pargout [0] = GB_mx_Matrix_to_mxArray (&Iset, "iset result", false) ;
63 
64     FREE_ALL ;
65 }
66 
67