1 //------------------------------------------------------------------------------
2 // GB_mex_msort_2: sort using GB_msort_2b
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 "[I,J] = GB_mex_msort_2 (I,J,nthreads)"
13
mexFunction(int nargout,mxArray * pargout[],int nargin,const mxArray * pargin[])14 void mexFunction
15 (
16 int nargout,
17 mxArray *pargout [ ],
18 int nargin,
19 const mxArray *pargin [ ]
20 )
21 {
22 bool malloc_debug = GB_mx_get_global (true) ;
23
24 // check inputs
25 if (nargin != 3 || nargout != 2)
26 {
27 mexErrMsgTxt ("Usage: " USAGE) ;
28 }
29 if (!mxIsClass (pargin [0], "int64"))
30 {
31 mexErrMsgTxt ("I must be a int64 array") ;
32 }
33 if (!mxIsClass (pargin [1], "int64"))
34 {
35 mexErrMsgTxt ("J must be a int64 array") ;
36 }
37
38 int64_t *I = mxGetData (pargin [0]) ;
39 int64_t n = (uint64_t) mxGetNumberOfElements (pargin [0]) ;
40
41 int64_t *J = mxGetData (pargin [1]) ;
42 if (n != (uint64_t) mxGetNumberOfElements (pargin [1]))
43 {
44 mexErrMsgTxt ("I and J must be the same length") ;
45 }
46
47 int GET_SCALAR (2, int, nthreads, 1) ;
48
49 // make a copy of the input arrays
50 pargout [0] = GB_mx_create_full (n, 1, GrB_INT64) ;
51 int64_t *Iout = mxGetData (pargout [0]) ;
52 memcpy (Iout, I, n * sizeof (int64_t)) ;
53
54 pargout [1] = GB_mx_create_full (n, 1, GrB_INT64) ;
55 int64_t *Jout = mxGetData (pargout [1]) ;
56 memcpy (Jout, J, n * sizeof (int64_t)) ;
57
58 GB_MEX_TIC ;
59 GB_msort_2b (Iout, Jout, n, nthreads) ;
60 GB_MEX_TOC ;
61
62 GB_mx_put_global (true) ;
63 }
64
65