96908c29dd0a07136e5d8731d63b0c2748ec5e7e
2 #include "constructionModelesLassoRank.h"
7 // nlhs, nrhs: resp. numbers of out and in parameters.
8 // plhs: array of out parameters, each being a mxArray
9 // plhs: array of in parameters (immutable), each being a mxArray
11 // MATLAB translates a call [A,B] = fun(C,D) into mexFunction(2,{A,B},2,{C,D}).
12 // Then mxArrayS are adapted to be passed to a regular C function,
13 // and the results are translated back to mxArrayS into plhs.
14 void mexFunction(int nlhs
, mxArray
* plhs
[],
15 int nrhs
, const mxArray
* prhs
[])
17 // Basic sanity checks
19 mexErrMsgIdAndTxt("select:constructionModelesLassoRank:nrhs","10 inputs required.");
21 mexErrMsgIdAndTxt("select:constructionModelesLassoRank:nlhs","3 outputs required.");
23 // Get matrices dimensions, to be given to main routine above
24 const mwSize n
= mxGetDimensions(prhs
[4])[0];
25 const mwSize p
= mxGetDimensions(prhs
[4])[1];
26 const mwSize m
= mxGetDimensions(prhs
[1])[0];
27 const mwSize k
= mxGetDimensions(prhs
[1])[2];
28 const mwSize L
= mxGetDimensions(prhs
[7])[1];
35 const mwSize
* dimPi
= mxGetDimensions(prhs
[0]);
36 Real
* brPi
= matlabToBrArray_real(mxGetPr(prhs
[0]), dimPi
, 2);
39 const mwSize
* dimRho
= mxGetDimensions(prhs
[1]);
40 Real
* brRho
= matlabToBrArray_real(mxGetPr(prhs
[1]), dimRho
, 4);
42 // min number of iterations
43 Int mini
= ((Int
*)mxGetData(prhs
[2]))[0];
45 // max number of iterations
46 Int maxi
= ((Int
*)mxGetData(prhs
[3]))[0];
49 const mwSize
* dimX
= mxGetDimensions(prhs
[4]);
50 Real
* brX
= matlabToBrArray_real(mxGetPr(prhs
[4]), dimX
, 2);
53 const mwSize
* dimY
= mxGetDimensions(prhs
[5]);
54 Real
* brY
= matlabToBrArray_real(mxGetPr(prhs
[5]), dimY
, 2);
57 Real tau
= mxGetScalar(prhs
[6]);
60 const mwSize
* dimA
= mxGetDimensions(prhs
[7]);
61 Int
* brA1
= matlabToBrArray_int(mxGetData(prhs
[7]), dimA
, 2);
64 Int rangmin
= ((Int
*)mxGetData(prhs
[8]))[0];
67 Int rangmax
= ((Int
*)mxGetData(prhs
[9]))[0];
74 mwSize Size
= pow(rangmax
-rangmin
+1,k
);
75 const mwSize dimPhi
[] = {p
, m
, k
, L
*Size
};
76 plhs
[0] = mxCreateNumericArray(4,dimPhi
,mxDOUBLE_CLASS
,mxREAL
);
77 Real
* phi
= mxGetPr(plhs
[0]);
80 const mwSize dimLvraisemblance
[] = {L
*Size
, 2};
81 plhs
[1] = mxCreateNumericMatrix(dimLvraisemblance
[0],dimLvraisemblance
[1],mxDOUBLE_CLASS
,mxREAL
);
82 Real
* lvraisemblance
= mxGetPr(plhs
[1]);
85 //////////////////////////////////////////
86 // Call to constructionModelesLassoRank //
87 //////////////////////////////////////////
89 constructionModelesLassoRank(
90 brPi
,brRho
,mini
,maxi
,brX
,brY
,tau
,brA1
,rangmin
,rangmax
,
100 //post-processing: convert by-rows outputs to MATLAB matrices
101 Real
* mlPhi
= brToMatlabArray_real(phi
, dimPhi
, 4);
102 copyArray(mlPhi
, phi
, dimPhi
[0]*dimPhi
[1]*dimPhi
[2]*dimPhi
[3]);
105 Real
* mlLvraisemblance
= brToMatlabArray_real(lvraisemblance
, dimLvraisemblance
, 2);
106 copyArray(mlLvraisemblance
, lvraisemblance
, dimLvraisemblance
[0]*dimLvraisemblance
[1]);
107 free(mlLvraisemblance
);