void mexFunction ( int nargout, mxArray *pargout [ ], int nargin, const mxArray *pargin [ ] ) { bool malloc_debug = GB_mx_get_global (true) ; GrB_Matrix C = NULL ; GrB_Descriptor desc = 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 < 2 || nargin > 5) { mexErrMsgTxt ("Usage: " USAGE) ; } // get C (make a deep copy) #define GET_DEEP_COPY \ C = GB_mx_mxArray_to_Matrix (pargin [0], "C input", true, true) ; #define FREE_DEEP_COPY GB_MATRIX_FREE (&C) ; GET_DEEP_COPY ; if (C == NULL) { FREE_ALL ; mexErrMsgTxt ("C failed") ; } mxClassID cclass = GB_mx_Type_to_classID (C->type) ; // get accum; default: NOP, default class is class(C) GrB_BinaryOp accum ; if (!GB_mx_mxArray_to_BinaryOp (&accum, pargin [1], "accum", GB_NOP_opcode, cclass, C->type == Complex, C->type == Complex)) { FREE_ALL ; mexErrMsgTxt ("accum failed") ; } // get I if (!GB_mx_mxArray_to_indices (&I, PARGIN (2), &ni, I_range, &ignore)) { FREE_ALL ; mexErrMsgTxt ("I failed") ; } // get J if (!GB_mx_mxArray_to_indices (&J, PARGIN (3), &nj, J_range, &ignore)) { FREE_ALL ; mexErrMsgTxt ("J failed") ; } // get desc if (!GB_mx_mxArray_to_Descriptor (&desc, PARGIN (4), "desc")) { FREE_ALL ; mexErrMsgTxt ("desc failed") ; } GrB_Index nrows, ncols ; GrB_Matrix_nvals (&nrows, C) ; GrB_Matrix_nvals (&ncols, C) ; // C(I,J) = accum (C(I,J),C) METHOD (GrB_assign (C, NULL, accum, C, I, ni, J, nj, desc)) ; GrB_wait ( ) ; TOC ; // return C to MATLAB as a struct and free the GraphBLAS C pargout [0] = GB_mx_Matrix_to_mxArray (&C, "C output", true) ; FREE_ALL ; }
void mexFunction ( int nargout, mxArray *pargout [ ], int nargin, const mxArray *pargin [ ] ) { bool malloc_debug = GB_mx_get_global (true) ; GrB_Matrix C = NULL ; GrB_Matrix Mask = NULL ; GrB_Matrix A = NULL ; GrB_Descriptor desc = NULL ; GrB_Index *I = NULL, ni = 0, I_range [3] ; GrB_Index *J = NULL, nj = 0, J_range [3] ; bool ignore ; GB_WHERE (USAGE) ; // check inputs if (nargout > 1 || nargin < 6 || nargin > 7) { mexErrMsgTxt ("Usage: " USAGE) ; } // get C (make a deep copy) #define GET_DEEP_COPY \ C = GB_mx_mxArray_to_Matrix (pargin [0], "C input", true, true) ; #define FREE_DEEP_COPY GB_MATRIX_FREE (&C) ; GET_DEEP_COPY ; if (C == NULL) { FREE_ALL ; mexErrMsgTxt ("C failed") ; } mxClassID cclass = GB_mx_Type_to_classID (C->type) ; // get Mask (shallow copy) Mask = GB_mx_mxArray_to_Matrix (pargin [1], "Mask", false, false) ; if (Mask == NULL && !mxIsEmpty (pargin [1])) { FREE_ALL ; mexErrMsgTxt ("Mask failed") ; } // get A (shallow copy) A = GB_mx_mxArray_to_Matrix (pargin [3], "A input", false, true) ; if (A == NULL) { FREE_ALL ; mexErrMsgTxt ("A failed") ; } // get accum; default: NOP, default class is class(C) GrB_BinaryOp accum ; if (!GB_mx_mxArray_to_BinaryOp (&accum, pargin [2], "accum", GB_NOP_opcode, cclass, C->type == Complex, A->type == Complex)) { FREE_ALL ; mexErrMsgTxt ("accum failed") ; } // get I if (!GB_mx_mxArray_to_indices (&I, pargin [4], &ni, I_range, &ignore)) { FREE_ALL ; mexErrMsgTxt ("I failed") ; } // get J if (!GB_mx_mxArray_to_indices (&J, pargin [5], &nj, J_range, &ignore)) { FREE_ALL ; mexErrMsgTxt ("J failed") ; } // get desc if (!GB_mx_mxArray_to_Descriptor (&desc, PARGIN (6), "desc")) { FREE_ALL ; mexErrMsgTxt ("desc failed") ; } // C<Mask> = accum (C,A(I,J)) METHOD (GrB_extract (C, Mask, accum, A, I, ni, J, nj, desc)) ; // return C to MATLAB as a struct and free the GraphBLAS C pargout [0] = GB_mx_Matrix_to_mxArray (&C, "C output", true) ; FREE_ALL ; }