int main(void) { unsigned long long fib[1503] = {0}, num; char d[10001]; int T, i, len; // Fill up first 1500 fibonacci numbers fib[1] = fib[2] = fib[1501] = fib[1501] = 1; for(i = 2; i < 1500; i++) { fib[i] = (fib[i - 1] + fib[i - 2]) % 1000; } while(scf("%d", &T) != EOF) { while(T--) { scf("%s%n", d, &len); len--; // Christian Bonilian's voodoo to get the modular number for(num = i = 0; i < len; i++) { num *= 2; num += (d[i] - '0'); num %= 1500; } prf("%03lld\n", fib[num]); } } return 0; }
double scf(Electronic_Structure& el, System& syst, vector<AO>& basis_ao, Control_Parameters& prms,Model_Parameters& modprms, vector< vector<int> >& atom_to_ao_map, vector<int>& ao_to_atom_map, int BM ){ /** Python-friendly version This function implements the SCF with the choice of algorithms: SCF_none, SCF_oda, SCF_oda_disk The choice is controlled by the parameter prms \param[in,out] el The object containing all the electronic structure information (MO-LCAO coefficients, density matrix, Fock, etc) \param[in,out] syst The reference to the object containing all the nuclear information - geometry and atomic types \param[in] basis_ao The vector of AO objects - the AO basis for given calculations \param[in] prms The object that contains all the parameters controlling the simulation - all settings, flags, etc. \param[in,out] modprms The object that contains all the Hamiltonian parameters for given system and method choice \param[in] atom_to_ao_map The mapping from the atomic indices to the lists of the indices of AOs localized on given atom \param[in] ao_to_atom_map The mapping from the AO index to the index of atoms on which given AO is localized \param[in] BM Benchmark flag - if =1 - do some benchmarking, if =0 - don't do it Returns the converged total electronic energy */ return scf(&el,syst,basis_ao, prms,modprms, atom_to_ao_map,ao_to_atom_map, BM); }
void addBackEnd::activatedAddMenu(int id) { kdDebug() << "activatedAddMenu: " << QString("%1").arg(id) << endl; if (((uint)id) == libNames.size()) doRollBack(); if(((uint)id) >= libNames.size()) return; KLibLoader *loader = KLibLoader::self(); // try to load the library QString libname = *libNames.at(id); KLibrary *lib = loader->library(QFile::encodeName(libname)); if (lib) { // get the create_ function QString factory("add_"); factory = factory+(*libNames.at(id)); void *add = lib->symbol(QFile::encodeName(factory)); if (add) { //call the add function bool (*func)(QString*, QString*, QMap<QString,QString> *); QMap<QString,QString> map; func = (bool (*)(QString*, QString*, QMap<QString,QString> *)) add; QString *tmp = new QString(""); if (func(tmp,libParam.at(id),&map)) { QString myFile = findFileName(tmp,m_universal,m_currentProfile); if (!myFile.isEmpty()) { kdDebug() <<"trying to save to file: "<<myFile << endl; KSimpleConfig scf(myFile,false); scf.setGroup("Desktop Entry"); for (QMap<QString,QString>::ConstIterator it = map.begin(); it != map.end(); ++it) { kdDebug() <<"writing:"<<it.key()<<" / "<<it.data()<<endl; scf.writePathEntry(it.key(), it.data()); } scf.sync(); emit updateNeeded(); } else { kdWarning() << "No unique filename found" << endl; } } else { kdWarning() << "No new entry (error?)" << endl; } delete tmp; } } else { kdWarning() << "libname:" << libNames.at(id) << " doesn't specify a library!" << endl; } }
void sys_rhs( KNVector& out, double t, const KNMatrix& x, const KNVector& par ) { if( (t < 0)||(t > 1) ){ std::cout << "rhs: t is not element of the interval\n"; } double g; if( t < TAU2 ) g = 1.0; else g = 0.0; double ttt = (2.0*t - floor(2.0*t))/2.0; double phi = 2*M_PI*ttt; out(0) = x(1,0); out(1) = -x(0,0) - 2*ZETA*x(1,0) + g*par(2)*scf( phi, x(0,0), x(0,1) ); }
void Sidebar_Widget::addWebSideBar(const KURL& url, const QString& /*name*/) { //kdDebug() << "Web sidebar entry to be added: " << url.url() // << " [" << name << "]" << endl; // Look for existing ones with this URL KStandardDirs *dirs = KGlobal::dirs(); QString list; dirs->saveLocation("data", m_relPath, true); list = locateLocal("data", m_relPath); // Go through list to see which ones exist. Check them for the URL QStringList files = QDir(list).entryList("websidebarplugin*.desktop"); for (QStringList::Iterator it = files.begin(); it != files.end(); ++it){ KSimpleConfig scf(list + *it, false); scf.setGroup("Desktop Entry"); if (scf.readPathEntry("URL", QString::null) == url.url()) { // We already have this one! KMessageBox::information(this, i18n("This entry already exists.")); return; } } QString tmpl = "websidebarplugin%1.desktop"; QString myFile = findFileName(&tmpl,m_universalMode,m_currentProfile); if (!myFile.isEmpty()) { KSimpleConfig scf(myFile, false); scf.setGroup("Desktop Entry"); scf.writeEntry("Type", "Link"); scf.writePathEntry("URL", url.url()); scf.writeEntry("Icon", "netscape"); scf.writeEntry("Name", i18n("Web SideBar Plugin")); scf.writeEntry("Open", "true"); scf.writeEntry("X-KDE-KonqSidebarModule", "konqsidebar_web"); scf.sync(); QTimer::singleShot(0,this,SLOT(updateButtons())); } }
void HierarchySaveLink::do_add(kernel::Particle *p, RMF::NodeHandle cur) { IMP_USAGE_CHECK(atom::Hierarchy(p).get_is_valid(true), "Invalid hierarchy passed."); RMF::SetCurrentFrame scf(cur.get_file(), RMF::ALL_FRAMES); data_.insert( std::make_pair(p->get_index(), boost::make_shared<Data>(cur.get_file()))); add_recursive(p->get_model(), p->get_index(), p->get_index(), ParticleIndexes(), cur, *data_[p->get_index()]); P::add_link(p, cur); data_[p->get_index()] ->save_bonds.setup_bonds(p->get_model(), p->get_index(), cur); }
int main(void) { int N; double min, max; while(scf("%d", &N) != EOF) { min = N / log(N); max = 1.25506 * min; prf("%.1f %.1f\n", min, max); } return 0; }
static F2(jtpdtspvv){A x;D*av,s,t,*wv,z;I i,*u,*u0,*uu,*v,*v0,*vv;P*ap,*wp; RZ(a&&w); ap=PAV(a); x=SPA(ap,i); u=u0=AV(x); uu=u+AN(x); x=SPA(ap,x); av=DAV(x); wp=PAV(w); x=SPA(wp,i); v=v0=AV(x); vv=v+AN(x); x=SPA(wp,x); wv=DAV(x); z=0.0; NAN0; while(1){ i=*u; while(i>*v&&v<vv)++v; if(v==vv)break; if(i==*v){s=av[u-u0]; t=wv[v-v0]; z+=s&&t?s*t:0; ++u; ++v; continue;} i=*v; while(i>*u&&u<uu)++u; if(u==uu)break; if(i==*u){s=av[u-u0]; t=wv[v-v0]; z+=s&&t?s*t:0; ++u; ++v; continue;} } NAN1; R scf(z); }
TEST(SparseFunction, JacobianComputation) { SparseCountingFunctor scf(100, 100); std::vector<double> pt(100); for (int i = 0; i < 100; ++i) pt[i] = i; auto J = scf.getJacobian(&pt[0]); int cntSparse = CountingFunctor::counter; CountingFunctor::counter = 0; NonSparseCountingFunctor nscf(100, 100); auto J2=nscf.getJacobian(&pt[0]); int cntNonSparse = CountingFunctor::counter; ASSERT_TRUE(cntNonSparse > 2 * cntSparse); ASSERT_LE((J - J2).frobeniusNorm(), 1e-9); }
void elecMinimize(Everything& e) { if(e.cntrl.scf) { SCF scf(e); scf.minimize(); } else if((not e.cntrl.fixed_H) or e.exCorr.exxFactor()) { ElecMinimizer emin(e); emin.minimize(e.elecMinParams); e.eVars.setEigenvectors(); } else { bandMinimize(e); } e.eVars.isRandom = false; //wavefunctions are no longer random //Converge empty states if necessary: if(e.cntrl.convergeEmptyStates and (not e.cntrl.fixed_H)) convergeEmptyStates(e); }
int main(int argc, char *argv[]) { int rv; char *full; if (argc != 3) { fprintf(stderr, "usage:\n" " sbsnarf full-path-to-sb output-bytecode-file\n\n"); return -1; } full = realpath(argv[1], NULL); printf("[+] full path to sb: \"%s\"\n", full); void *h = dlopen("libsandbox.1.dylib", RTLD_FIRST | RTLD_LAZY | RTLD_LOCAL); if (NULL == h) { errx(-1, "dlopen failed: %s", dlerror()); } void *(*scf)(char *, int, char **) = dlsym(h, "sandbox_compile_file"); if (NULL == scf) { errx(-1, "dlsym failed: %s", dlerror()); } void (*sfp)(void *) = dlsym(h, "sandbox_free_profile"); if (NULL == sfp) { errx(-1, "dlsym failed: %s", dlerror()); } char *error; struct { unsigned int type; user_addr_t bytecode; user_size_t bytecode_length; } *sb = scf(full, 0, &error); if (NULL == sb) { dlclose(h); errx(-1, "sandbox_compile_file failed: %s", error); } if (NULL != error) { free(error); } FILE *f_out = fopen(argv[2], "wb"); if (NULL == f_out) { sfp(sb); dlclose(h); err(-1, "fopen failed:"); } rv = fwrite((void *) sb->bytecode, sb->bytecode_length, 1, f_out); if (1 != rv) { sfp(sb); dlclose(h); err(-1, "fwrite failed:"); } fclose(f_out); sfp(sb); dlclose(h); printf("[+] success!\n"); return 0; }
int main (int argc, char *argv[]) { int32 checkpointVers = 0; int32 tigStoreVers = 0; GlobalData = new Globals_CGW(); argc = AS_configure(argc, argv); int arg=1; int err=0; while (arg < argc) { if (strcmp(argv[arg], "-g") == 0) { strcpy(GlobalData->gkpStoreName, argv[++arg]); } else if (strcmp(argv[arg], "-t") == 0) { strcpy(GlobalData->tigStoreName, argv[++arg]); tigStoreVers = atoi(argv[++arg]); } else if (strcmp(argv[arg], "-c") == 0) { strcpy(GlobalData->outputPrefix, argv[++arg]); checkpointVers = atoi(argv[++arg]); } else { fprintf(stderr, "%s: unknown option '%s'\n", argv[0], argv[arg]); err++; } arg++; } if ((GlobalData->gkpStoreName[0] == 0) || (GlobalData->tigStoreName[0] == 0) || (err)) { fprintf(stderr, "usage: %s -g gkpStore [-o prefix] [-s firstUID] [-n namespace] [-E server] [-h]\n", argv[0]); fprintf(stderr, " -g gkpStore mandatory path to the gkpStore\n"); fprintf(stderr, " -t tigStore version mandatory path to the tigStore and version\n"); fprintf(stderr, " -c checkpoint version optional path to a checkpoint and version\n"); fprintf(stderr, "\n"); exit(1); } LoadScaffoldGraphFromCheckpoint(GlobalData->outputPrefix, checkpointVers, FALSE); vector<instrumentLIB> lib; for (int32 i=0; i<GetNumDistTs(ScaffoldGraph->Dists); i++) { DistT *dptr = GetDistT(ScaffoldGraph->Dists, i); lib.push_back(instrumentLIB(i, dptr->mu, dptr->sigma, true)); } GraphNodeIterator scaffolds; CIScaffoldT *scaffold; InitGraphNodeIterator(&scaffolds, ScaffoldGraph->ScaffoldGraph, GRAPH_NODE_DEFAULT); while ((scaffold = NextGraphNodeIterator(&scaffolds)) != NULL) { if(scaffold->type != REAL_SCAFFOLD) continue; //if (scaffold->id != 14) // continue; instrumentSCF scf(scaffold); scf.analyze(lib); scf.report(); } DestroyScaffoldGraph(ScaffoldGraph); return(0); }
/** * Returns set of initial states of automaton * * @param aut: automaton * @return: set of initial states */ void getInitialStatesOfAutomaton(Automaton & aut, MTBDDLeafStateSet & initialStates) { TransMTBDD* bdd = getMTBDDForStateTuple(aut, Automaton::StateTuple()); StateCollectorFunctor scf(initialStates); scf(*bdd); }
void sys_deri( KNMatrix &out, double t, const KNMatrix& x, const KNVector& par, size_t nx, const size_t* vx, size_t np, const size_t* vp, const KNMatrix& vv ) { if( (t < 0)||(t > 1) ){ std::cout << "deri: t is not element of the interval\n"; } double g; if( t < TAU2 ) g = 1.0; else g = 0.0; double ttt = (2.0*t - floor(2.0*t))/2.0; double phi = 2*M_PI*ttt; // derivatives w.r.t. the dependent variables: x(t), x(t-tau1), etc. if( (nx == 1) && (np == 0) ){ switch( vx[0] ){ case 0: out(0,0) = 0.0; out(0,1) = 1.0; out(1,0) = -1.0 + g*par(2)*d_scf_x0( phi, x(0,0), x(0,1) ); out(1,1) = -2.0*ZETA; break; case 1: out(0,0) = 0.0; out(0,1) = 0.0; out(1,0) = g*par(2)*d_scf_x1( phi, x(0,0), x(0,1) ); out(1,1) = 0.0; break; default: std::cout << "deri: not implemented\n"; break; } } // derivatives w.r.t. the parameters, purely, so this results a vector if( (nx == 0) && (np == 1) ){ switch( vp[0] ){ case 0: // T period length std::cout << "deri w.r.t. T: not implemented\n"; break; case 2: out(0) = 0.0; out(1) = g*scf( phi, x(0,0), x(0,1) ); break; default: std::cout << "deri: not implemented\n"; break; } } // second derivatives wrt. xx if( (nx == 2) && (np == 0) ){ switch( vx[0] ){ // phi(.,vx[0]) case 0: switch( vx[1] ){ case 0: // o(0) = 1.0 * vv[1]; // o(1) = ( - // g*g1*par(2)*d_cf( H0 + x(0,1) - x(0,0) ) - // g*g2*par(2)*d_cf( 2*H0 + x(0,2) - x(0,0) ) )*vv[0] // -2.0*ZETA * vv[1]; out(0,0) = 0.0; out(0,1) = 0.0; out(1,0) = g*par(2)*d_scf_x0x0( phi, x(0,0), x(0,1) )*vv(0,0); out(1,1) = 0.0; //std::std::cout<<"-00-"<<g*par(2)*d_scf_x0x0( x(0,0), x(0,1) )*vv(0,0); break; case 1: out(0,0) = 0.0; out(0,1) = 0.0; out(1,0) = g*par(2)*d_scf_x0x1( phi, x(0,0), x(0,1) )*vv(0,0); out(1,1) = 0.0; //std::std::cout<<"-01-"<<g*par(2)*d_scf_x0x1( x(0,0), x(0,1) )*vv(0,0); break; default: std::cout << "deri: not implemented\n"; break; } break; case 1: // out(0) = 0.0; // out(1) = g*g1*par(2)*d_cf( H0 + x(0,1) - x(0,0) )*vv[0]; switch( vx[1] ){ case 0: out(0,0) = 0.0; out(0,1) = 0.0; out(1,0) = g*par(2)*d_scf_x0x1( phi, x(0,0), x(0,1) )*vv(0,1); out(1,1) = 0.0; //std::std::cout<<"-10-"<<g*par(2)*d_scf_x0x1( x(0,0), x(0,1) )*vv(0,1); break; case 1: out(0,0) = 0.0; out(0,1) = 0.0; out(1,0) = g*par(2)*d_scf_x1x1( phi, x(0,0), x(0,1) )*vv(0,1); out(1,1) = 0.0; //std::std::cout<<"-11-"<<g*par(2)*d_scf_x1x1( x(0,0), x(0,1) )*vv(0,1); break; default: std::cout << "deri: not implemented\n"; break; } break; default: std::cout << "deri: not implemented\n"; break; } } // mixed derivative wrt to xx and par if( (nx == 1) && (np == 1) ){ switch( vp[0] ){ case 0: // T period length std::cout << "deri w.r.t. T: not implemented\n"; break; case 2: switch( vx[0] ){ case 0: out(0,0) = 0.0; out(0,1) = 0.0; out(1,0) = g*d_scf_x0( phi, x(0,0), x(0,1) ); out(1,1) = 0.0; break; case 1: out(0,0) = 0.0; out(0,1) = 0.0; out(1,0) = g*d_scf_x1( phi, x(0,0), x(0,1) ); out(1,1) = 0.0; break; default: std::cout << "deri: not implemented\n"; break; } break; default: std::cout << "deri: not implemented\n"; break; } } }