15033154ff266f125a695ba3ffcb7b525ab306c2
5 // See comments in src/sources/EMGLLF.c and R/EMGLLF.R (wrapper)
19 // Get matrices dimensions
20 int n
= INTEGER(getAttrib(X_
, R_DimSymbol
))[0];
21 SEXP dim
= getAttrib(phiInit_
, R_DimSymbol
);
22 int p
= INTEGER(dim
)[0];
23 int m
= INTEGER(dim
)[1];
24 int k
= INTEGER(dim
)[2];
30 // get scalar parameters
31 int mini
= INTEGER_VALUE(mini_
);
32 int maxi
= INTEGER_VALUE(maxi_
);
33 double gamma
= NUMERIC_VALUE(gamma_
);
34 double lambda
= NUMERIC_VALUE(lambda_
);
35 double eps
= NUMERIC_VALUE(eps_
);
37 // Get pointers from SEXP arrays ; WARNING: by columns !
38 double* phiInit
= REAL(phiInit_
);
39 double* rhoInit
= REAL(rhoInit_
);
40 double* piInit
= REAL(piInit_
);
41 double* gamInit
= REAL(gamInit_
);
49 SEXP phi
, rho
, pi
, LLF
, S
, affec
, dimPhiS
, dimRho
;
50 PROTECT(dimPhiS
= allocVector(INTSXP
, 3));
51 int* pDimPhiS
= INTEGER(dimPhiS
);
52 pDimPhiS
[0] = p
; pDimPhiS
[1] = m
; pDimPhiS
[2] = k
;
53 PROTECT(dimRho
= allocVector(INTSXP
, 3));
54 int* pDimRho
= INTEGER(dimRho
);
55 pDimRho
[0] = m
; pDimRho
[1] = m
; pDimRho
[2] = k
;
56 PROTECT(phi
= allocArray(REALSXP
, dimPhiS
));
57 PROTECT(rho
= allocArray(REALSXP
, dimRho
));
58 PROTECT(pi
= allocVector(REALSXP
, k
));
59 PROTECT(LLF
= allocVector(REALSXP
, maxi
-mini
+1));
60 PROTECT(S
= allocArray(REALSXP
, dimPhiS
));
61 PROTECT(affec
= allocVector(INTSXP
, n
));
62 double *pPhi
=REAL(phi
), *pRho
=REAL(rho
), *pPi
=REAL(pi
), *pLLF
=REAL(LLF
), *pS
=REAL(S
);
63 int *pAffec
=INTEGER(affec
);
69 EMGLLF_core(phiInit
,rhoInit
,piInit
,gamInit
,mini
,maxi
,gamma
,lambda
,X
,Y
,eps
,
70 pPhi
,pRho
,pPi
,pLLF
,pS
,pAffec
,
73 // Build list from OUT params and return it
74 SEXP listParams
, listNames
;
76 PROTECT(listParams
= allocVector(VECSXP
, nouts
));
77 char* lnames
[6] = {"phi", "rho", "pi", "LLF", "S", "affec"}; //lists labels
78 PROTECT(listNames
= allocVector(STRSXP
,nouts
));
79 for (int i
=0; i
<nouts
; i
++)
80 SET_STRING_ELT(listNames
,i
,mkChar(lnames
[i
]));
81 setAttrib(listParams
, R_NamesSymbol
, listNames
);
82 SET_VECTOR_ELT(listParams
, 0, phi
);
83 SET_VECTOR_ELT(listParams
, 1, rho
);
84 SET_VECTOR_ELT(listParams
, 2, pi
);
85 SET_VECTOR_ELT(listParams
, 3, LLF
);
86 SET_VECTOR_ELT(listParams
, 4, S
);
87 SET_VECTOR_ELT(listParams
, 5, affec
);