-#include "ioutils.h"
-#include "selectiontotale.h"
-#include "EMGLLF.h"
-#include <mex.h>
-
-// nlhs, nrhs: resp. numbers of out and in parameters.
-// plhs: array of out parameters, each being a mxArray
-// plhs: array of in parameters (immutable), each being a mxArray
-//
-// MATLAB translates a call [A,B] = fun(C,D) into mexFunction(2,{A,B},2,{C,D}).
-// Then mxArrayS are adapted to be passed to a regular C function,
-// and the results are translated back to mxArrayS into plhs.
-void mexFunction(int nlhs, mxArray* plhs[],
- int nrhs, const mxArray* prhs[])
-{
- // Basic sanity checks
- if (nrhs!=12)
- mexErrMsgIdAndTxt("select:selectiontotale:nrhs","12 inputs required.");
- if (nlhs!=4)
- mexErrMsgIdAndTxt("select:selectiontotale:nlhs","4 outputs required.");
-
- // Get matrices dimensions, to be given to main routine above
- const mwSize n = mxGetDimensions(prhs[8])[0];
- const mwSize p = mxGetDimensions(prhs[8])[1];
- const mwSize m = mxGetDimensions(prhs[1])[0];
- const mwSize k = mxGetDimensions(prhs[1])[2];
- const mwSize L = mxGetNumberOfElements(prhs[7]);
+#include <R.h>
+#include <Rdefines.h>
+#include "sources/EMGLLF.h"
+
+SEXP EMGLLF(
+ SEXP phiInit_,
+ SEXP rhoInit_,
+ SEXP piInit_,
+ SEXP gamInit_,
+ SEXP mini_,
+ SEXP maxi_,
+ SEXP gamma_,
+ SEXP glambda_,
+ SEXP X_,
+ SEXP Y_,
+ SEXP seuil_,
+ SEXP tau_
+) {
+ // Get matrices dimensions
+ SEXP dimX = getAttrib(X_, R_DimSymbol);
+ int n = INTEGER(dimX)[0];
+ int p = INTEGER(dimX)[1];
+ SEXP dimRho = getAttrib(rhoInit_, R_DimSymbol)
+ int m = INTEGER(dimRho)[0];
+ int k = INTEGER(dimRho)[2];
+ int L = INTEGER(getAttrib(glambda_, R_LengthSymbol))[0];