omxExpectation * omxNewInternalExpectation(const char *expType, omxState* os) { omxExpectation* expect = Calloc(1, omxExpectation); expect->setVarGroup = defaultSetVarGroup; /* Switch based on Expectation type. */ for (size_t ex=0; ex < OMX_STATIC_ARRAY_SIZE(omxExpectationSymbolTable); ex++) { const omxExpectationTableEntry *entry = omxExpectationSymbolTable + ex; if(strEQ(expType, entry->name)) { expect->expType = entry->name; expect->initFun = entry->initFun; break; } } if(!expect->initFun) { Free(expect); Rf_error("Expectation %s not implemented", expType); } expect->currentState = os; expect->canDuplicate = true; expect->dynamicDataSource = false; return expect; }
static omxFitFunction *omxNewInternalFitFunction(omxState* os, const char *fitType, omxExpectation *expect, omxMatrix *matrix, bool rowLik) { omxFitFunction *obj = (omxFitFunction*) R_alloc(1, sizeof(omxFitFunction)); OMXZERO(obj, 1); for (size_t fx=0; fx < OMX_STATIC_ARRAY_SIZE(omxFitFunctionSymbolTable); fx++) { const omxFitFunctionTableEntry *entry = omxFitFunctionSymbolTable + fx; if(strcmp(fitType, entry->name) == 0) { obj->fitType = entry->name; obj->initFun = entry->initFun; // We need to set up the FreeVarGroup before calling initFun // because older fit functions expect to know the number of // free variables during initFun. obj->setVarGroup = entry->setVarGroup; // ugh! obj->addOutput = defaultAddOutput; break; } } if(obj->initFun == NULL) Rf_error("Fit function '%s' not implemented", fitType); if (!matrix) { obj->matrix = omxInitMatrix(1, 1, TRUE, os); obj->matrix->hasMatrixNumber = TRUE; obj->matrix->matrixNumber = ~os->algebraList.size(); os->algebraList.push_back(obj->matrix); } else { obj->matrix = matrix; } obj->matrix->fitFunction = obj; obj->expectation = expect; if (rowLik && expect && expect->data) { omxData *dat = expect->data; omxResizeMatrix(matrix, dat->rows, 1); } else { omxResizeMatrix(matrix, 1, 1); } return obj; }
void omxChangeFitType(omxFitFunction *oo, const char *fitType) { if (oo->initialized) { Rf_error("%s: cannot omxChangeFitType from %s to %s; already initialized", oo->matrix->name(), oo->fitType, fitType); } for (size_t fx=0; fx < OMX_STATIC_ARRAY_SIZE(omxFitFunctionSymbolTable); fx++) { const omxFitFunctionTableEntry *entry = omxFitFunctionSymbolTable + fx; if (strEQ(fitType, entry->name)) { oo->fitType = entry->name; oo->initFun = entry->initFun; return; } } Rf_error("Cannot find fit type '%s'", fitType); }
omxExpectation * omxNewInternalExpectation(const char *expType, omxState* os) { omxExpectation* expect = 0; /* Switch based on Expectation type. */ for (size_t ex=0; ex < OMX_STATIC_ARRAY_SIZE(omxExpectationSymbolTable); ex++) { const omxExpectationTableEntry *entry = omxExpectationSymbolTable + ex; if(strEQ(expType, entry->name)) { expect = entry->initFun(); expect->expType = entry->name; break; } } if (!expect) Rf_error("expectation '%s' not recognized", expType); expect->currentState = os; expect->canDuplicate = true; expect->dynamicDataSource = false; return expect; }