/*=========================================================================== C-equivalent of R-function lagderiv =========================================================================== */ SEXP getLagDeriv(SEXP T, SEXP nr) { SEXP value; int i, ilen, interval; double t; ilen = LENGTH(nr); if (initialisehist == 0) error("pastgradient can only be called from 'func' or 'res' when triggered by appropriate integrator."); if (!isNumeric(T)) error("'t' should be numeric"); t = *NUMERIC_POINTER(T); interval = findHistInt (t); if ((ilen ==1) && (INTEGER(nr)[0] == 0)) { PROTECT(value=NEW_NUMERIC(n_eq)); for(i=0; i<n_eq; i++) { NUMERIC_POINTER(value)[i] = past(i, interval, t, 2); } } else { PROTECT(value=NEW_NUMERIC(ilen)); for(i=0; i<ilen; i++) { NUMERIC_POINTER(value)[i] = past(INTEGER(nr)[i]-1, interval, t, 2); } } UNPROTECT(1); return(value); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); setWindowIcon(QIcon(":icons/icon.png")); setWindowTitle("quickly translate"); QSystemTrayIcon * trayIcon = new QSystemTrayIcon(this); mNetManager = new QNetworkAccessManager(this); mLangageModel = new LanguageModel; trayIcon->setIcon(QIcon(":icons/icon.png")); trayIcon->setContextMenu(ui->menuFile); trayIcon->show(); ui->dockWidget->hide(); ui->sourceComboBox->setModel(mLangageModel); ui->targetComboBox->setModel(mLangageModel); QDesktopWidget * desktop = new QDesktopWidget; QPoint startPos = QPoint(desktop->geometry().bottomRight() ); QPoint finalPos = desktop->geometry().center() - QPoint(width()/2,height()/2); move(finalPos); connect(trayIcon,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),this,SLOT(trayActivated(QSystemTrayIcon::ActivationReason))); connect(ui->actionExit,SIGNAL(triggered()),this,SLOT(exit())); connect(ui->translateButton,SIGNAL(clicked()),this,SLOT(translate())); connect(ui->sourceTextEdit,SIGNAL(returnPressed()),this,SLOT(translate())); connect(ui->swapButton,SIGNAL(clicked()),this,SLOT(swapLangages())); connect(ui->actionCopy,SIGNAL(triggered()),this,SLOT(copy())); connect(ui->actionCut,SIGNAL(triggered()),this,SLOT(cut())); connect(ui->actionPast,SIGNAL(triggered()),this,SLOT(past())); connect(ui->actionPreferences,SIGNAL(triggered()),this,SLOT(showPreferences())); connect(ui->actionAboutQt,SIGNAL(triggered()),this,SLOT(showAboutQt())); connect(ui->actionAbout,SIGNAL(triggered()),this,SLOT(showAbout())); connect(ui->actionTTS,SIGNAL(triggered()),this,SLOT(showTextTTS())); connect(ui->sourceSoundButton,SIGNAL(clicked()),this,SLOT(textToSpeak())); connect(ui->targetSoundButton,SIGNAL(clicked()),this,SLOT(textToSpeak())); // mPropertyAnimation = new QPropertyAnimation(this, "pos"); // mPropertyAnimation->setDuration(800); // mPropertyAnimation->setStartValue(startPos); // mPropertyAnimation->setEndValue(finalPos); //load default langage QSettings settings; QString sourceId = settings.value("source").toString(); QString targetId = settings.value("target").toString(); ui->sourceComboBox->setCurrentIndex(mLangageModel->findLangageId(sourceId)); ui->targetComboBox->setCurrentIndex(mLangageModel->findLangageId(targetId)); }
void lagvalue(double T, int *nr, int N, double *ytau) { int i, interval; if (initialisehist == 0) error("pastvalue can only be called from 'func' or 'res' when triggered by appropriate integrator."); interval = findHistInt(T); for(i = 0; i < N; i++) ytau[i] = past(nr[i], interval, T, 1); }
void FITSdateTest::testComparison() { debug(LOG_DEBUG, DEBUG_LOG, 0, "testComparison() begin"); FITSdate past("1982-02-14"); FITSdate now; CPPUNIT_ASSERT(past < now); CPPUNIT_ASSERT(past == past); CPPUNIT_ASSERT(now == now); CPPUNIT_ASSERT(!(past == now)); debug(LOG_DEBUG, DEBUG_LOG, 0, "testComparison() end"); }
void Channel::supply(Variant *var) { if (!var) return; Lock l(mutex); unsigned long id = push(var); while (!past(id, received)) cond->wait(mutex); }
const EHEnt* Func::findEH(Offset o) const { ASSERT(o >= base() && o < past()); const EHEnt* eh = NULL; unsigned int i; const EHEntVec& ehtab = shared()->m_ehtab; for (i = 0; i < ehtab.size(); i++) { if (ehtab[i].m_base <= o && o < ehtab[i].m_past) { eh = &ehtab[i]; } } return eh; }
/** * Return true if Offset o is inside the protected region of a fault * funclet for iterId, otherwise false. */ bool Func::checkIterScope(Offset o, Id iterId) const { const EHEntVec& ehtab = shared()->m_ehtab; ASSERT(o >= base() && o < past()); for (unsigned i = 0, n = ehtab.size(); i < n; i++) { const EHEnt* eh = &ehtab[i]; if (eh->m_ehtype == EHEnt::EHType_Fault && eh->m_base <= o && o < eh->m_past && eh->m_iterId == iterId) { return true; } } return false; }
bool Func::checkIterScope(Offset o, Id iterId, bool& itRef) const { const EHEntVec& ehtab = shared()->m_ehtab; assert(o >= base() && o < past()); for (unsigned i = 0, n = ehtab.size(); i < n; i++) { const EHEnt* eh = &ehtab[i]; if (eh->m_type == EHEnt::Type::Fault && eh->m_base <= o && o < eh->m_past && eh->m_iterId == iterId) { itRef = eh->m_itRef; return true; } } return false; }
const FPIEnt* Func::findPrecedingFPI(Offset o) const { ASSERT(o >= base() && o < past()); const FPIEntVec& fpitab = shared()->m_fpitab; ASSERT(fpitab.size()); const FPIEnt* fe = &fpitab[0]; unsigned int i; for (i = 1; i < fpitab.size(); i++) { const FPIEnt* cur = &fpitab[i]; if (o > cur->m_fcallOff && fe->m_fcallOff < cur->m_fcallOff) { fe = cur; } } ASSERT(fe); return fe; }
int ctrl_y(t_elem *e) { t_string *cpy; t_string *save; if (taille_clip(e) < 1) return (0); save = e->cursor; cpy = e->clipboard; my_tputs(e->cap[VI]); _bol(e, 0); while (e->cursor != save) e->cursor = e->cursor->next; past(e, cpy, save); my_tputs(e->cap[VE]); return (0); }
void MainWindow::trayActivated(QSystemTrayIcon::ActivationReason reason) { if ( reason != QSystemTrayIcon::Trigger) return; if (isHidden()) { show(); QSettings settings; if (settings.value("autopast").toBool()) past(); if (settings.value("autotranslate").toBool()) translate(); } else hide(); }
const FPIEnt* Func::findFPI(Offset o) const { ASSERT(o >= base() && o < past()); const FPIEnt* fe = NULL; unsigned int i; const FPIEntVec& fpitab = shared()->m_fpitab; for (i = 0; i < fpitab.size(); i++) { /* * We consider the "FCall" instruction part of the FPI region, but * the corresponding push is not considered part of it. (This * means all offsets in the FPI region will have the partial * ActRec on the stack.) */ if (fpitab[i].m_fpushOff < o && o <= fpitab[i].m_fcallOff) { fe = &fpitab[i]; } } return fe; }
Offset Func::findFaultPCFromEH(Offset o) const { ASSERT(o >= base() && o < past()); unsigned int i = 0; int max = -1; const EHEntVec& ehtab = shared()->m_ehtab; for (i = 0; i < ehtab.size(); i++) { if (ehtab[i].m_ehtype == EHEnt::EHType_Catch) { continue; } if (ehtab[i].m_fault < o && (max == -1 || ehtab[i].m_fault > ehtab[max].m_fault)) { max = i; } } ASSERT(max != -1); return ehtab[max].m_past; }
/*! */ void Dmc_method::runWithVariables(Properties_manager & prop, System * sys, Wavefunction_data * wfdata, Pseudopotential * pseudo, ostream & output) { allocateIntermediateVariables(sys, wfdata); if(!wfdata->supports(laplacian_update)) error("DMC doesn't support all-electron moves..please" " change your wave function to use the new Jastrow"); cout.precision(15); output.precision(10); prop.setSize(wf->nfunc(), nblock, nstep, nconfig, sys, wfdata); restorecheckpoint(readconfig, sys, wfdata, pseudo); prop.initializeLog(average_var); //MB: new properties manager for forward walking (one per each length) Array1 <Properties_manager> prop_fw; prop_fw.Resize(fw_length.GetSize()); if(max_fw_length){ for(int s=0;s<fw_length.GetSize();s++){ string logfile, label_temp; prop.getLog(logfile, label_temp); char strbuff[40]; sprintf(strbuff, "%d", fw_length(s)); label_temp+="_fw"; label_temp+=strbuff; prop_fw(s).setLog(logfile, label_temp); prop_fw(s).setSize(wf->nfunc(), nblock, nstep, nconfig, sys, wfdata); prop_fw(s).initializeLog(average_var); } } if(nhist==-1) nhist=1; doublevar teff=timestep; for(int block=0; block < nblock; block++) { int totkilled=0; int totbranch=0; int totpoints=0; for(int step=0; step < nstep; ) { int npsteps=min(feedback_interval, nstep-step); Dynamics_info dinfo; doublevar acsum=0; doublevar deltar2=0; Array1 <doublevar> epos(3); doublevar avg_acceptance=0; for(int walker=0; walker < nconfig; walker++) { pts(walker).config_pos.restorePos(sample); wf->updateLap(wfdata, sample); //------Do several steps without branching for(int p=0; p < npsteps; p++) { pseudo->randomize(); for(int e=0; e< nelectrons; e++) { int acc; acc=dyngen->sample(e, sample, wf, wfdata, guidingwf, dinfo, timestep); if(dinfo.accepted) deltar2+=dinfo.diffusion_rate/(nconfig*nelectrons*npsteps); if(dinfo.accepted) { pts(walker).age(e)=0; } else { pts(walker).age(e)++; } avg_acceptance+=dinfo.acceptance/(nconfig*nelectrons*npsteps); if(acc>0) acsum++; } totpoints++; Properties_point pt; if(tmoves or tmoves_sizeconsistent) { //------------------T-moves doTmove(pt,pseudo,sys,wfdata,wf,sample,guidingwf); } ///---------------------------------done with the T-moves else { mygather.gatherData(pt, pseudo, sys, wfdata, wf, sample, guidingwf); } Dmc_history new_hist; new_hist.main_en=pts(walker).prop.energy(0); pts(walker).past_energies.push_front(new_hist); deque<Dmc_history> & past(pts(walker).past_energies); if(past.size() > nhist) past.erase(past.begin()+nhist, past.end()); pts(walker).prop=pt; if(!pure_dmc) { pts(walker).weight*=getWeight(pts(walker),teff,etrial); //Introduce potentially a small bias to avoid instability. if(pts(walker).weight>max_poss_weight) pts(walker).weight=max_poss_weight; } else pts(walker).weight=getWeightPURE_DMC(pts(walker),teff,etrial); if(pts(walker).ignore_walker) { pts(walker).ignore_walker=0; pts(walker).weight=1; pts(walker).prop.count=0; } pts(walker).prop.weight=pts(walker).weight; //This is somewhat inaccurate..will need to change it later //For the moment, the autocorrelation will be slightly //underestimated pts(walker).prop.parent=walker; pts(walker).prop.nchildren=1; pts(walker).prop.children(0)=walker; pts(walker).prop.avgrets.Resize(1,average_var.GetDim(0)); for(int i=0; i< average_var.GetDim(0); i++) { average_var(i)->randomize(wfdata,wf,sys,sample); average_var(i)->evaluate(wfdata, wf, sys, pseudo, sample, pts(walker).prop.avgrets(0,i)); } prop.insertPoint(step+p, walker, pts(walker).prop); for(int i=0; i< densplt.GetDim(0); i++) densplt(i)->accumulate(sample,pts(walker).prop.weight(0)); for(int i=0; i< nldensplt.GetDim(0); i++) nldensplt(i)->accumulate(sample,pts(walker).prop.weight(0), wfdata,wf); //MB: making the history of prop.avgrets for forward walking if(max_fw_length){ forwardWalking(walker, step+p,prop_fw); }//if FW } pts(walker).config_pos.savePos(sample); } //---Finished moving all walkers doublevar accept_ratio=acsum/(nconfig*nelectrons*npsteps); teff=timestep*accept_ratio; //deltar2/rf_diffusion; updateEtrial(feedback); step+=npsteps; int nkilled; if(!pure_dmc) nkilled=calcBranch(); else nkilled=0; totkilled+=nkilled; totbranch+=nkilled; } ///----Finished block if(!low_io || block==nblock-1) { savecheckpoint(storeconfig,sample); for(int i=0; i< densplt.GetDim(0); i++) densplt(i)->write(); for(int i=0; i< nldensplt.GetDim(0); i++) nldensplt(i)->write(log_label); } if(!pure_dmc){ prop.endBlock(); } else prop.endBlockSHDMC(); if(max_fw_length){ for(int s=0;s<fw_length.GetSize();s++){ //prop_fw(s).endBlock(); prop_fw(s).endBlock_per_step(); } } totbranch=parallel_sum(totbranch); totkilled=parallel_sum(totkilled); totpoints=parallel_sum(totpoints); Properties_final_average finavg; prop.getFinal(finavg); eref=finavg.avg(Properties_types::total_energy,0); updateEtrial(feedback); doublevar maxage=0; doublevar avgage=0; for(int w=0;w < nconfig; w++) { for(int e=0; e< nelectrons; e++) { if(maxage<pts(w).age(e)) maxage=pts(w).age(e); avgage+=pts(w).age(e); } } avgage/=(nconfig*nelectrons); if(output) { //cout << "Block " << block // << " nconfig " << totconfig // << " etrial " << etrial << endl; if(global_options::rappture ) { ofstream rapout("rappture.log"); rapout << "=RAPPTURE-PROGRESS=>" << int(100.0*doublevar(block+1)/doublevar(nblock)) << " Diffusion Monte Carlo" << endl; cout << "=RAPPTURE-PROGRESS=>" << int(100.0*doublevar(block+1)/doublevar(nblock)) << " Diffusion Monte Carlo" << endl; rapout.close(); } output << "***" << endl; output << "Block " << block << " etrial " << etrial << endl; output << "maximum age " << maxage << " average age " << avgage << endl; dyngen->showStats(output); prop.printBlockSummary(output); output << "Branched " << totbranch << " times. So a branch every " << doublevar(totpoints)/doublevar(totbranch) << " steps " << endl; } dyngen->resetStats(); } if(output) { output << "\n ----------Finished DMC------------\n\n"; prop.printSummary(output,average_var); //MB: final printout for FW if(max_fw_length){ for(int s=0;s<fw_length.GetSize();s++) prop_fw(s).printSummary(output,average_var); } } wfdata->clearObserver(); deallocateIntermediateVariables(); }
void print_func_body(Output& out, const FuncInfo& finfo) { auto const func = finfo.func; auto lblIter = begin(finfo.labels); auto const lblStop = end(finfo.labels); auto ehIter = begin(finfo.ehStarts); auto const ehStop = end(finfo.ehStarts); auto bcIter = func->unit()->at(func->base()); auto const bcStop = func->unit()->at(func->past()); min_priority_queue<Offset> ehEnds; while (bcIter != bcStop) { auto const pop = reinterpret_cast<const Op*>(bcIter); auto const off = func->unit()->offsetOf(pop); // First, close any protected EH regions that are past-the-end at // this offset. while (!ehEnds.empty() && ehEnds.top() == off) { ehEnds.pop(); out.dec_indent(); out.fmtln("}}"); } // Next, open any new protected regions that start at this offset. for (; ehIter != ehStop && ehIter->first == off; ++ehIter) { auto const info = finfo.ehInfo.find(ehIter->second); always_assert(info != end(finfo.ehInfo)); match<void>( info->second, [&] (const EHCatch& catches) { out.indent(); out.fmt(".try_catch"); for (auto& kv : catches.blocks) { out.fmt(" ({} {})", kv.first, kv.second); } out.fmt(" {{"); out.nl(); }, [&] (const EHFault& fault) { out.fmtln(".try_fault {} {{", fault.label); } ); out.inc_indent(); ehEnds.push(ehIter->second->m_past); } // Then, print labels if we have any. This order keeps the labels // from dangling on weird sides of .try_fault or .try_catch // braces. while (lblIter != lblStop && lblIter->first < off) ++lblIter; if (lblIter != lblStop && lblIter->first == off) { out.dec_indent(); out.fmtln("{}:", lblIter->second); out.inc_indent(); } print_instr(out, finfo, bcIter); bcIter += instrLen(reinterpret_cast<const Op*>(bcIter)); } }
void cgCall(IRLS& env, const IRInstruction* inst) { auto const sp = srcLoc(env, inst, 0).reg(); auto const fp = srcLoc(env, inst, 1).reg(); auto const extra = inst->extra<Call>(); auto const callee = extra->callee; auto const argc = extra->numParams; auto& v = vmain(env); auto& vc = vcold(env); auto const catchBlock = label(env, inst->taken()); auto const calleeSP = sp[cellsToBytes(extra->spOffset.offset)]; auto const calleeAR = calleeSP + cellsToBytes(argc); v << store{fp, calleeAR + AROFF(m_sfp)}; v << storeli{safe_cast<int32_t>(extra->after), calleeAR + AROFF(m_soff)}; if (extra->fcallAwait) { // This clobbers any flags that might have already been set on the callee // AR (e.g., by SpillFrame), but this is okay because there should never be // any conflicts; see the documentation in act-rec.h. auto const imm = static_cast<int32_t>( ActRec::encodeNumArgsAndFlags(argc, ActRec::Flags::IsFCallAwait) ); v << storeli{imm, calleeAR + AROFF(m_numArgsAndFlags)}; } auto const isNativeImplCall = callee && callee->builtinFuncPtr() && !callee->nativeFuncPtr() && argc == callee->numParams(); if (isNativeImplCall) { // The assumption here is that for builtins, the generated func contains // only a single opcode (NativeImpl), and there are no non-argument locals. if (do_assert) { assertx(argc == callee->numLocals()); assertx(callee->numIterators() == 0); auto addr = callee->getEntry(); while (peek_op(addr) == Op::AssertRATL) { addr += instrLen(addr); } assertx(peek_op(addr) == Op::NativeImpl); assertx(addr + instrLen(addr) == callee->unit()->entry() + callee->past()); } v << store{v.cns(mcg->ustubs().retHelper), calleeAR + AROFF(m_savedRip)}; if (callee->attrs() & AttrMayUseVV) { v << storeqi{0, calleeAR + AROFF(m_invName)}; } v << lea{calleeAR, rvmfp()}; emitCheckSurpriseFlagsEnter(v, vc, fp, Fixup(0, argc), catchBlock); auto const builtinFuncPtr = callee->builtinFuncPtr(); TRACE(2, "Calling builtin preClass %p func %p\n", callee->preClass(), builtinFuncPtr); // We sometimes call this while curFunc() isn't really the builtin, so make // sure to record the sync point as if we are inside the builtin. if (FixupMap::eagerRecord(callee)) { auto const syncSP = v.makeReg(); v << lea{calleeSP, syncSP}; emitEagerSyncPoint(v, callee->getEntry(), rvmtl(), rvmfp(), syncSP); } // Call the native implementation. This will free the locals for us in the // normal case. In the case where an exception is thrown, the VM unwinder // will handle it for us. auto const done = v.makeBlock(); v << vinvoke{CallSpec::direct(builtinFuncPtr), v.makeVcallArgs({{rvmfp()}}), v.makeTuple({}), {done, catchBlock}, Fixup(0, argc)}; env.catch_calls[inst->taken()] = CatchCall::CPP; v = done; // The native implementation already put the return value on the stack for // us, and handled cleaning up the arguments. We have to update the frame // pointer and the stack pointer, and load the return value into the return // register so the trace we are returning to has it where it expects. // TODO(#1273094): We should probably modify the actual builtins to return // values via registers using the C ABI and do a reg-to-reg move. loadTV(v, inst->dst(), dstLoc(env, inst, 0), rvmfp()[AROFF(m_r)], true); v << load{rvmfp()[AROFF(m_sfp)], rvmfp()}; emitRB(v, Trace::RBTypeFuncExit, callee->fullName()->data()); return; } v << lea{calleeAR, rvmfp()}; if (RuntimeOption::EvalHHIRGenerateAsserts) { v << syncvmsp{v.cns(0x42)}; constexpr uint64_t kUninitializedRIP = 0xba5eba11acc01ade; emitImmStoreq(v, kUninitializedRIP, rvmfp()[AROFF(m_savedRip)]); } // Emit a smashable call that initially calls a recyclable service request // stub. The stub and the eventual targets take rvmfp() as an argument, // pointing to the callee ActRec. auto const target = callee ? mcg->ustubs().immutableBindCallStub : mcg->ustubs().bindCallStub; auto const done = v.makeBlock(); v << callphp{target, php_call_regs(), {{done, catchBlock}}}; env.catch_calls[inst->taken()] = CatchCall::PHP; v = done; auto const dst = dstLoc(env, inst, 0); v << defvmret{dst.reg(0), dst.reg(1)}; }