5 // nlhs, nrhs: resp. numbers of out and in parameters.
6 // plhs: array of out parameters, each being a mxArray
7 // plhs: array of in parameters (immutable), each being a mxArray
9 // MATLAB translates a call [A,B] = fun(C,D) into mexFunction(2,{A,B},2,{C,D}).
10 // Then mxArrayS are adapted to be passed to a regular C function,
11 // and the results are translated back to mxArrayS into plhs.
16 const mxArray
* prhs
[])
18 // Basic sanity checks
20 mexErrMsgIdAndTxt("select:EMGLLF:nrhs","11 inputs required.");
22 mexErrMsgIdAndTxt("select:EMGLLF:nlhs","5 outputs required.");
24 // Get matrices dimensions
25 const mwSize n
= mxGetDimensions(prhs
[8])[0];
26 const mwSize p
= mxGetDimensions(prhs
[0])[0];
27 const mwSize m
= mxGetDimensions(prhs
[0])[1];
28 const mwSize k
= mxGetDimensions(prhs
[0])[2];
35 const mwSize
* dimPhiInit
= mxGetDimensions(prhs
[0]);
36 Real
* brPhiInit
= matlabToBrArray_real(mxGetPr(prhs
[0]), dimPhiInit
, 3);
39 const mwSize
* dimRhoInit
= mxGetDimensions(prhs
[1]);
40 Real
* brRhoInit
= matlabToBrArray_real(mxGetPr(prhs
[1]), dimRhoInit
, 3);
43 Real
* piInit
= mxGetPr(prhs
[2]);
46 const mwSize
* dimGamInit
= mxGetDimensions(prhs
[3]);
47 Real
* brGamInit
= matlabToBrArray_real(mxGetPr(prhs
[3]), dimGamInit
, 2);
49 // min number of iterations
50 Int mini
= ((Int
*)mxGetData(prhs
[4]))[0];
52 // max number of iterations
53 Int maxi
= ((Int
*)mxGetData(prhs
[5]))[0];
56 Real gamma
= mxGetScalar(prhs
[6]);
59 Real lambda
= mxGetScalar(prhs
[7]);
62 const mwSize
* dimX
= mxGetDimensions(prhs
[8]);
63 Real
* brX
= matlabToBrArray_real(mxGetPr(prhs
[8]), dimX
, 2);
66 const mwSize
* dimY
= mxGetDimensions(prhs
[9]);
67 Real
* brY
= matlabToBrArray_real(mxGetPr(prhs
[9]), dimY
, 2);
70 Real tau
= mxGetScalar(prhs
[10]);
77 const mwSize dimPhi
[] = {dimPhiInit
[0], dimPhiInit
[1], dimPhiInit
[2]};
78 plhs
[0] = mxCreateNumericArray(3,dimPhi
,mxDOUBLE_CLASS
,mxREAL
);
79 Real
* phi
= mxGetPr(plhs
[0]);
82 const mwSize dimRho
[] = {dimRhoInit
[0], dimRhoInit
[1], dimRhoInit
[2]};
83 plhs
[1] = mxCreateNumericArray(3,dimRho
,mxDOUBLE_CLASS
,mxREAL
);
84 Real
* rho
= mxGetPr(plhs
[1]);
87 plhs
[2] = mxCreateNumericMatrix(k
,1,mxDOUBLE_CLASS
,mxREAL
);
88 Real
* pi
= mxGetPr(plhs
[2]);
91 plhs
[3] = mxCreateNumericMatrix(maxi
,1,mxDOUBLE_CLASS
,mxREAL
);
92 Real
* LLF
= mxGetPr(plhs
[3]);
95 const mwSize dimS
[] = {p
, m
, k
};
96 plhs
[4] = mxCreateNumericArray(3,dimS
,mxDOUBLE_CLASS
,mxREAL
);
97 Real
* S
= mxGetPr(plhs
[4]);
103 EMGLLF(brPhiInit
,brRhoInit
,piInit
,brGamInit
,mini
,maxi
,gamma
,lambda
,brX
,brY
,tau
,
113 //post-processing: convert by-rows outputs to MATLAB matrices
114 Real
* mlPhi
= brToMatlabArray_real(phi
, dimPhi
, 3);
115 copyArray(mlPhi
, phi
, dimPhi
[0]*dimPhi
[1]*dimPhi
[2]);
118 Real
* mlRho
= brToMatlabArray_real(rho
, dimRho
, 3);
119 copyArray(mlRho
, rho
, dimRho
[0]*dimRho
[1]*dimRho
[2]);
122 Real
* mlS
= brToMatlabArray_real(S
, dimS
, 3);
123 copyArray(mlS
, S
, dimS
[0]*dimS
[1]*dimS
[2]);