1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
//------------------------------------------------------------------------------
// GB_mex_Matrix_subref: C=A(I,J)
//------------------------------------------------------------------------------
// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2020, All Rights Reserved.
// http://suitesparse.com See GraphBLAS/Doc/License.txt for license.
//------------------------------------------------------------------------------
#include "GB_mex.h"
#define USAGE "C = GB_mex_Matrix_subref (A, I, J)"
#define FREE_ALL \
{ \
GB_MATRIX_FREE (&A) ; \
GB_MATRIX_FREE (&C) ; \
GB_mx_put_global (true, 0) ; \
}
void mexFunction
(
int nargout,
mxArray *pargout [ ],
int nargin,
const mxArray *pargin [ ]
)
{
bool malloc_debug = GB_mx_get_global (true) ;
GrB_Matrix A = NULL ;
GrB_Matrix C = NULL ;
GrB_Index *I = NULL, ni = 0, I_range [3] ;
GrB_Index *J = NULL, nj = 0, J_range [3] ;
bool ignore ;
// check inputs
GB_WHERE (USAGE) ;
if (nargout > 1 || nargin != 3)
{
mexErrMsgTxt ("Usage: " USAGE) ;
}
#define GET_DEEP_COPY ;
#define FREE_DEEP_COPY ;
// get A (shallow copy)
A = GB_mx_mxArray_to_Matrix (pargin [0], "A", false, true) ;
if (A == NULL)
{
FREE_ALL ;
mexErrMsgTxt ("A failed") ;
}
// get I
if (!GB_mx_mxArray_to_indices (&I, pargin [1], &ni, I_range, &ignore))
{
FREE_ALL ;
mexErrMsgTxt ("I failed") ;
}
// get J
if (!GB_mx_mxArray_to_indices (&J, pargin [2], &nj, J_range, &ignore))
{
FREE_ALL ;
mexErrMsgTxt ("J failed") ;
}
// C = A(I,J)
METHOD (GB_subref (&C, true, A, I, ni, J, nj, false, true, Context)) ;
// return C to MATLAB
pargout [0] = GB_mx_Matrix_to_mxArray (&C, "C subref result", false) ;
FREE_ALL ;
}
|