comparison toolboxes/FullBNT-1.0.7/KPMtools/junk.c @ 0:e9a9cd732c1e tip

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