Mercurial > hg > octave-nkf
annotate examples/mysparse.c @ 15078:fe4752f772e2
Generate ND indexing functions on demand in JIT.
* src/jit-typeinfo.cc (jit_operation::~jit_operation,
jit_operation::do_generate, jit_operation::generate,
jit_operation::signature_cmp::operator()): New function.
(jit_operation::overload): Call do_generate when lookup fails.
(jit_index_operation, jit_paren_subsref, jit_paren_subsasgn): New class.
(jit_typeinfo::jit_typeinfo): Update to use jit_paren_subsref and
jit_paren_subsasgn.
(jit_typeinfo::gen_subsref, jit_typeinfo::gen_subsasgn): Removed functions.
* src/jit-typeinfo.h (jit_operation::~jit_operation, jit_operation::generate,
jit_operation::do_generate): New declaration.
(jit_operation::add_overload, jit_operation::overload, jit_operation::result,
jit_operation::to_idx): Use signature_vec typedef.
(jit_operation::singature_cmp): New class.
(jit_index_operation, jit_paren_subsref, jit_paren_subsasgn): New class.
(jit_typeinfo::get_scalar_ptr): Nwe function.
(jit_typeinfo::gen_subsref, jit_typeinfo::gen_subsasgn): Removed declaration.
* src/pt-jit.cc: New test.
author | Max Brister <max@2bass.com> |
---|---|
date | Wed, 01 Aug 2012 17:00:12 -0500 |
parents | 6cb30a539481 |
children | 9a8dbd6b6b20 |
rev | line source |
---|---|
5903 | 1 #include "mex.h" |
2 | |
3 void | |
7081 | 4 mexFunction (int nlhs, mxArray *plhs[], int nrhs, |
9932
6cb30a539481
untabify files in examples directory
John W. Eaton <jwe@octave.org>
parents:
9053
diff
changeset
|
5 const mxArray *prhs[]) |
5903 | 6 { |
6686 | 7 mwSize n, m, nz; |
5903 | 8 mxArray *v; |
6686 | 9 mwIndex i; |
5903 | 10 double *pr, *pi; |
11 double *pr2, *pi2; | |
6686 | 12 mwIndex *ir, *jc; |
13 mwIndex *ir2, *jc2; | |
5903 | 14 |
15 if (nrhs != 1 || ! mxIsSparse (prhs[0])) | |
16 mexErrMsgTxt ("expects sparse matrix"); | |
17 | |
18 m = mxGetM (prhs [0]); | |
19 n = mxGetN (prhs [0]); | |
20 nz = mxGetNzmax (prhs [0]); | |
21 | |
22 if (mxIsComplex (prhs[0])) | |
23 { | |
7081 | 24 mexPrintf ("Matrix is %d-by-%d complex", |
9932
6cb30a539481
untabify files in examples directory
John W. Eaton <jwe@octave.org>
parents:
9053
diff
changeset
|
25 " sparse matrix", m, n); |
6580 | 26 mexPrintf (" with %d elements\n", nz); |
5903 | 27 |
28 pr = mxGetPr (prhs[0]); | |
29 pi = mxGetPi (prhs[0]); | |
30 ir = mxGetIr (prhs[0]); | |
31 jc = mxGetJc (prhs[0]); | |
32 | |
33 i = n; | |
34 while (jc[i] == jc[i-1] && i != 0) i--; | |
7081 | 35 mexPrintf ("last non-zero element (%d, %d) =", |
9932
6cb30a539481
untabify files in examples directory
John W. Eaton <jwe@octave.org>
parents:
9053
diff
changeset
|
36 ir[nz-1]+ 1, i); |
7081 | 37 mexPrintf (" (%g, %g)\n", pr[nz-1], pi[nz-1]); |
5903 | 38 |
39 v = mxCreateSparse (m, n, nz, mxCOMPLEX); | |
40 pr2 = mxGetPr (v); | |
41 pi2 = mxGetPi (v); | |
42 ir2 = mxGetIr (v); | |
43 jc2 = mxGetJc (v); | |
44 | |
45 for (i = 0; i < nz; i++) | |
6580 | 46 { |
47 pr2[i] = 2 * pr[i]; | |
48 pi2[i] = 2 * pi[i]; | |
49 ir2[i] = ir[i]; | |
50 } | |
5903 | 51 for (i = 0; i < n + 1; i++) |
6580 | 52 jc2[i] = jc[i]; |
5903 | 53 |
54 if (nlhs > 0) | |
6580 | 55 plhs[0] = v; |
5903 | 56 } |
57 else if (mxIsLogical (prhs[0])) | |
58 { | |
59 bool *pbr, *pbr2; | |
7081 | 60 mexPrintf ("Matrix is %d-by-%d logical", |
9932
6cb30a539481
untabify files in examples directory
John W. Eaton <jwe@octave.org>
parents:
9053
diff
changeset
|
61 " sparse matrix", m, n); |
6580 | 62 mexPrintf (" with %d elements\n", nz); |
5903 | 63 |
64 pbr = mxGetLogicals (prhs[0]); | |
65 ir = mxGetIr (prhs[0]); | |
66 jc = mxGetJc (prhs[0]); | |
67 | |
68 i = n; | |
69 while (jc[i] == jc[i-1] && i != 0) i--; | |
7081 | 70 mexPrintf ("last non-zero element (%d, %d) = %d\n", |
71 ir[nz-1]+ 1, i, pbr[nz-1]); | |
5903 | 72 |
73 v = mxCreateSparseLogicalMatrix (m, n, nz); | |
74 pbr2 = mxGetLogicals (v); | |
75 ir2 = mxGetIr (v); | |
76 jc2 = mxGetJc (v); | |
77 | |
78 for (i = 0; i < nz; i++) | |
6580 | 79 { |
80 pbr2[i] = pbr[i]; | |
81 ir2[i] = ir[i]; | |
82 } | |
5903 | 83 for (i = 0; i < n + 1; i++) |
6580 | 84 jc2[i] = jc[i]; |
5903 | 85 |
86 if (nlhs > 0) | |
6580 | 87 plhs[0] = v; |
5903 | 88 } |
89 else | |
90 { | |
7081 | 91 mexPrintf ("Matrix is %d-by-%d real", |
9932
6cb30a539481
untabify files in examples directory
John W. Eaton <jwe@octave.org>
parents:
9053
diff
changeset
|
92 " sparse matrix", m, n); |
6580 | 93 mexPrintf (" with %d elements\n", nz); |
5903 | 94 |
95 pr = mxGetPr (prhs[0]); | |
96 ir = mxGetIr (prhs[0]); | |
97 jc = mxGetJc (prhs[0]); | |
98 | |
99 i = n; | |
100 while (jc[i] == jc[i-1] && i != 0) i--; | |
7081 | 101 mexPrintf ("last non-zero element (%d, %d) = %g\n", |
102 ir[nz-1]+ 1, i, pr[nz-1]); | |
5903 | 103 |
104 v = mxCreateSparse (m, n, nz, mxREAL); | |
105 pr2 = mxGetPr (v); | |
106 ir2 = mxGetIr (v); | |
107 jc2 = mxGetJc (v); | |
108 | |
109 for (i = 0; i < nz; i++) | |
6580 | 110 { |
111 pr2[i] = 2 * pr[i]; | |
112 ir2[i] = ir[i]; | |
113 } | |
5903 | 114 for (i = 0; i < n + 1; i++) |
6580 | 115 jc2[i] = jc[i]; |
5903 | 116 |
117 if (nlhs > 0) | |
6580 | 118 plhs[0] = v; |
5903 | 119 } |
120 } |