idamnjanovic@60
|
1 /**************************************************************************
|
idamnjanovic@60
|
2 *
|
idamnjanovic@60
|
3 * File name: omp2mex.c
|
idamnjanovic@60
|
4 *
|
idamnjanovic@60
|
5 * Ron Rubinstein
|
idamnjanovic@60
|
6 * Computer Science Department
|
idamnjanovic@60
|
7 * Technion, Haifa 32000 Israel
|
idamnjanovic@60
|
8 * ronrubin@cs
|
idamnjanovic@60
|
9 *
|
idamnjanovic@60
|
10 * Last Updated: 18.8.2009
|
idamnjanovic@60
|
11 *
|
idamnjanovic@60
|
12 *************************************************************************/
|
idamnjanovic@60
|
13
|
idamnjanovic@60
|
14 #include "ompcore.h"
|
idamnjanovic@60
|
15 #include "omputils.h"
|
idamnjanovic@60
|
16 #include "mexutils.h"
|
idamnjanovic@60
|
17
|
idamnjanovic@60
|
18
|
idamnjanovic@60
|
19 /* Input Arguments */
|
idamnjanovic@60
|
20
|
idamnjanovic@60
|
21 #define IN_D prhs[0]
|
idamnjanovic@60
|
22 #define IN_X prhs[1]
|
idamnjanovic@60
|
23 #define IN_DtX prhs[2]
|
idamnjanovic@60
|
24 #define IN_XtX prhs[3]
|
idamnjanovic@60
|
25 #define IN_G prhs[4]
|
idamnjanovic@60
|
26 #define IN_EPS prhs[5]
|
idamnjanovic@60
|
27 #define IN_SPARSE_G prhs[6]
|
idamnjanovic@60
|
28 #define IN_MSGDELTA prhs[7]
|
idamnjanovic@60
|
29 #define IN_MAXATOMS prhs[8]
|
idamnjanovic@60
|
30 #define IN_PROFILE prhs[9]
|
idamnjanovic@60
|
31
|
idamnjanovic@60
|
32
|
idamnjanovic@60
|
33 /* Output Arguments */
|
idamnjanovic@60
|
34
|
idamnjanovic@60
|
35 #define GAMMA_OUT plhs[0]
|
idamnjanovic@60
|
36
|
idamnjanovic@60
|
37
|
idamnjanovic@60
|
38 /***************************************************************************************/
|
idamnjanovic@60
|
39
|
idamnjanovic@60
|
40
|
idamnjanovic@60
|
41 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray*prhs[])
|
idamnjanovic@60
|
42
|
idamnjanovic@60
|
43 {
|
idamnjanovic@60
|
44 double *D, *x, *DtX, *XtX, *G, eps, msgdelta;
|
idamnjanovic@60
|
45 int gmode, maxatoms, profile;
|
idamnjanovic@60
|
46 mwSize m, n, L; /* D is n x m , X is n x L, DtX is m x L */
|
idamnjanovic@60
|
47
|
idamnjanovic@60
|
48
|
idamnjanovic@60
|
49 /* check parameters */
|
idamnjanovic@60
|
50
|
idamnjanovic@60
|
51 checkmatrix(IN_D, "OMP2", "D");
|
idamnjanovic@60
|
52 checkmatrix(IN_X, "OMP2", "X");
|
idamnjanovic@60
|
53 checkmatrix(IN_DtX, "OMP2", "DtX");
|
idamnjanovic@60
|
54 checkmatrix(IN_XtX, "OMP2", "XtX");
|
idamnjanovic@60
|
55 checkmatrix(IN_G, "OMP2", "G");
|
idamnjanovic@60
|
56
|
idamnjanovic@60
|
57 checkscalar(IN_EPS, "OMP2", "EPSILON");
|
idamnjanovic@60
|
58 checkscalar(IN_SPARSE_G, "OMP2", "sparse_g");
|
idamnjanovic@60
|
59 checkscalar(IN_MSGDELTA, "OMP2", "msgdelta");
|
idamnjanovic@60
|
60 checkscalar(IN_MAXATOMS, "OMP2", "maxatoms");
|
idamnjanovic@60
|
61 checkscalar(IN_PROFILE, "OMP2", "profile");
|
idamnjanovic@60
|
62
|
idamnjanovic@60
|
63
|
idamnjanovic@60
|
64 /* get parameters */
|
idamnjanovic@60
|
65
|
idamnjanovic@60
|
66 x = D = DtX = XtX = G = 0;
|
idamnjanovic@60
|
67
|
idamnjanovic@60
|
68 if (!mxIsEmpty(IN_D))
|
idamnjanovic@60
|
69 D = mxGetPr(IN_D);
|
idamnjanovic@60
|
70
|
idamnjanovic@60
|
71 if (!mxIsEmpty(IN_X))
|
idamnjanovic@60
|
72 x = mxGetPr(IN_X);
|
idamnjanovic@60
|
73
|
idamnjanovic@60
|
74 if (!mxIsEmpty(IN_DtX))
|
idamnjanovic@60
|
75 DtX = mxGetPr(IN_DtX);
|
idamnjanovic@60
|
76
|
idamnjanovic@60
|
77 if (!mxIsEmpty(IN_XtX))
|
idamnjanovic@60
|
78 XtX = mxGetPr(IN_XtX);
|
idamnjanovic@60
|
79
|
idamnjanovic@60
|
80 if (!mxIsEmpty(IN_G))
|
idamnjanovic@60
|
81 G = mxGetPr(IN_G);
|
idamnjanovic@60
|
82
|
idamnjanovic@60
|
83 eps = mxGetScalar(IN_EPS);
|
idamnjanovic@60
|
84 if ((int)(mxGetScalar(IN_SPARSE_G)+1e-2)) {
|
idamnjanovic@60
|
85 gmode = SPARSE_GAMMA;
|
idamnjanovic@60
|
86 }
|
idamnjanovic@60
|
87 else {
|
idamnjanovic@60
|
88 gmode = FULL_GAMMA;
|
idamnjanovic@60
|
89 }
|
idamnjanovic@60
|
90 msgdelta = mxGetScalar(IN_MSGDELTA);
|
idamnjanovic@60
|
91 if (mxGetScalar(IN_MAXATOMS) < -1e-5) {
|
idamnjanovic@60
|
92 maxatoms = -1;
|
idamnjanovic@60
|
93 }
|
idamnjanovic@60
|
94 else {
|
idamnjanovic@60
|
95 maxatoms = (int)(mxGetScalar(IN_MAXATOMS)+1e-2);
|
idamnjanovic@60
|
96 }
|
idamnjanovic@60
|
97 profile = (int)(mxGetScalar(IN_PROFILE)+1e-2);
|
idamnjanovic@60
|
98
|
idamnjanovic@60
|
99
|
idamnjanovic@60
|
100 /* check sizes */
|
idamnjanovic@60
|
101
|
idamnjanovic@60
|
102 if (D && x) {
|
idamnjanovic@60
|
103 n = mxGetM(IN_D);
|
idamnjanovic@60
|
104 m = mxGetN(IN_D);
|
idamnjanovic@60
|
105 L = mxGetN(IN_X);
|
idamnjanovic@60
|
106
|
idamnjanovic@60
|
107 if (mxGetM(IN_X) != n) {
|
idamnjanovic@60
|
108 mexErrMsgTxt("D and X have incompatible sizes.");
|
idamnjanovic@60
|
109 }
|
idamnjanovic@60
|
110
|
idamnjanovic@60
|
111 if (G) {
|
idamnjanovic@60
|
112 if (mxGetN(IN_G)!=mxGetM(IN_G)) {
|
idamnjanovic@60
|
113 mexErrMsgTxt("G must be a square matrix.");
|
idamnjanovic@60
|
114 }
|
idamnjanovic@60
|
115 if (mxGetN(IN_G) != m) {
|
idamnjanovic@60
|
116 mexErrMsgTxt("D and G have incompatible sizes.");
|
idamnjanovic@60
|
117 }
|
idamnjanovic@60
|
118 }
|
idamnjanovic@60
|
119 }
|
idamnjanovic@60
|
120
|
idamnjanovic@60
|
121 else if (DtX && XtX) {
|
idamnjanovic@60
|
122 m = mxGetM(IN_DtX);
|
idamnjanovic@60
|
123 L = mxGetN(IN_DtX);
|
idamnjanovic@60
|
124
|
idamnjanovic@60
|
125 /* set n to an arbitrary value that is at least the max possible number of selected atoms */
|
idamnjanovic@60
|
126
|
idamnjanovic@60
|
127 if (maxatoms>0) {
|
idamnjanovic@60
|
128 n = maxatoms;
|
idamnjanovic@60
|
129 }
|
idamnjanovic@60
|
130 else {
|
idamnjanovic@60
|
131 n = m;
|
idamnjanovic@60
|
132 }
|
idamnjanovic@60
|
133
|
idamnjanovic@60
|
134 if ( !(mxGetM(IN_XtX)==L && mxGetN(IN_XtX)==1) && !(mxGetM(IN_XtX)==1 && mxGetN(IN_XtX)==L) ) {
|
idamnjanovic@60
|
135 mexErrMsgTxt("DtX and XtX have incompatible sizes.");
|
idamnjanovic@60
|
136 }
|
idamnjanovic@60
|
137
|
idamnjanovic@60
|
138 if (mxGetN(IN_G)!=mxGetM(IN_G)) {
|
idamnjanovic@60
|
139 mexErrMsgTxt("G must be a square matrix.");
|
idamnjanovic@60
|
140 }
|
idamnjanovic@60
|
141 if (mxGetN(IN_G) != m) {
|
idamnjanovic@60
|
142 mexErrMsgTxt("DtX and G have incompatible sizes.");
|
idamnjanovic@60
|
143 }
|
idamnjanovic@60
|
144 }
|
idamnjanovic@60
|
145
|
idamnjanovic@60
|
146 else {
|
idamnjanovic@60
|
147 mexErrMsgTxt("Either D and X, or DtX and XtX, must be specified.");
|
idamnjanovic@60
|
148 }
|
idamnjanovic@60
|
149
|
idamnjanovic@60
|
150
|
idamnjanovic@60
|
151 /* Do OMP! */
|
idamnjanovic@60
|
152
|
idamnjanovic@60
|
153 GAMMA_OUT = ompcore(D, x, DtX, XtX, G, n, m, L, maxatoms, eps, gmode, profile, msgdelta, 1);
|
idamnjanovic@60
|
154
|
idamnjanovic@60
|
155 return;
|
idamnjanovic@60
|
156 }
|