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:EMGrank:nrhs","8 inputs required.");
22 mexErrMsgIdAndTxt("select:EMGrank:nlhs","3 outputs required.");
24 // Get matrices dimensions
25 const mwSize n
= mxGetDimensions(prhs
[4])[0];
26 const mwSize p
= mxGetDimensions(prhs
[4])[1];
27 const mwSize m
= mxGetDimensions(prhs
[1])[0];
28 const mwSize k
= mxGetDimensions(prhs
[1])[2];
35 Real
* Pi
= mxGetPr(prhs
[0]);
38 const mwSize
* dimRho
= mxGetDimensions(prhs
[1]);
39 Real
* brRho
= matlabToBrArray_real(mxGetPr(prhs
[1]), dimRho
, 3);
41 // min number of iterations
42 Int mini
= ((Int
*)mxGetData(prhs
[2]))[0];
44 // max number of iterations
45 Int maxi
= ((Int
*)mxGetData(prhs
[3]))[0];
48 const mwSize
* dimX
= mxGetDimensions(prhs
[4]);
49 Real
* brX
= matlabToBrArray_real(mxGetPr(prhs
[4]), dimX
, 2);
52 const mwSize
* dimY
= mxGetDimensions(prhs
[5]);
53 Real
* brY
= matlabToBrArray_real(mxGetPr(prhs
[5]), dimY
, 2);
56 Real tau
= mxGetScalar(prhs
[6]);
59 Int
* rank
= (Int
*)mxGetData(prhs
[7]);
66 const mwSize dimPhi
[] = {p
, m
, k
};
67 plhs
[0] = mxCreateNumericArray(3,dimPhi
,mxDOUBLE_CLASS
,mxREAL
);
68 Real
* phi
= mxGetPr(plhs
[0]);
71 plhs
[1] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS
,mxREAL
);
72 Real
* LLF
= mxGetPr(plhs
[1]);
78 EMGrank(Pi
,brRho
,mini
,maxi
,brX
,brY
,tau
,rank
,
86 //post-processing: convert by-rows outputs to MATLAB matrices
87 Real
* mlPhi
= brToMatlabArray_real(phi
, dimPhi
, 3);
88 copyArray(mlPhi
, phi
, dimPhi
[0]*dimPhi
[1]*dimPhi
[2]);