747a3c99756c23026d1cbb0d238047e8d0f91f80
3 #include "sources/EMGLLF.h"
18 // Get matrices dimensions
19 int n
= INTEGER(getAttrib(X_
, R_DimSymbol
))[0];
20 SEXP dim
= getAttrib(phiInit_
, R_DimSymbol
)
21 int p
= INTEGER(dim
)[0];
22 int m
= INTEGER(dim
)[1];
23 int k
= INTEGER(dim
)[2];
29 // get scalar parameters
30 int mini
= INTEGER_VALUE(mini_
);
31 int maxi
= INTEGER_VALUE(maxi_
);
32 double gamma
= NUMERIC_VALUE(gamma_
);
33 double lambda
= NUMERIC_VALUE(lambda_
);
34 double tau
= NUMERIC_VALUE(tau_
);
36 // Get pointers from SEXP arrays ; WARNING: by columns !
37 double* phiInit
= REAL(phiInit_
);
38 double* rhoInit
= REAL(rhoInit_
);
39 double* piInit
= REAL(piInit_
);
40 double* gamInit
= REAL(gamInit_
);
48 SEXP phi
, rho
, pi
, LLF
, S
, dimPhiS
, dimRho
;
49 PROTECT(dimPhiS
= allocVector(INTSXP
, 3));
50 int* pDimPhiS
= INTEGER(dimPhiS
);
51 pDimPhiS
[0] = p
; pDimPhiS
[1] = m
; pDimPhiS
[2] = k
;
52 PROTECT(dimRho
= allocVector(INTSXP
, 3));
53 int* pDimRho
= INTEGER(dimRho
);
54 pDimRho
[0] = m
; pDimRho
[1] = m
; pDimRho
[2] = k
;
55 PROTECT(phi
= allocArray(REALSXP
, dimPhiS
));
56 PROTECT(rho
= allocArray(REALSXP
, dimRho
));
57 PROTECT(pi
= allocVector(REALSXP
, k
));
58 PROTECT(LLF
= allocVector(REALSXP
, maxi
-mini
+1));
59 PROTECT(S
= allocArray(REALSXP
, dimPhiS
));
60 double* pPhi
=REAL(phi
), pRho
=REAL(rho
), pPi
=REAL(pi
), pLLF
=REAL(LLF
), pS
=REAL(S
);
66 EMGLLF(phiInit
,rhoInit
,piInit
,gamInit
,mini
,maxi
,gamma
,lambda
,X
,Y
,tau
,
67 pPhi
,pRho
,pPi
,pLLF
,pS
,
70 // Build list from OUT params and return it
71 SEXP listParams
, listNames
;
72 PROTECT(listParams
= allocVector(VECSXP
, 5));
73 char* lnames
[5] = {"phi", "rho", "pi", "LLF", "S"}; //lists labels
74 PROTECT(listNames
= allocVector(STRSXP
,5));
75 for (int i
=0; i
<5; i
++)
76 SET_STRING_ELT(listNames
,i
,mkChar(lnames
[i
]));
77 setAttrib(listParams
, R_NamesSymbol
, listNames
);
78 SET_ARRAY_ELT(listParams
, 0, phi
);
79 SET_ARRAY_ELT(listParams
, 1, rho
);
80 SET_MATRIX_ELT(listParams
, 2, pi
);
81 SET_VECTOR_ELT(listParams
, 3, LLF
);
82 SET_ARRAY_ELT(listParams
, 4, S
);