#include "cs_mex.h" /* cs_sparse27: convert triplet form into compress-column form sparse matrix */ void mexFunction ( int nargout, mxArray *pargout [ ], int nargin, const mxArray *pargin [ ] ) { cs *A, *C, *T, Tmatrix ; if (nargout > 1 || nargin != 3) { mexErrMsgTxt ("Usage: A = cs_sparse(i,j,x)") ; } T = &Tmatrix ; /* get i,j,x and copy to triplet form */ T->nz = mxGetM (pargin [0]) ; /* note the next 2 lines differ from cs_sparse: */ T->i = cs_mex_get_int (T->nz, pargin [0], &(T->m), 1) ; T->p = cs_mex_get_int (T->nz, pargin [1], &(T->n), 1) ; cs_mex_check (1, T->nz, 1, 0, 0, 1, pargin [2]) ; T->x = mxGetPr (pargin [2]) ; T->nzmax = T->nz ; C = cs_compress (T) ; /* create sparse matrix C */ cs_dupl (C) ; /* remove duplicates from C */ cs_dropzeros (C) ; /* remove zeros from C */ /* note that the columns of C contain row indices in unsorted order. compare this function with cs_sparse_mex.c. sort the matrix C here, for problems 2.7 and 2.8. call this function cs_sparse27 for problem 2.7, and cs_sparse28 for problem 2.8 */ /* for example: */ cs_sort (C) ; /* below, if you've created another matrix instead of C, return it instead. be sure to free any matrices you do not return to MATLAB */ pargout [0] = cs_mex_put_sparse (&C) ; /* return C */ cs_free (T->p) ; cs_free (T->i) ; }