Mercurial > hg > octave-nkf
comparison examples/code/mysparse.c @ 19225:c8240a60dd01
Add penny.mat to build system.
* examples/data/penny.mat: New example data file.
* examples/data/Makefile.am: Automake file for new directory of example data files.
* examples/Makefile.am: Change to be just a pass-through to the subdirectories
code/ and data/.
* examples/@FIRfilter/FIRfilter.m, examples/@FIRfilter/FIRfilter_aggregation.m,
examples/@FIRfilter/display.m, examples/@FIRfilter/module.mk,
examples/@FIRfilter/subsasgn.m, examples/@FIRfilter/subsref.m,
examples/@polynomial/display.m, examples/@polynomial/double.m,
examples/@polynomial/end.m, examples/@polynomial/get.m,
examples/@polynomial/module.mk, examples/@polynomial/mtimes.m,
examples/@polynomial/numel.m, examples/@polynomial/plot.m,
examples/@polynomial/polynomial.m,
examples/@polynomial/polynomial_superiorto.m, examples/@polynomial/polyval.m,
examples/@polynomial/roots.m, examples/@polynomial/set.m,
examples/@polynomial/subsasgn.m, examples/@polynomial/subsref.m,
examples/COPYING, examples/addtwomatrices.cc, examples/celldemo.cc,
examples/embedded.cc, examples/fortrandemo.cc, examples/fortransub.f,
examples/funcdemo.cc, examples/globaldemo.cc, examples/helloworld.cc,
examples/make_int.cc, examples/mex_demo.c, examples/mycell.c,
examples/myfeval.c, examples/myfevalf.f, examples/myfunc.c, examples/myhello.c,
examples/mypow2.c, examples/myprop.c, examples/myset.c, examples/mysparse.c,
examples/mystring.c, examples/mystruct.c, examples/oct_demo.cc,
examples/oregonator.cc, examples/oregonator.m, examples/paramdemo.cc,
examples/standalone.cc, examples/standalonebuiltin.cc, examples/stringdemo.cc,
examples/structdemo.cc, examples/unwinddemo.cc:
Move current example files to examples/code/ directory.
* configure.ac: Add Makefiles in examples/code and examples/data directories.
* build-aux/common.mk: Define octdatadir variable.
* doc/interpreter/Makefile.am: Change location of External Code Interface
examples to examples/code directory.
* doc/interpreter/munge-texi.pl: Expand EXAMPLEFILE macro to examples/code
directory.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 19 Aug 2014 14:32:44 -0700 |
parents | examples/mysparse.c@9ac2357f19bc |
children |
comparison
equal
deleted
inserted
replaced
19224:d902542221c8 | 19225:c8240a60dd01 |
---|---|
1 #include "mex.h" | |
2 | |
3 void | |
4 mexFunction (int nlhs, mxArray *plhs[], | |
5 int nrhs, const mxArray *prhs[]) | |
6 { | |
7 mwSize m, n, nz; | |
8 mxArray *v; | |
9 mwIndex i; | |
10 double *pr, *pi; | |
11 double *pr2, *pi2; | |
12 mwIndex *ir, *jc; | |
13 mwIndex *ir2, *jc2; | |
14 | |
15 if (nrhs != 1 || ! mxIsSparse (prhs[0])) | |
16 mexErrMsgTxt ("ARG1 must be a 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 { | |
24 mexPrintf ("Matrix is %d-by-%d complex sparse matrix", m, n); | |
25 mexPrintf (" with %d elements\n", nz); | |
26 | |
27 pr = mxGetPr (prhs[0]); | |
28 pi = mxGetPi (prhs[0]); | |
29 ir = mxGetIr (prhs[0]); | |
30 jc = mxGetJc (prhs[0]); | |
31 | |
32 i = n; | |
33 while (jc[i] == jc[i-1] && i != 0) i--; | |
34 | |
35 mexPrintf ("last nonzero element (%d, %d) = (%g, %g)\n", | |
36 ir[nz-1]+ 1, i, pr[nz-1], pi[nz-1]); | |
37 | |
38 v = mxCreateSparse (m, n, nz, mxCOMPLEX); | |
39 pr2 = mxGetPr (v); | |
40 pi2 = mxGetPi (v); | |
41 ir2 = mxGetIr (v); | |
42 jc2 = mxGetJc (v); | |
43 | |
44 for (i = 0; i < nz; i++) | |
45 { | |
46 pr2[i] = 2 * pr[i]; | |
47 pi2[i] = 2 * pi[i]; | |
48 ir2[i] = ir[i]; | |
49 } | |
50 for (i = 0; i < n + 1; i++) | |
51 jc2[i] = jc[i]; | |
52 | |
53 if (nlhs > 0) | |
54 plhs[0] = v; | |
55 } | |
56 else if (mxIsLogical (prhs[0])) | |
57 { | |
58 mxLogical *pbr, *pbr2; | |
59 mexPrintf ("Matrix is %d-by-%d logical sparse matrix", m, n); | |
60 mexPrintf (" with %d elements\n", nz); | |
61 | |
62 pbr = mxGetLogicals (prhs[0]); | |
63 ir = mxGetIr (prhs[0]); | |
64 jc = mxGetJc (prhs[0]); | |
65 | |
66 i = n; | |
67 while (jc[i] == jc[i-1] && i != 0) i--; | |
68 mexPrintf ("last nonzero element (%d, %d) = %d\n", | |
69 ir[nz-1]+ 1, i, pbr[nz-1]); | |
70 | |
71 v = mxCreateSparseLogicalMatrix (m, n, nz); | |
72 pbr2 = mxGetLogicals (v); | |
73 ir2 = mxGetIr (v); | |
74 jc2 = mxGetJc (v); | |
75 | |
76 for (i = 0; i < nz; i++) | |
77 { | |
78 pbr2[i] = pbr[i]; | |
79 ir2[i] = ir[i]; | |
80 } | |
81 for (i = 0; i < n + 1; i++) | |
82 jc2[i] = jc[i]; | |
83 | |
84 if (nlhs > 0) | |
85 plhs[0] = v; | |
86 } | |
87 else | |
88 { | |
89 mexPrintf ("Matrix is %d-by-%d real sparse matrix", m, n); | |
90 mexPrintf (" with %d elements\n", nz); | |
91 | |
92 pr = mxGetPr (prhs[0]); | |
93 ir = mxGetIr (prhs[0]); | |
94 jc = mxGetJc (prhs[0]); | |
95 | |
96 i = n; | |
97 while (jc[i] == jc[i-1] && i != 0) i--; | |
98 mexPrintf ("last nonzero element (%d, %d) = %g\n", | |
99 ir[nz-1]+ 1, i, pr[nz-1]); | |
100 | |
101 v = mxCreateSparse (m, n, nz, mxREAL); | |
102 pr2 = mxGetPr (v); | |
103 ir2 = mxGetIr (v); | |
104 jc2 = mxGetJc (v); | |
105 | |
106 for (i = 0; i < nz; i++) | |
107 { | |
108 pr2[i] = 2 * pr[i]; | |
109 ir2[i] = ir[i]; | |
110 } | |
111 for (i = 0; i < n + 1; i++) | |
112 jc2[i] = jc[i]; | |
113 | |
114 if (nlhs > 0) | |
115 plhs[0] = v; | |
116 } | |
117 } |