1 //------------------------------------------------------------------------------
2 // GB_mex_clear: clear 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 // clear a matrix
11
12 #include "GB_mex.h"
13
14 #define USAGE "C = GB_mex_clear (A)"
15
16 #define FREE_ALL \
17 { \
18 GrB_Matrix_free_(&A) ; \
19 GrB_Matrix_free_(&C) ; \
20 GB_mx_put_global (true) ; \
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, C = NULL ;
34
35 // check inputs
36 if (nargout > 1 || nargin < 1 || nargin > 3)
37 {
38 mexErrMsgTxt ("Usage: " USAGE) ;
39 }
40
41 #define GET_DEEP_COPY GrB_Matrix_dup (&C, A) ;
42 #define FREE_DEEP_COPY GrB_Matrix_free_(&C) ;
43
44 // get A (shallow copy)
45 A = GB_mx_mxArray_to_Matrix (pargin [0], "A input", false, true) ;
46 if (A == NULL)
47 {
48 FREE_ALL ;
49 mexErrMsgTxt ("A failed") ;
50 }
51
52 // output matrix has same type as input matrix
53 GrB_Type ctype = A->type ;
54
55 // copy A into C
56 GrB_Matrix_dup (&C, A) ;
57
58 // clear C
59 METHOD (GrB_Matrix_clear (C)) ;
60
61 // return C to MATLAB as a struct and free the GraphBLAS C
62 pargout [0] = GB_mx_Matrix_to_mxArray (&C, "C output", true) ;
63
64 FREE_ALL ;
65 }
66
67