annotate _FullBNT/KPMtools/junk.c @ 9:4ea6619cb3f5 tip

removed log files
author matthiasm
date Fri, 11 Apr 2014 15:55:11 +0100
parents b5b38998ef3b
children
rev   line source
matthiasm@8 1
matthiasm@8 2 m = mxGetM(prhs[0]);
matthiasm@8 3 n = mxGetN(prhs[0]);
matthiasm@8 4 pr = mxGetPr(prhs[0]);
matthiasm@8 5 pi = mxGetPi(prhs[0]);
matthiasm@8 6 cmplx = (pi == NULL ? 0 : 1);
matthiasm@8 7
matthiasm@8 8 /* Allocate space for sparse matrix.
matthiasm@8 9 * NOTE: Assume at most 20% of the data is sparse. Use ceil
matthiasm@8 10 * to cause it to round up.
matthiasm@8 11 */
matthiasm@8 12
matthiasm@8 13 percent_sparse = 0.2;
matthiasm@8 14 nzmax = (int)ceil((double)m*(double)n*percent_sparse);
matthiasm@8 15
matthiasm@8 16 plhs[0] = mxCreateSparse(m,n,nzmax,cmplx);
matthiasm@8 17 sr = mxGetPr(plhs[0]);
matthiasm@8 18 si = mxGetPi(plhs[0]);
matthiasm@8 19 irs = mxGetIr(plhs[0]);
matthiasm@8 20 jcs = mxGetJc(plhs[0]);
matthiasm@8 21
matthiasm@8 22 /* Copy nonzeros. */
matthiasm@8 23 k = 0;
matthiasm@8 24 isfull = 0;
matthiasm@8 25 for (j = 0; (j < n); j++) {
matthiasm@8 26 int i;
matthiasm@8 27 jcs[j] = k;
matthiasm@8 28 for (i = 0; (i < m); i++) {
matthiasm@8 29 if (IsNonZero(pr[i]) || (cmplx && IsNonZero(pi[i]))) {
matthiasm@8 30
matthiasm@8 31 /* Check to see if non-zero element will fit in
matthiasm@8 32 * allocated output array. If not, increase
matthiasm@8 33 * percent_sparse by 10%, recalculate nzmax, and augment
matthiasm@8 34 * the sparse array.
matthiasm@8 35 */
matthiasm@8 36 if (k >= nzmax) {
matthiasm@8 37 int oldnzmax = nzmax;
matthiasm@8 38 percent_sparse += 0.1;
matthiasm@8 39 nzmax = (int)ceil((double)m*(double)n*percent_sparse);
matthiasm@8 40
matthiasm@8 41 /* Make sure nzmax increases atleast by 1. */
matthiasm@8 42 if (oldnzmax == nzmax)
matthiasm@8 43 nzmax++;
matthiasm@8 44
matthiasm@8 45 mxSetNzmax(plhs[0], nzmax);
matthiasm@8 46 mxSetPr(plhs[0], mxRealloc(sr, nzmax*sizeof(double)));
matthiasm@8 47 if (si != NULL)
matthiasm@8 48 mxSetPi(plhs[0], mxRealloc(si, nzmax*sizeof(double)));
matthiasm@8 49 mxSetIr(plhs[0], mxRealloc(irs, nzmax*sizeof(int)));
matthiasm@8 50
matthiasm@8 51 sr = mxGetPr(plhs[0]);
matthiasm@8 52 si = mxGetPi(plhs[0]);
matthiasm@8 53 irs = mxGetIr(plhs[0]);
matthiasm@8 54 }
matthiasm@8 55 sr[k] = pr[i];
matthiasm@8 56 if (cmplx) {
matthiasm@8 57 si[k] = pi[i];
matthiasm@8 58 }
matthiasm@8 59 irs[k] = i;
matthiasm@8 60 k++;
matthiasm@8 61 }
matthiasm@8 62 }
matthiasm@8 63 pr += m;
matthiasm@8 64 pi += m;
matthiasm@8 65 }
matthiasm@8 66 jcs[n] = k;
matthiasm@8 67 }