Mercurial > hg > smallbox
annotate util/ksvd utils/sprow.c @ 198:83af80baf959 luisf_dev
Reverted SMALL_two_step to the original version; adds path in the Init script.
author | luisf <luis.figueira@eecs.qmul.ac.uk> |
---|---|
date | Tue, 20 Mar 2012 12:29:47 +0000 |
parents | c3eca463202d |
children |
rev | line source |
---|---|
idamnjanovic@70 | 1 /************************************************************************** |
idamnjanovic@70 | 2 * |
idamnjanovic@70 | 3 * File name: sprow.c |
idamnjanovic@70 | 4 * |
idamnjanovic@70 | 5 * Ron Rubinstein |
idamnjanovic@70 | 6 * Computer Science Department |
idamnjanovic@70 | 7 * Technion, Haifa 32000 Israel |
idamnjanovic@70 | 8 * ronrubin@cs |
idamnjanovic@70 | 9 * |
idamnjanovic@70 | 10 * Last Updated: 24.8.2009 |
idamnjanovic@70 | 11 * |
idamnjanovic@70 | 12 *************************************************************************/ |
idamnjanovic@70 | 13 |
idamnjanovic@70 | 14 |
idamnjanovic@70 | 15 #include "mex.h" |
idamnjanovic@70 | 16 #include "mexutils.h" |
idamnjanovic@70 | 17 |
idamnjanovic@70 | 18 |
idamnjanovic@70 | 19 /* Input Arguments */ |
idamnjanovic@70 | 20 |
idamnjanovic@70 | 21 #define A_IN prhs[0] |
idamnjanovic@70 | 22 #define J_IN prhs[1] |
idamnjanovic@70 | 23 |
idamnjanovic@70 | 24 |
idamnjanovic@70 | 25 /* Output Arguments */ |
idamnjanovic@70 | 26 |
idamnjanovic@70 | 27 #define X_OUT plhs[0] |
idamnjanovic@70 | 28 #define ID_OUT plhs[1] |
idamnjanovic@70 | 29 |
idamnjanovic@70 | 30 |
idamnjanovic@70 | 31 void mexFunction(int nlhs, mxArray *plhs[], |
idamnjanovic@70 | 32 int nrhs, const mxArray*prhs[]) |
idamnjanovic@70 | 33 |
idamnjanovic@70 | 34 { |
idamnjanovic@70 | 35 double *pr, *x, *id, rowid; |
idamnjanovic@70 | 36 mwIndex *ir, *jc; |
idamnjanovic@70 | 37 mwSize m, n; |
idamnjanovic@70 | 38 mwIndex i, j, k, l, rowlen; |
idamnjanovic@70 | 39 |
idamnjanovic@70 | 40 if (nrhs != 2) { |
idamnjanovic@70 | 41 mexErrMsgTxt("GETSPROW requires two input arguments."); |
idamnjanovic@70 | 42 } else if (nlhs > 2) { |
idamnjanovic@70 | 43 mexErrMsgTxt("Too many output arguments."); |
idamnjanovic@70 | 44 } |
idamnjanovic@70 | 45 |
idamnjanovic@70 | 46 checkmatrix(A_IN, "GETSPROW", "A"); |
idamnjanovic@70 | 47 checksparse(A_IN, "GETSPROW", "A"); |
idamnjanovic@70 | 48 checkscalar(J_IN, "GETSPROW", "J"); |
idamnjanovic@70 | 49 |
idamnjanovic@70 | 50 m = mxGetM(A_IN); |
idamnjanovic@70 | 51 n = mxGetN(A_IN); |
idamnjanovic@70 | 52 |
idamnjanovic@70 | 53 rowid = mxGetScalar(J_IN); |
idamnjanovic@70 | 54 if (rowid < 0) { |
idamnjanovic@70 | 55 mexErrMsgTxt("Invalid row index."); |
idamnjanovic@70 | 56 } |
idamnjanovic@70 | 57 j = (mwIndex)(rowid + 1e-2); |
idamnjanovic@70 | 58 if (j<1 || j>m) { |
idamnjanovic@70 | 59 mexErrMsgTxt("Row index is out of range."); |
idamnjanovic@70 | 60 } |
idamnjanovic@70 | 61 j--; |
idamnjanovic@70 | 62 |
idamnjanovic@70 | 63 pr = mxGetPr(A_IN); |
idamnjanovic@70 | 64 ir = mxGetIr(A_IN); |
idamnjanovic@70 | 65 jc = mxGetJc(A_IN); |
idamnjanovic@70 | 66 |
idamnjanovic@70 | 67 /* Determine length of row */ |
idamnjanovic@70 | 68 rowlen = 0; |
idamnjanovic@70 | 69 for (i=0; i<jc[n]; ++i) { |
idamnjanovic@70 | 70 rowlen += (ir[i]==j); |
idamnjanovic@70 | 71 } |
idamnjanovic@70 | 72 |
idamnjanovic@70 | 73 /* Allocate output parameters */ |
idamnjanovic@70 | 74 X_OUT = mxCreateDoubleMatrix(1, rowlen, mxREAL); |
idamnjanovic@70 | 75 ID_OUT = mxCreateDoubleMatrix(1, rowlen, mxREAL); |
idamnjanovic@70 | 76 |
idamnjanovic@70 | 77 x = mxGetPr(X_OUT); |
idamnjanovic@70 | 78 id = mxGetPr(ID_OUT); |
idamnjanovic@70 | 79 |
idamnjanovic@70 | 80 /* Compute j-th row */ |
idamnjanovic@70 | 81 k=0; |
idamnjanovic@70 | 82 for (l=1; l<=n; ++l) { |
idamnjanovic@70 | 83 i = jc[l-1]; |
idamnjanovic@70 | 84 while (i<jc[l] && ir[i]<j) { |
idamnjanovic@70 | 85 i++; |
idamnjanovic@70 | 86 } |
idamnjanovic@70 | 87 if (i<jc[l] && ir[i]==j) { |
idamnjanovic@70 | 88 x[k] = pr[i]; |
idamnjanovic@70 | 89 id[k] = l; |
idamnjanovic@70 | 90 k++; |
idamnjanovic@70 | 91 } |
idamnjanovic@70 | 92 } |
idamnjanovic@70 | 93 |
idamnjanovic@70 | 94 } |