1 //------------------------------------------------------------------------------
2 // GB_mex_wathen: construct a random finite-element matrix
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 #include "GB_mex.h"
11 
12 #define USAGE "A = GB_mex_wathen (nx, ny, method, scale, rho)"
13 
14 #define FREE_ALL GB_mx_put_global (true) ;
15 
mexFunction(int nargout,mxArray * pargout[],int nargin,const mxArray * pargin[])16 void mexFunction
17 (
18     int nargout,
19     mxArray *pargout [ ],
20     int nargin,
21     const mxArray *pargin [ ]
22 )
23 {
24 
25     bool malloc_debug = GB_mx_get_global (true) ;
26     GrB_Matrix A = NULL ;
27 
28     // check inputs
29     if (nargout > 1 || nargin > 5)
30     {
31         mexErrMsgTxt ("Usage: " USAGE) ;
32     }
33 
34     // get nx
35     int64_t GET_SCALAR (0, int64_t, nx, 4) ;
36 
37     // get ny
38     int64_t GET_SCALAR (1, int64_t, ny, 4) ;
39 
40     // get method
41     int GET_SCALAR (2, int, method, 0) ;
42 
43     // get scale
44     bool GET_SCALAR (3, bool, scale, false) ;
45 
46     // get rho
47     double *rho = NULL ;
48     if (nargin > 4)
49     {
50         if (mxGetM (pargin [4]) != nx || mxGetN (pargin [4]) != ny)
51         {
52             mexErrMsgTxt ("rho has wrong size") ;
53         }
54         if (!mxIsClass (pargin [4], "double") || mxIsSparse (pargin [4]))
55         {
56             mexErrMsgTxt ("rho must be a dense and double") ;
57         }
58         rho = mxGetData (pargin [4]) ;
59     }
60 
61     // construct the Wathen matrix
62     simple_rand_seed (1) ;
63     GrB_Info info = wathen (&A, nx, ny, scale, method, rho) ;
64     if (info != GrB_SUCCESS)
65     {
66         mexErrMsgTxt ("wathen failed") ;
67     }
68 
69     // return A to MATLAB
70     pargout [0] = GB_mx_Matrix_to_mxArray (&A, "A final", false) ;
71 
72     FREE_ALL ;
73 }
74 
75