summaryrefslogtreecommitdiffstats
path: root/SD-VBS/common/toolbox/mex_template.c
blob: b85683f33bebdbf4ae823d71dbcce37a920d9a63 (plain) (blame)
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
//function W = mex_template(X,Y);

#include <math.h>
#include <mex.h>
//#include <matrix.h>
//#include "mex_util.cpp"

//#define PI 3.1415927

void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray 
*in[]) {
    //reading in
    const mxArray *X = in[0];
    double *pr = mxGetPr(X);
    int *ir = mxGetIr(X);
    int *jc = mxGetJc(X);
    int m = mxGetM(X);
    int n = mxGetN(X);
    
    mxArray *cell_1 = mxGetCell(cell_input,0);
    mxGetData()
    mxGetNumberOfDimensions()
    mxGetDimensions()
    mxGetNumberOfElements()
    
    //sparse array reading
    int i,j,k;
    double x;
    for (j=0;j<n;j++)
        for (k=jc[j]; k!=jc[j+1]; k++) {
            i = ir[k];
            x = pr[k];
            //x = X(i,j);
        }
    
    //printing variables & debugging
    int nnz = jc[n];
    mexPrintf("nnz = %d\n",nnz);
    double z = 0.15;
    mexPrintf("z = %1.3g \n",z);
    mexErrMsgTxt("Stopped\n");
    
    //common functions
    fabs(x) // absolute value of float x
    
    //writing out
    mxArray *W = mxCreateSparse(m, n, nnz, mxREAL);

    
    mxArray *args[2];
    args[0] = (mxArray*) prhs[0];
    args[1] = mxCreateDoubleScalar(2.0);
    mexCallMATLAB(1, plhs, 2, args, "sum");

    //allocating, desallocating
    int *ind = (int*)mxCalloc(n,sizeof(int));
    mxFree(ind);
}