annotate solvers/SMALL_ompGabor/omp2mex.c @ 234:c96880c0c47c

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