1 //------------------------------------------------------------------------------
2 // GB_mex_random: construct a random matrix, double or Complex
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_random (nrows, ncols, ntuples," \
13 " complex, seed, make_symmetric, no_self_edges, method)"
14
15 #define GET_DEEP_COPY ;
16 #define FREE_DEEP_COPY ;
17 #define FREE_ALL GB_mx_put_global (true) ;
18
mexFunction(int nargout,mxArray * pargout[],int nargin,const mxArray * pargin[])19 void mexFunction
20 (
21 int nargout,
22 mxArray *pargout [ ],
23 int nargin,
24 const mxArray *pargin [ ]
25 )
26 {
27
28 bool malloc_debug = GB_mx_get_global (true) ;
29 GrB_Matrix A = NULL ;
30
31 // check inputs
32 if (nargout > 1 || nargin == 0 || nargin > 8)
33 {
34 mexErrMsgTxt ("Usage: " USAGE) ;
35 }
36
37 int64_t GET_SCALAR (0, int64_t , nrows, 4) ;
38 int64_t GET_SCALAR (1, int64_t , ncols, 4) ;
39 int64_t GET_SCALAR (2, int64_t , ntuples, 0) ;
40 bool GET_SCALAR (3, bool , A_complex, false) ;
41 int64_t GET_SCALAR (4, uint64_t, seed, 1) ;
42 bool GET_SCALAR (5, bool , make_symmetric, false) ;
43 bool GET_SCALAR (6, bool , no_self_edges, false) ;
44 int GET_SCALAR (7, int , method, 0) ;
45
46 // construct the random matrix
47 simple_rand_seed (seed) ;
48 if (method == 3)
49 {
50 // test out-of-memory condition
51 METHOD (random_matrix (&A, make_symmetric, no_self_edges,
52 nrows, ncols, ntuples, method, A_complex)) ;
53 }
54 else
55 {
56 GB_MEX_TIC ;
57 GrB_Info info = random_matrix (&A, make_symmetric, no_self_edges,
58 nrows, ncols, ntuples, method, A_complex) ;
59 GB_MEX_TOC ;
60 if (info != GrB_SUCCESS)
61 {
62 mexErrMsgTxt ("random_matrix failed") ;
63 }
64 }
65
66 // return A to MATLAB
67 pargout [0] = GB_mx_Matrix_to_mxArray (&A, "A final", false) ;
68
69 FREE_ALL ;
70 }
71
72