1 //------------------------------------------------------------------------------
2 // GB_mex_dump: copy and print a 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 "C = GB_mex_dump (A,pr)"
13 
14 #define FREE_ALL                        \
15 {                                       \
16     GrB_Matrix_free_(&A) ;              \
17     Complex_finalize ( ) ;              \
18     GB_mx_put_global (true) ;           \
19 }
20 
mexFunction(int nargout,mxArray * pargout[],int nargin,const mxArray * pargin[])21 void mexFunction
22 (
23     int nargout,
24     mxArray *pargout [ ],
25     int nargin,
26     const mxArray *pargin [ ]
27 )
28 {
29 
30     bool malloc_debug = GB_mx_get_global (false) ;
31     GrB_Matrix A = NULL ;
32 
33     // check inputs
34     if (nargout > 1 || nargin < 1 || nargin > 2)
35     {
36         mexErrMsgTxt ("Usage: " USAGE) ;
37     }
38 
39     // get A (deep copy)
40     A = GB_mx_mxArray_to_Matrix (pargin [0], "A input", true, true) ;
41     if (A == NULL)
42     {
43         FREE_ALL ;
44         mexErrMsgTxt ("A failed") ;
45     }
46 
47     // get pr
48     int GET_SCALAR (1, int, pr, 1) ;
49 
50     // dump the matrix
51     GrB_Info info = GB_Matrix_check (A, "", pr, NULL) ;
52     if (info != GrB_SUCCESS)
53     {
54         mexErrMsgTxt ("matrix fail") ;
55     }
56 
57     // return A to MATLAB as a struct and free the GraphBLAS A
58     pargout [0] = GB_mx_Matrix_to_mxArray (&A, "C output", true) ;
59 
60     FREE_ALL ;
61 }
62 
63