BreakIterator* BreakIterator::createInstance(const Locale& loc, int32_t kind, UErrorCode& status) { if (U_FAILURE(status)) { return NULL; } #if !UCONFIG_NO_SERVICE if (hasService()) { Locale actualLoc(""); BreakIterator *result = (BreakIterator*)gService->get(loc, kind, &actualLoc, status); // TODO: The way the service code works in ICU 2.8 is that if // there is a real registered break iterator, the actualLoc // will be populated, but if the handleDefault path is taken // (because nothing is registered that can handle the // requested locale) then the actualLoc comes back empty. In // that case, the returned object already has its actual/valid // locale data populated (by makeInstance, which is what // handleDefault calls), so we don't touch it. YES, A COMMENT // THIS LONG is a sign of bad code -- so the action item is to // revisit this in ICU 3.0 and clean it up/fix it/remove it. if (U_SUCCESS(status) && (result != NULL) && *actualLoc.getName() != 0) { U_LOCALE_BASED(locBased, *result); locBased.setLocaleIDs(actualLoc.getName(), actualLoc.getName()); } return result; } else #endif { return makeInstance(loc, kind, status); } }
CMPIStatus CWS_DirectoryGetInstance( CMPIInstanceMI * mi, const CMPIContext * ctx, const CMPIResult * rslt, const CMPIObjectPath * cop, const char ** properties) { CMPIInstance *in = NULL; CMPIStatus st = {CMPI_RC_OK,NULL}; CMPIData nd = CMGetKey(cop,"Name",&st); CWS_FILE filebuf; if (!silentMode()) fprintf(stderr,"--- CWS_DirectoryGetInstance() \n"); if (st.rc == CMPI_RC_OK && nd.type == CMPI_string && CWS_Get_File(CMGetCharsPtr(nd.value.string, NULL),&filebuf)) in = makeInstance(_broker, LOCALCLASSNAME, CMGetCharsPtr(CMGetNameSpace(cop,NULL), NULL), &filebuf); if (CMIsNullObject(in)) { CMSetStatusWithChars(_broker, &st, CMPI_RC_ERR_FAILED, "Could not find or construct instance"); } else { CMReturnInstance(rslt,in); CMReturnDone(rslt); } return st; }
Collator* U_EXPORT2 Collator::createInstance(const Locale& desiredLocale, UErrorCode& status) { if (U_FAILURE(status)) return 0; #if !UCONFIG_NO_SERVICE if (hasService()) { Locale actualLoc; Collator *result = (Collator*)gService->get(desiredLocale, &actualLoc, status); // Ugly Hack Alert! If the returned locale is empty (not root, // but empty -- getName() == "") then that means the service // returned a default object, not a "real" service object. In // that case, the locale metadata (valid & actual) is setup // correctly already, and we don't want to overwrite it. (TODO // remove in 3.0) [aliu] if (*actualLoc.getName() != 0) { result->setLocales(desiredLocale, actualLoc, actualLoc); } return result; } #endif return makeInstance(desiredLocale, status); }
Collator* U_EXPORT2 Collator::createInstance(const Locale& desiredLocale, UErrorCode& status) { if (U_FAILURE(status)) return 0; if (desiredLocale.isBogus()) { // Locale constructed from malformed locale ID or language tag. status = U_ILLEGAL_ARGUMENT_ERROR; return NULL; } Collator* coll; #if !UCONFIG_NO_SERVICE if (hasService()) { Locale actualLoc; coll = (Collator*)gService->get(desiredLocale, &actualLoc, status); } else #endif { coll = makeInstance(desiredLocale, status); } setAttributesFromKeywords(desiredLocale, *coll, status); if (U_FAILURE(status)) { delete coll; return NULL; } return coll; }
Collator* U_EXPORT2 Collator::createInstance(const Locale& desiredLocale, UErrorCode& status) { if (U_FAILURE(status)) return 0; if (desiredLocale.isBogus()) { // Locale constructed from malformed locale ID or language tag. status = U_ILLEGAL_ARGUMENT_ERROR; return NULL; } Collator* coll; #if !UCONFIG_NO_SERVICE if (hasService()) { Locale actualLoc; coll = (Collator*)gService->get(desiredLocale, &actualLoc, status); } else #endif { coll = makeInstance(desiredLocale, status); // Either returns NULL with U_FAILURE(status), or non-NULL with U_SUCCESS(status) } // The use of *coll in setAttributesFromKeywords can cause the NULL check to be // optimized out of the delete even though setAttributesFromKeywords returns // immediately if U_FAILURE(status), so we add a check here. if (U_FAILURE(status)) { return NULL; } setAttributesFromKeywords(desiredLocale, *coll, status); if (U_FAILURE(status)) { delete coll; return NULL; } return coll; }
AbstractPluginPtr Registry::makeNamedInstance(const std::string& pluginTypeID, const std::string& instanceName, std::vector<AbstractPluginPtr>& deps) { AbstractPluginPtr plugin = makeInstance(pluginTypeID, deps); mNamedInstances[instanceName] = plugin; return plugin; }
NumberFormat* U_EXPORT2 NumberFormat::createInstance(const Locale& loc, UNumberFormatStyle kind, UErrorCode& status) { #if !UCONFIG_NO_SERVICE if (haveService()) { return (NumberFormat*)gService->get(loc, kind, status); } #endif return makeInstance(loc, kind, status); }
NumberFormat* NumberFormat::createInstance(const Locale& loc, EStyles kind, UErrorCode& status) { umtx_lock(NULL); UBool haveService = gService != NULL; umtx_unlock(NULL); if (haveService) { return (NumberFormat*)gService->get(loc, kind, status); } else { return makeInstance(loc, kind, status); } }
NumberFormat* U_EXPORT2 NumberFormat::createInstance(const Locale& loc, EStyles kind, UErrorCode& status) { #if !UCONFIG_NO_SERVICE UBool haveService; UMTX_CHECK(NULL, gService != NULL, haveService); if (haveService) { return (NumberFormat*)gService->get(loc, kind, status); } else #endif { return makeInstance(loc, kind, status); } }
CMPIStatus CWS_DirectoryEnumInstances( CMPIInstanceMI * mi, const CMPIContext * ctx, const CMPIResult * rslt, const CMPIObjectPath * ref, const char ** properties) { CMPIInstance *in; CMPIStatus st = {CMPI_RC_OK,NULL}; void *enumhdl; CWS_FILE filebuf; if (!silentMode()) fprintf(stderr,"--- CWS_DirectoryEnumInstances() \n"); enumhdl = CWS_Begin_Enum(CWS_FILEROOT,CWS_TYPE_DIR); if (enumhdl == NULL) { CMSetStatusWithChars(_broker, &st, CMPI_RC_ERR_FAILED, "Could not begin file enumeration"); return st; } else { while (CWS_Next_Enum(enumhdl,&filebuf)) { /* build instance from file buffer */ in = makeInstance(_broker, LOCALCLASSNAME, CMGetCharsPtr(CMGetNameSpace(ref,NULL), NULL), &filebuf); if (CMIsNullObject(in)) { CMSetStatusWithChars(_broker, &st, CMPI_RC_ERR_FAILED, "Could not construct instance"); break; } CMReturnInstance(rslt,in); } CMReturnDone(rslt); CWS_End_Enum(enumhdl); } return st; }
BatchWraper* TrainingInstances::getBatch(int width, int color, string prevNgram, int trainingNum) { #ifndef TEST_MODE try { #endif BatchWraper* ret= makeInstance(trainingNum,width,color); if (ret!=NULL) return ret; else return new BatchWraperBlank(); #ifndef TEST_MODE } catch (exception& e) { cout <<"Exception in TrainingInstances::getBatch(), "<<e.what()<<endl; } catch (...) { cout <<"Exception in TrainingInstances::getBatch(), UNKNOWN"<<endl; } #endif return new BatchWraperBlank(); }
void gaus(float ** A,float* B,float* X,int size) { // Forward move // Choose special item ( diagonal item -x) // x 0 0 0 // 0 x 0 0 // 0 0 x 0 // 0 0 0 x int i=0,j=0,k=0; float specialItem=0; float koeff=0; for( j = 0; j < size; j++ ) { specialItem=A[j][j]; //making specialItem equal to 1 makeInstance(A,B,j,size); // Going downwards from specialItem for( i=j+1;i<size;i++) { koeff=A[i][j]; // Substracting all items in the row for( k=0;k<size;k++) { A[i][k]=A[i][k]-(koeff*A[j][k]); } B[i]-=koeff*B[j]; } } //Backward move //1 0 0 0 | b1 //0 1 0 0 | b2 //0 0 1 0 | b3 //0 0 0 1 | b4 for( i=size-1;i>0; --i) { for( j=0;j<i;++j) { B[j]-=A[j][i]*B[i]; A[j][i]=0; } } for( i=0;i<size;++i) { X[i]=B[i]; } /* X[size-1]=B[size-1]; float tmp=0; for(int i=size-2;i>=0;i--) { for(int j=size-1;j>i;j--) { tmp=tmp+A[i][j]*X[j]; } X[i]=B[i]-tmp; tmp=0; } */ }
NumberFormat* NumberFormat::makeInstance(const Locale& desiredLocale, UNumberFormatStyle style, UErrorCode& status) { return makeInstance(desiredLocale, style, false, status); }
Instances *ThresholdCurve::getCurve(std::vector<Prediction*> predictions, const int classIndex) { if ((predictions.size() == 0) || ((static_cast<NominalPrediction*>(predictions.at(0)))->distribution().size() <= classIndex)) { return nullptr; } double totPos = 0, totNeg = 0; double_array probs = getProbabilities(predictions, classIndex); // Get distribution of positive/negatives for (int i = 0; i < probs.size(); i++) { NominalPrediction *pred = static_cast<NominalPrediction*>(predictions.at(i)); if (pred->actual() == Prediction::MISSING_VALUE) { std::cout << " Skipping prediction with missing class value"; continue; } if (pred->weight() < 0) { std::cout << " Skipping prediction with negative weight"; continue; } if (pred->actual() == classIndex) { totPos += pred->weight(); } else { totNeg += pred->weight(); } } Instances *insts = makeHeader(); int_array sorted = Utils::Sort(probs); TwoClassStats *tc = new TwoClassStats(totPos, totNeg, 0, 0); double threshold = 0; double cumulativePos = 0; double cumulativeNeg = 0; for (int i = 0; i < sorted.size(); i++) { if ((i == 0) || (probs[sorted[i]] > threshold)) { tc->setTruePositive(tc->getTruePositive() - cumulativePos); tc->setFalseNegative(tc->getFalseNegative() + cumulativePos); tc->setFalsePositive(tc->getFalsePositive() - cumulativeNeg); tc->setTrueNegative(tc->getTrueNegative() + cumulativeNeg); threshold = probs[sorted[i]]; insts->add(*makeInstance(tc, threshold)); cumulativePos = 0; cumulativeNeg = 0; if (i == sorted.size() - 1) { break; } } NominalPrediction *pred = static_cast<NominalPrediction*>(predictions.at(sorted[i])); if (pred->actual() == Prediction::MISSING_VALUE) { std::cout << " Skipping prediction with missing class value"; continue; } if (pred->weight() < 0) { std::cout << " Skipping prediction with negative weight"; continue; } if (pred->actual() == classIndex) { cumulativePos += pred->weight(); } else { cumulativeNeg += pred->weight(); } } // make sure a zero point gets into the curve if (tc->getFalseNegative() != totPos || tc->getTrueNegative() != totNeg) { tc = new TwoClassStats(0, 0, totNeg, totPos); threshold = probs[sorted[sorted.size() - 1]] + 10e-6; insts->add(*makeInstance(tc, threshold)); } return insts; }