annotate util/ksvd utils/ompbox utils/omp2mex.c @ 137:9207d56c5547 ivand_dev

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