void AlgebraFitFunction::init() { auto *off = this; omxState *currentState = off->matrix->currentState; AlgebraFitFunction *aff = this; aff->ff = off; ProtectedSEXP Ralg(R_do_slot(rObj, Rf_install("algebra"))); aff->algebra = omxMatrixLookupFromState1(Ralg, currentState); ProtectedSEXP Runit(R_do_slot(rObj, Rf_install("units"))); off->setUnitsFromName(CHAR(STRING_ELT(Runit, 0))); ProtectedSEXP Rgr(R_do_slot(rObj, Rf_install("gradient"))); aff->gradient = omxMatrixLookupFromState1(Rgr, currentState); if (aff->gradient) off->gradientAvailable = TRUE; ProtectedSEXP Rh(R_do_slot(rObj, Rf_install("hessian"))); aff->hessian = omxMatrixLookupFromState1(Rh, currentState); if (aff->hessian) off->hessianAvailable = TRUE; ProtectedSEXP Rverb(R_do_slot(rObj, Rf_install("verbose"))); aff->verbose = Rf_asInteger(Rverb); off->canDuplicate = true; }
void FitMultigroup::init() { auto *oo = this; FitMultigroup *mg =this; SEXP rObj = oo->rObj; if (!rObj) return; if (mg->fits.size()) return; // hack to prevent double initialization, remove TOOD oo->units = FIT_UNITS_UNINITIALIZED; oo->gradientAvailable = TRUE; oo->hessianAvailable = TRUE; oo->canDuplicate = true; omxState *os = oo->matrix->currentState; ProtectedSEXP Rverb(R_do_slot(rObj, Rf_install("verbose"))); mg->verbose = Rf_asInteger(Rverb); ProtectedSEXP Rgroups(R_do_slot(rObj, Rf_install("groups"))); int *fits = INTEGER(Rgroups); for(int gx = 0; gx < Rf_length(Rgroups); gx++) { if (isErrorRaised()) break; omxMatrix *mat; if (fits[gx] >= 0) { mat = os->algebraList[fits[gx]]; } else { mxThrow("Can only add algebra and fitfunction"); } if (mat == oo->matrix) mxThrow("Cannot add multigroup to itself"); mg->fits.push_back(mat); if (mat->fitFunction) { omxCompleteFitFunction(mat); oo->gradientAvailable = (oo->gradientAvailable && mat->fitFunction->gradientAvailable); oo->hessianAvailable = (oo->hessianAvailable && mat->fitFunction->hessianAvailable); } else { oo->gradientAvailable = FALSE; oo->hessianAvailable = FALSE; } } }