1 //------------------------------------------------------------------------------
2 // GB_mex_isequal: returns true if A and B are equal
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_isequal (A, B)"
13 
14 #define FREE_ALL                        \
15 {                                       \
16     GrB_Matrix_free_(&A) ;              \
17     GrB_Matrix_free_(&B) ;              \
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 (true) ;
31     GrB_Matrix A = NULL ;
32     GrB_Matrix B = NULL ;
33 
34     // check inputs
35     if (nargout > 1 || nargin != 2)
36     {
37         mexErrMsgTxt ("Usage: " USAGE) ;
38     }
39 
40     #define GET_DEEP_COPY ;
41     #define FREE_DEEP_COPY ;
42 
43     // get A and B
44     A = GB_mx_mxArray_to_Matrix (pargin [0], "A", false, true) ;
45     B = GB_mx_mxArray_to_Matrix (pargin [1], "B", false, true) ;
46     if (A == NULL || B == NULL)
47     {
48         FREE_ALL ;
49         mexErrMsgTxt ("failed") ;
50     }
51 
52     // C = all (A == B) ; if type is Complex and Complex != GxB_FC64,
53     // use Complex_eq
54     bool result ;
55     METHOD (isequal (&result, A, B, Complex_eq)) ;
56 
57     // return C to MATLAB as a plain sparse matrix
58     pargout [0] = mxCreateDoubleScalar ((double) result) ;
59 
60     FREE_ALL ;
61 }
62 
63