2 #include "selectiontotale.h"
6 // nlhs, nrhs: resp. numbers of out and in parameters.
7 // plhs: array of out parameters, each being a mxArray
8 // plhs: array of in parameters (immutable), each being a mxArray
10 // MATLAB translates a call [A,B] = fun(C,D) into mexFunction(2,{A,B},2,{C,D}).
11 // Then mxArrayS are adapted to be passed to a regular C function,
12 // and the results are translated back to mxArrayS into plhs.
13 void mexFunction(int nlhs
, mxArray
* plhs
[],
14 int nrhs
, const mxArray
* prhs
[])
16 // Basic sanity checks
18 mexErrMsgIdAndTxt("select:selectiontotale:nrhs","12 inputs required.");
20 mexErrMsgIdAndTxt("select:selectiontotale:nlhs","4 outputs required.");
22 // Get matrices dimensions, to be given to main routine above
23 const mwSize n
= mxGetDimensions(prhs
[8])[0];
24 const mwSize p
= mxGetDimensions(prhs
[8])[1];
25 const mwSize m
= mxGetDimensions(prhs
[1])[0];
26 const mwSize k
= mxGetDimensions(prhs
[1])[2];
27 const mwSize L
= mxGetNumberOfElements(prhs
[7]);
34 const mwSize
* dimPhiInit
= mxGetDimensions(prhs
[0]);
35 Real
* brPhiInit
= matlabToBrArray_real(mxGetPr(prhs
[0]), dimPhiInit
, 3);
38 const mwSize
* dimRhoInit
= mxGetDimensions(prhs
[1]);
39 Real
* brRhoInit
= matlabToBrArray_real(mxGetPr(prhs
[1]), dimRhoInit
, 3);
42 Real
* piInit
= mxGetPr(prhs
[2]);
45 const mwSize
* dimGamInit
= mxGetDimensions(prhs
[3]);
46 Real
* brGamInit
= matlabToBrArray_real(mxGetPr(prhs
[3]), dimGamInit
, 2);
48 // min number of iterations
49 Int mini
= ((Int
*)mxGetData(prhs
[4]))[0];
51 // max number of iterations
52 Int maxi
= ((Int
*)mxGetData(prhs
[5]))[0];
55 Real gamma
= mxGetScalar(prhs
[6]);
58 Real
* glambda
= mxGetPr(prhs
[7]);
61 const mwSize
* dimX
= mxGetDimensions(prhs
[8]);
62 Real
* brX
= matlabToBrArray_real(mxGetPr(prhs
[8]), dimX
, 2);
65 const mwSize
* dimY
= mxGetDimensions(prhs
[9]);
66 Real
* brY
= matlabToBrArray_real(mxGetPr(prhs
[9]), dimY
, 2);
69 Real seuil
= mxGetScalar(prhs
[10]);
72 Real tau
= mxGetScalar(prhs
[11]);
79 mwSize dimA
[] = {p
,m
+1,L
};
80 plhs
[0] = mxCreateNumericArray(3,dimA
,mxGetClassID(prhs
[4]),mxREAL
);
81 Int
* A1
= (Int
*)mxGetData(plhs
[0]);
84 plhs
[1] = mxCreateNumericArray(3,dimA
,mxGetClassID(prhs
[4]),mxREAL
);
85 Int
* A2
= (Int
*)mxGetData(plhs
[1]);
88 const mwSize dimRho
[] = {dimRhoInit
[0], dimRhoInit
[1], dimRhoInit
[2], L
};
89 plhs
[2] = mxCreateNumericArray(4,dimRho
,mxDOUBLE_CLASS
,mxREAL
);
90 Real
* Rho
= mxGetPr(plhs
[2]);
93 const mwSize dimPi
[] = {k
, L
};
94 plhs
[3] = mxCreateNumericMatrix(dimPi
[0],dimPi
[1],mxDOUBLE_CLASS
,mxREAL
);
95 double* Pi
= mxGetPr(plhs
[3]);
97 /////////////////////////////
98 // Call to selectiontotale //
99 /////////////////////////////
101 selectiontotale(brPhiInit
,brRhoInit
,piInit
,brGamInit
,mini
,maxi
,gamma
,glambda
,brX
,brY
,seuil
,tau
,
111 //post-processing: convert by-rows outputs to MATLAB matrices
112 Int
* mlA1
= brToMatlabArray_int(A1
,dimA
,3);
113 copyArray(mlA1
,A1
,dimA
[0]*dimA
[1]*dimA
[2]);
116 Int
* mlA2
= brToMatlabArray_int(A2
,dimA
,3);
117 copyArray(mlA2
,A2
,dimA
[0]*dimA
[1]*dimA
[2]);
120 Real
* mlRho
= brToMatlabArray_real(Rho
, dimRho
, 4);
121 copyArray(mlRho
, Rho
, dimRho
[0]*dimRho
[1]*dimRho
[2]*dimRho
[3]);
124 Real
* mlPi
= brToMatlabArray_real(Pi
, dimPi
, 2);
125 copyArray(mlPi
, Pi
, dimPi
[0]*dimPi
[1]);