From f618466c25d43f3bae9e40920273bf77de1e1149 Mon Sep 17 00:00:00 2001 From: leochanj105 Date: Mon, 19 Oct 2020 23:09:30 -0400 Subject: initial sd-vbs initial sd-vbs add sd-vbs sd-vbs --- SD-VBS/common/toolbox/MultiNcut/sparsifyc.c | 232 ++++++++++++++++++++++++++++ 1 file changed, 232 insertions(+) create mode 100755 SD-VBS/common/toolbox/MultiNcut/sparsifyc.c (limited to 'SD-VBS/common/toolbox/MultiNcut/sparsifyc.c') diff --git a/SD-VBS/common/toolbox/MultiNcut/sparsifyc.c b/SD-VBS/common/toolbox/MultiNcut/sparsifyc.c new file mode 100755 index 0000000..82fca98 --- /dev/null +++ b/SD-VBS/common/toolbox/MultiNcut/sparsifyc.c @@ -0,0 +1,232 @@ +/*================================================================= +* syntax: SPMX = SPARSIFY(MX, THRES) +* +* SPARSIFY - sparsify the input matrix, i.e. ignore the values +* of the matrix which are below a threshold +* +* Input: - MX: m-by-n matrix (sparse or full) +* - THRES: threshold value (double) +* +* Output: - SPMX: m-by-n sparse matrix only with values +* whose absolut value is above the given threshold +* +* Written by Mirko Visontai (10/24/2003) +*=================================================================*/ + + +#include +#include "mex.h" + +void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) +{ + /* Declare variable */ + int i,m,n,nzmax,newnnz,col,processed,passed; + int starting_row_index, current_row_index, stopping_row_index; + double *in_pr,*in_pi,*out_pr,*out_pi; + int *in_ir,*in_jc,*out_ir,*out_jc; + double thres; + + /* Check for proper number of input and output arguments */ + if ((nlhs != 1) || (nrhs != 2)){ + mexErrMsgTxt("usage: SPMX = SPARSIFY(MX, THRES)."); + } + /* if matrix is complex threshold the norm of the numbers */ + if (mxIsComplex(prhs[0])){ + /* Check data type of input argument */ + if (mxIsSparse(prhs[0])){ + + /* read input */ + in_pr = mxGetPr(prhs[0]); + in_pi = mxGetPi(prhs[0]); + in_ir = mxGetIr(prhs[0]); + in_jc = mxGetJc(prhs[0]); + nzmax = mxGetNzmax(prhs[0]); + m = mxGetM(prhs[0]); + n = mxGetN(prhs[0]); + thres = mxGetScalar(prhs[1]); + + /* Count new nonzeros */ + newnnz=0; + for(i=0; ithres) {newnnz++;} + } + + if (newnnz>0){ + /* create output */ + plhs[0] = mxCreateSparse(m,n,newnnz,mxCOMPLEX); + if (plhs[0]==NULL) + mexErrMsgTxt("Could not allocate enough memory!\n"); + out_pr = mxGetPr(plhs[0]); + out_pi = mxGetPr(plhs[0]); + out_ir = mxGetIr(plhs[0]); + out_jc = mxGetJc(plhs[0]); + passed = 0; + out_jc[0] = 0; + for (col=0; col thres){ + + out_pr[passed]=in_pr[current_row_index]; + out_pi[passed]=in_pi[current_row_index]; + out_ir[passed]=in_ir[current_row_index]; + out_jc[col+1] = out_jc[col+1]+1; + passed++; + } + } + } + } + } + else{ + plhs[0] = mxCreateSparse(m,n,0,mxCOMPLEX); + } + } + else{ /* for full matrices */ + /* read input */ + in_pr = mxGetPr(prhs[0]); + in_pi = mxGetPr(prhs[0]); + m = mxGetM(prhs[0]); + n = mxGetN(prhs[0]); + thres = mxGetScalar(prhs[1]); + + /* Count new nonzeros */ + newnnz=0; + for(i=0; ithres) {newnnz++;} + } + + if (newnnz>0){ + /* create output */ + plhs[0] = mxCreateSparse(m,n,newnnz,mxCOMPLEX); + if (plhs[0]==NULL) + mexErrMsgTxt("Could not allocate enough memory!\n"); + out_pr = mxGetPr(plhs[0]); + out_pi = mxGetPi(plhs[0]); + out_ir = mxGetIr(plhs[0]); + out_jc = mxGetJc(plhs[0]); + passed = 0; + out_jc[0] = 0; + + for (col=0; col thres){ + + out_pr[passed]=in_pr[current_row_index+m*col]; + out_ir[passed]=current_row_index; + out_jc[col+1] = out_jc[col+1]+1; + passed++; + } + } + } + } + else{ + plhs[0] = mxCreateSparse(m,n,0,mxCOMPLEX); + } + } + } + else { + /* Check data type of input argument */ + if (mxIsSparse(prhs[0])){ + + /* read input */ + in_pr = mxGetPr(prhs[0]); + in_ir = mxGetIr(prhs[0]); + in_jc = mxGetJc(prhs[0]); + nzmax = mxGetNzmax(prhs[0]); + n = mxGetN(prhs[0]); + m = mxGetM(prhs[0]); + thres = mxGetScalar(prhs[1]); + + /* Count new nonzeros */ + newnnz=0; + for(i=0; ithres) {newnnz++;} + } + + if (newnnz>0){ + /* create output */ + plhs[0] = mxCreateSparse(m,n,newnnz,mxREAL); + if (plhs[0]==NULL) + mexErrMsgTxt("Could not allocate enough memory!\n"); + out_pr = mxGetPr(plhs[0]); + out_ir = mxGetIr(plhs[0]); + out_jc = mxGetJc(plhs[0]); + passed = 0; + out_jc[0] = 0; + for (col=0; colthres){ + out_pr[passed]=in_pr[current_row_index]; + out_ir[passed]=in_ir[current_row_index]; + out_jc[col+1] = out_jc[col+1]+1; + passed++; + } + } + } + } + } + else{ + plhs[0] = mxCreateSparse(m,n,0,mxREAL); + } + } + else{ /* for full matrices */ + /* read input */ + in_pr = mxGetPr(prhs[0]); + n = mxGetN(prhs[0]); + m = mxGetM(prhs[0]); + thres = mxGetScalar(prhs[1]); + + /* Count new nonzeros */ + newnnz=0; + for(i=0; ithres) {newnnz++;} + } + + if (newnnz>0){ + /* create output */ + plhs[0] = mxCreateSparse(m,n,newnnz,mxREAL); + if (plhs[0]==NULL) + mexErrMsgTxt("Could not allocate enough memory!\n"); + out_pr = mxGetPr(plhs[0]); + out_ir = mxGetIr(plhs[0]); + out_jc = mxGetJc(plhs[0]); + passed = 0; + out_jc[0] = 0; + + for (col=0; colthres){ + out_pr[passed]=in_pr[current_row_index+m*col]; + out_ir[passed]=current_row_index; + out_jc[col+1] = out_jc[col+1]+1; + passed++; + } + } + } + } + else{ + plhs[0] = mxCreateSparse(m,n,0,mxREAL); + } + } + } +} + -- cgit v1.2.2