38 if (!utl::mexCheckType<T>(prhs[0]))
39 mexErrMsgTxt(
"type of argument 1 is not consistent");
40 if (mxIsSparse(prhs[0]))
41 mexErrMsgTxt(
"argument 1 should be full");
42 if (!utl::mexCheckType<T>(prhs[1]))
43 mexErrMsgTxt(
"type of argument 2 is not consistent");
44 if (mxIsSparse(prhs[1]))
45 mexErrMsgTxt(
"argument 2 should be full");
46 if (mxIsSparse(prhs[2]))
47 mexErrMsgTxt(
"argument 3 should be full");
48 if (!mxIsStruct(prhs[3]))
49 mexErrMsgTxt(
"argument 4 should be struct");
52 T* prX =
reinterpret_cast<T*
>(mxGetPr(prhs[0]));
53 const mwSize* dimsX=mxGetDimensions(prhs[0]);
54 int n=
static_cast<int>(dimsX[0]);
55 int M=
static_cast<int>(dimsX[1]);
57 T* prD =
reinterpret_cast<T*
>(mxGetPr(prhs[1]));
58 const mwSize* dimsD=mxGetDimensions(prhs[1]);
59 int nD=
static_cast<int>(dimsD[0]);
60 int K=
static_cast<int>(dimsD[1]);
61 if (n != nD) mexErrMsgTxt(
"argument sizes are not consistent");
63 T lambda = utl::GetScalarStruct<T>(prhs[3],
"lambda");
64 int L = utl::GetScalarStructDef<int>(prhs[3],
"L",K);
65 int numThreads = utl::GetScalarStructDef<int>(prhs[3],
"numThreads",-1);
66 bool pos = utl::GetScalarStructDef<bool>(prhs[3],
"pos",
false);
69 printf(
"L is changed to %d\n",n);
73 printf(
"L is changed to %d\n",K);
80 T* prWeight =
reinterpret_cast<T*
>(mxGetPr(prhs[2]));
81 const mwSize* dimsW=mxGetDimensions(prhs[2]);
82 int KK=
static_cast<int>(dimsW[0]);
83 int MM=
static_cast<int>(dimsW[1]);
84 if (K != KK || M != MM) mexErrMsgTxt(
"argument sizes are not consistent");
90 spams::lassoWeight<T>(X,D,weight,alpha,L,lambda,mode,pos,numThreads);
92 alpha.nzmax(),alpha.v(),alpha.r(),alpha.pB());
95 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[]) {
97 mexErrMsgTxt(
"Bad number of inputs arguments");
99 if (!(nlhs == 1 || nlhs == 1))
100 mexErrMsgTxt(
"Bad number of output arguments");
102 if (mxGetClassID(prhs[0]) == mxDOUBLE_CLASS) {
103 callFunction<double>(plhs,prhs);
105 callFunction<float>(plhs,prhs);
void callFunction(mxArray *plhs[], const mxArray *prhs[])
void ConvertSpMatrix(mxArray *&matlab_mat, int K, int M, int n, int nzmax, const T *v, const int *r, const int *pB)
convert sparse matrix to Matlab sparse matrix
Contains miscellaneous functions for mex files. utl functions for mex code. Some codes are from spams...
Contains sparse decomposition algorithms It requires the toolbox linalg.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])