L::Integrator::Status L::RuleIntegratorErr::integrate ( Integrand &f, const Hypercube &h, Index maxEval, real reqAbsError, real reqRelError, EstErr &ee) { checkDimension(h, f); checkTerminationCriteria (maxEval, reqAbsError, reqRelError, false); std::auto_ptr<EmbeddedRule> rule (getRule(h.getDimension())); if (maxEval < rule->getNumPoints ()) { #ifdef HINTLIB_NO_EXCEPTIONS ee.set (0.0, 0.0); return ERROR; #else throw NoEvaluationsPossible (maxEval); #endif } rule->evalError (f, h, ee); Status status = checkRequestedError (ee, reqAbsError, reqRelError); return (status == ERROR) ? MAX_EVAL_REACHED : status; }
Dimension DesktopServerProto::readDimension(BlockingGate *gate) { Dimension dim; dim.width = gate->readInt32(); dim.height = gate->readInt32(); checkDimension(&dim); return dim; }
static void readPPMHeader(FILE *fp, int *width, int *height) { char ch; int maxval; if (fscanf(fp, "P%c\n", &ch) != 1 || ch != '6') { printf("file is not in ppm raw format; cannot read"); return ; } /* skip comments */ ch = getc(fp); while (ch == '#') { do { ch = getc(fp); } while (ch != '\n'); /* read to the end of the line */ ch = getc(fp); /* thanks, Elliot */ } if (!isdigit(ch)) { printf("cannot read header information from ppm file"); return ; } ungetc(ch, fp); /* put that digit back */ /* read the width, height, and maximum value for a pixel */ fscanf(fp, "%d%d%d\n", width, height, &maxval); if (maxval != 255) { printf("image is not true-color (24 bit); read failed"); return ; } checkDimension(*width); checkDimension(*height); }
Integrator::Status RQMCIntegrator::integrate( Integrand &f, const Hypercube &h, Index n, real, real, EstErr &ee) { checkDimension(h, f); if (n == 0) { ee.set(0.0, 0.0); return ERROR; } ps->setCube(&h); n = ps->getOptimalNumber(n, h); ps->enableRandomize(); if (randCount == 0) return ERROR; int m = n / randCount; std::vector<Statistic<>> stats(randCount); std::default_random_engine e(globalSeed); for (unsigned int i = 0; i < randCount; i++) { Statistic<> s; Point point(h.getDimension()); int seed = e(); ps->randomize(seed); ps->integrate(point, f, m, s); stats[i] = s; } std::vector<double> estimates; estimates.reserve(randCount); for (auto x : stats) estimates.push_back(x.getMean() * h.getVolume()); double rqmcEst = sum(estimates) / randCount; double rqmcStdError = std::sqrt(var(estimates) / randCount); if (randCount == 1) rqmcStdError = 0; ee.set(rqmcEst, rqmcStdError); return MAX_EVAL_REACHED; }
L::Integrator::Status L::RuleIntegrator::integrate ( Integrand &f, const Hypercube &h, Index maxEval, real reqAbsError, real reqRelError, EstErr &ee) { checkDimension(h, f); checkTerminationCriteria (maxEval, reqAbsError, reqRelError, false); std::auto_ptr<CubatureRule> rule (getRule(h.getDimension())); if (maxEval < rule->getNumPoints ()) { #ifdef HINTLIB_NO_EXCEPTIONS ee.set (0.0, 0.0); return ERROR; #else throw NoEvaluationsPossible (maxEval); #endif } ee.setNoErr (rule->eval(f, h)); return MAX_EVAL_REACHED; }