#include "lmem.h" #include "lobject.h" #include "lstate.h" #include "lstring.h" void luaS_freeall (lua_State *L) { lua_assert(G(L)->strt.nuse==0); luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size, TString *); } void luaS_resize (lua_State *L, int newsize) { GCObject **newhash = luaM_newvector(L, newsize, GCObject *); stringtable *tb = &G(L)->strt; int i; for (i=0; i<newsize; i++) newhash[i] = NULL; /* rehash */ for (i=0; i<tb->size; i++) { GCObject *p = tb->hash[i]; while (p) { /* for each node in the list */ GCObject *next = p->gch.next; /* save next */ lu_hash h = gcotots(p)->tsv.hash; int h1 = lmod(h, newsize); /* new position */ lua_assert(cast(int, h%newsize) == lmod(h, newsize)); p->gch.next = newhash[h1]; /* chain it */ newhash[h1] = p; p = next; } }
#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 #if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE ASJ( jmp, 5, f) ASL(4) // non-SSE2 #endif AS2( add [AS_REG_7+0*4], ecx) // A AS2( add [AS_REG_7+4*4], edi) // E AS2( mov eax, B(0)) AS2( mov ebx, C(0)) AS2( mov ecx, D(0)) AS2( add [AS_REG_7+1*4], eax) AS2( add [AS_REG_7+2*4], ebx) AS2( add [AS_REG_7+3*4], ecx) AS2( mov eax, F(0)) AS2( mov ebx, G(0)) AS2( mov ecx, H(0)) AS2( add [AS_REG_7+5*4], eax) AS2( add [AS_REG_7+6*4], ebx) AS2( add [AS_REG_7+7*4], ecx) AS2( mov ecx, AS_REG_7d) AS2( cmp WORD_REG(dx), DATA_END) ASJ( jb, 2, b) #if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE ASL(5) #endif #endif AS_POP_IF86(sp) AS_POP_IF86(bp) #if !defined(_MSC_VER) || (_MSC_VER < 1400)
LUA_API void lua_close (lua_State *L) { L = G(L)->mainthread; /* only the main thread can be closed */ lua_lock(L); close_state(L); }
void luaC_sweep (lua_State *L, int all) { if (all) all = 256; /* larger than any mark */ sweeplist(L, &G(L)->rootudata, all); sweepstrings(L, all); sweeplist(L, &G(L)->rootgc, all); }
static int Kou_Ap_Am(double S0,NumFunc_1 *P,double T,double r,double divid,double sigma,double lambda,double lambdap,double lambdam,double p,double *ptPrice,double *ptDelta) { double K=P->Par[0].Val.V_DOUBLE; long double x[12]={sigma,lambda,p,lambdap,lambdam,S0,K,r,T,divid,0,0},temp,eps1=1e-6,un=1.0L,q=1-p; if ((P->Compute)==&Call) { //On utilise la dualité (Farjado & Mordecki) temp=x[7]; x[7]=x[9]; x[9]=temp; temp=x[2]; x[2]=(1-x[2])*x[4]/(1+x[4]); q=temp*x[3]/(x[3]-1); temp=x[3]; x[3]=x[4]+1; x[4]=temp-1; temp=x[5]; x[5]=x[6]; x[6]=temp; } long double ksi=x[2]*x[3]/(x[3]-1)+q*x[4]/(x[4]+1)-1, nu=(x[7]-x[9])-sigma*sigma/2-lambda*ksi, eps=1e-16; long double y[8]={nu,sigma,lambda,x[2],x[3],x[4],x[7]/(1-exp(-x[7]*T)),q}, beta3,beta4; KCE G(y); dichotomie solG(G,-x[4]+eps,-eps,eps1); beta3=solG.racine()[0]; newton solG1(G,beta3,eps); beta3=-solG1.racine()[0]; long double x0=-x[4]-10; while(G.f(x0)<0) x0=x0-10; dichotomie solG2(G,x0,-x[4]-eps,eps1); beta4=solG2.racine()[0]; newton solG3(G,beta4,eps); beta4=-solG3.racine()[0]; long double C=beta3*beta4*(1+x[4]); long double D=x[4]*(1+beta3)*(1+beta4); x[10]=C; x[11]=D; //for(i=0;i<12;i++) //cout << x[i] <<endl; amer_eq f(x); long double x1, x2; x1=x[6]/2; x2=x[6]/(2+eps); if(f.f(x1)*f.f(x2)>0) { int i=1; long double temp; if(f.f(x1)>0) { x2=(1+un*i/100.)*x[6]/2.; while(f.f(x2)>0) { temp=x2; x2=(1+un*i/100.)*x[6]; x1=temp; i++; } } else { x1=(1+eps-un*i/100.)*x[6]/(2.+eps); while(f.f(x1)<0) { temp=x1; x1=(1+eps-un*i/100.)*x[6]/(2.+eps); x2=temp; i++; } } } dichotomie solf(f,x1,x2,1e-1); long double v0=solf.racine()[0]; long double EuP, dEuP, EuP0, dEuP0, cst1, cst2,dcst1,dcst2, cst11, cst21, dcst11, dcst21; long double z[8]; z[0]=nu; z[1]=sigma; z[2]=lambda; z[3]=x[2]; z[4]=x[3]; z[5]=x[4]; z[6]=log(x[6]/v0); z[7]=T; cst1=psiVN(z); dcst1=dpsiVN(z)/x[6]; z[6]=log(x[6]/x[5]); cst11=psiVN(z); if((P->Compute)==&Put) dcst11=-dpsiVN(z)/x[5]; else dcst11=dpsiVN(z)/x[6]; z[0]=(x[7]-x[9])+sigma*sigma/2-lambda*ksi; z[2]=lambda*(ksi+1); z[3]=x[2]*x[3]/((1+ksi)*(x[3]-1)); z[4]=x[3]-1; z[5]=x[4]+1; cst21=psiVN(z); if((P->Compute)==&Put) dcst21=-dpsiVN(z)/x[5]; else dcst21=dpsiVN(z)/x[6]; z[6]=log(x[6]/v0); cst2=psiVN(z); dcst2=dpsiVN(z)/x[6]; EuP0=x[6]*exp(-x[7]*T)*(1-cst1)-v0*exp(-x[9]*T)*(1-cst2); dEuP0=exp(-x[7]*T)*(1-cst1)-x[6]*exp(-x[7]*T)*dcst1+v0*exp(-x[9]*T)*dcst2; EuP=x[6]*exp(-x[7]*T)*(1-cst11)-x[5]*exp(-x[9]*T)*(1-cst21); if((P->Compute)==&Put) dEuP=-x[6]*exp(-x[7]*T)*dcst11-exp(-x[9]*T)*(1-cst21)+x[5]*exp(-x[9]*T)*dcst21; else dEuP=-x[6]*exp(-x[7]*T)*dcst11+exp(-x[7]*T)*(1-cst11)+x[5]*exp(-x[9]*T)*dcst21; long double proba=1.0L-cst1, A, B,dA,dB; A=powl(v0,beta3)*(beta4*x[6]-(1+beta4)*(v0*expl(-x[9]*T)+EuP0)+x[6]*expl(-x[7]*T)*proba)/(beta4-beta3); B=powl(v0,beta4)*(beta3*x[6]-(1+beta3)*(v0*expl(-x[9]*T)+EuP0)+x[6]*expl(-x[7]*T)*proba)/(beta3-beta4); dA=powl(v0,beta3)*(beta4-(1+beta4)*dEuP0+exp(-x[7]*T)*(1-cst1)-x[6]*exp(-x[7]*T)*dcst1)/(beta4-beta3); dB=powl(v0,beta4)*(beta3-(1+beta3)*dEuP0+exp(-x[7]*T)*(1-cst1)-x[6]*exp(-x[7]*T)*dcst1)/(beta3-beta4); if(x[7]!=0) { if(x[5]>=v0) *ptPrice=EuP+A*powl(x[5],-beta3)+B*powl(x[5],-beta4); else *ptPrice=x[6]-x[5]*exp(-x[9]*T); } else { *ptPrice=EuP; } if(x[7]!=0) { if(x[5]>=v0) { if ((P->Compute)==&Put) *ptDelta=dEuP-beta3*A*powl(x[5],-beta3-1)-beta4*B*powl(x[5],-beta4-1); else *ptDelta=dEuP+dA*powl(x[5],-beta3)+dB*powl(x[5],-beta4); } else { if ((P->Compute)==&Put) *ptDelta=-exp(-x[9]*T)+exp(-x[7]*T)*(1-cst11); else *ptDelta=1.0; } } else { *ptDelta=dEuP; } return OK; }
/*p.d.f of Chi-square*/ double chisq(int df, double x) { return ( pow(x/2, (df-2)/2.)*exp(-x/2)/(2*G(df/2.)) ); }
void Thread::init(STATE) { GO(thread).set(ontology::new_class(state, "Thread", G(object))); G(thread)->set_object_type(state, Thread::type); }
void Executable::init(STATE) { GO(executable).set(ontology::new_class(state, "Executable", G(object), G(rubinius))); G(executable)->set_object_type(state, ExecutableType); G(executable)->name(state, state->symbol("Rubinius::Executable")); }
Spectrum ConnectBDPT(const Scene &scene, Vertex *lightVertices, Vertex *cameraVertices, int s, int t, const Distribution1D &lightDistr, const Camera &camera, Sampler &sampler, Point2f *pRaster, Float *misWeightPtr) { Spectrum L(0.f); // Ignore invalid connections related to infinite area lights if (t > 1 && s != 0 && cameraVertices[t - 1].type == VertexType::Light) return Spectrum(0.f); // Perform connection and write contribution to _L_ Vertex sampled; if (s == 0) { // Interpret the camera subpath as a complete path const Vertex &pt = cameraVertices[t - 1]; if (pt.IsLight()) L = pt.Le(scene, cameraVertices[t - 2]) * pt.beta; } else if (t == 1) { // Sample a point on the camera and connect it to the light subpath const Vertex &qs = lightVertices[s - 1]; if (qs.IsConnectible()) { VisibilityTester vis; Vector3f wi; Float pdf; Spectrum Wi = camera.Sample_Wi(qs.GetInteraction(), sampler.Get2D(), &wi, &pdf, pRaster, &vis); if (pdf > 0 && !Wi.IsBlack()) { // Initialize dynamically sampled vertex and _L_ for $t=1$ case sampled = Vertex::CreateCamera(&camera, vis.P1(), Wi / pdf); L = qs.beta * qs.f(sampled) * vis.Tr(scene, sampler) * sampled.beta; if (qs.IsOnSurface()) L *= AbsDot(wi, qs.ns()); } } } else if (s == 1) { // Sample a point on a light and connect it to the camera subpath const Vertex &pt = cameraVertices[t - 1]; if (pt.IsConnectible()) { Float lightPdf; VisibilityTester vis; Vector3f wi; Float pdf; int lightNum = lightDistr.SampleDiscrete(sampler.Get1D(), &lightPdf); const std::shared_ptr<Light> &light = scene.lights[lightNum]; Spectrum lightWeight = light->Sample_Li( pt.GetInteraction(), sampler.Get2D(), &wi, &pdf, &vis); if (pdf > 0 && !lightWeight.IsBlack()) { EndpointInteraction ei(vis.P1(), light.get()); sampled = Vertex::CreateLight(ei, lightWeight / (pdf * lightPdf), 0); sampled.pdfFwd = sampled.PdfLightOrigin(scene, pt, lightDistr); L = pt.beta * pt.f(sampled) * vis.Tr(scene, sampler) * sampled.beta; if (pt.IsOnSurface()) L *= AbsDot(wi, pt.ns()); } } } else { // Handle all other bidirectional connection cases const Vertex &qs = lightVertices[s - 1], &pt = cameraVertices[t - 1]; if (qs.IsConnectible() && pt.IsConnectible()) { L = qs.beta * qs.f(pt) * pt.f(qs) * pt.beta; if (!L.IsBlack()) L *= G(scene, sampler, qs, pt); } } // Compute MIS weight for connection strategy Float misWeight = L.IsBlack() ? 0.f : MISWeight(scene, lightVertices, cameraVertices, sampled, s, t, lightDistr); L *= misWeight; if (misWeightPtr) *misWeightPtr = misWeight; return L; }
void Dir::init(STATE) { GO(dir).set(ontology::new_class(state, "Dir", G(object))); G(dir)->set_object_type(state, DirType); }
int main(int , char* []) { typedef boost::adjacency_list< boost::mapS, boost::vecS, boost::bidirectionalS, boost::property<boost::vertex_color_t, boost::default_color_type, boost::property<boost::vertex_degree_t, int, boost::property<boost::vertex_in_degree_t, int, boost::property<boost::vertex_out_degree_t, int> > > > > Graph; Graph G(5); boost::add_edge(0, 2, G); boost::add_edge(1, 1, G); boost::add_edge(1, 3, G); boost::add_edge(1, 4, G); boost::add_edge(2, 1, G); boost::add_edge(2, 3, G); boost::add_edge(2, 4, G); boost::add_edge(3, 1, G); boost::add_edge(3, 4, G); boost::add_edge(4, 0, G); boost::add_edge(4, 1, G); typedef Graph::vertex_descriptor Vertex; Graph G_copy(5); // Array to store predecessor (parent) of each vertex. This will be // used as a Decorator (actually, its iterator will be). std::vector<Vertex> p(boost::num_vertices(G)); // VC++ version of std::vector has no ::pointer, so // I use ::value_type* instead. typedef std::vector<Vertex>::value_type* Piter; // Array to store distances from the source to each vertex . We use // a built-in array here just for variety. This will also be used as // a Decorator. boost::graph_traits<Graph>::vertices_size_type d[5]; std::fill_n(d, 5, 0); // The source vertex Vertex s = *(boost::vertices(G).first); p[s] = s; boost::breadth_first_search (G, s, boost::visitor(boost::make_bfs_visitor (std::make_pair(boost::record_distances(d, boost::on_tree_edge()), std::make_pair (boost::record_predecessors(&p[0], boost::on_tree_edge()), copy_graph(G_copy, boost::on_examine_edge())))) )); boost::print_graph(G); boost::print_graph(G_copy); if (boost::num_vertices(G) < 11) { std::cout << "distances: "; #ifdef BOOST_OLD_STREAM_ITERATORS std::copy(d, d + 5, std::ostream_iterator<int, char>(std::cout, " ")); #else std::copy(d, d + 5, std::ostream_iterator<int>(std::cout, " ")); #endif std::cout << std::endl; std::for_each(boost::vertices(G).first, boost::vertices(G).second, print_parent<Piter>(&p[0])); } return 0; }
void request_raw_connection(Promise<std::unique_ptr<mtproto::RawConnection>> promise) override { send_closure(G()->connection_creator(), &ConnectionCreator::request_raw_connection, dc_id_, allow_media_only_, is_media_, std::move(promise), hash_); }
int video_thread(SceSize args, void *argp) { // Pixel coordinates: first = first luminant pixel to breach threshhold, last = ..., mid = ... Coord first, last, mid; int bufsize; int threshold = 200; // Luminance threshold. int showvideo = 0; // Show the actual video input? 0: No, 1: Yes // Camera buffers. PspUsbCamSetupVideoParam videoparam; static u8 buffer[MAX_STILL_IMAGE_SIZE] __attribute__((aligned(64))); static u8 work[68*1024] __attribute__((aligned(64))); static u32 framebuffer[480*272] __attribute__((aligned(64))); // Startup cursor position. cursor.x = 237, cursor.y = 50; old.x = 237, old.y = 50; // Setup the screenmap size and position. screenmap.x = 20; screenmap.y = 200; screenmap.w = 60; screenmap.h = 60; screenmap.gridcolor = 0xFFC09090; screenmap.fillcolor = 0xFFF0F0F0; screenmap.selcolor = 0xFFC0FFFF; // Create a start button. Button btnStart; btnStart.x = 420; btnStart.y = 250; btnStart.w = 50; btnStart.h = 12; btnStart.fillcolor = 0xFF00FFFF; btnStart.textcolor = 0xFF000000; btnStart.bordercolor = 0xFF000000; btnStart.shadowcolor = 0xFF888888; btnStart.bordersize = 1; btnStart.borderbevel = 0; btnStart.shadowsize = 0; btnStart.shadowdistance = 0; strcpy(btnStart.text, "Start"); strcpy(btnStart.name, "btnStart"); // Wait for camera to be connected. while (!connected) { clearScreen(0xFFF0F0F0); printTextScreenCenter(132, "Please connect the camera and press any button.", 0xFF009900); flipScreen(); sceDisplayWaitVblankStart(); sceKernelDelayThread(20000); } // Load the camera modules and start the decoder. if (LoadModules() < 0) sceKernelSleepThread(); if (StartUsb() < 0) sceKernelSleepThread(); if (sceUsbActivate(PSP_USBCAM_PID) < 0) sceKernelSleepThread(); if (InitJpegDecoder() < 0) sceKernelSleepThread(); while (1) { if ((sceUsbGetState() & 0xF) == PSP_USB_CONNECTION_ESTABLISHED) break; sceKernelDelayThread(50000); } //Setup video parameters and start video capture. memset(&videoparam, 0, sizeof(videoparam)); videoparam.size = sizeof(videoparam); videoparam.resolution = PSP_USBCAM_RESOLUTION_480_272; videoparam.framerate = PSP_USBCAM_FRAMERATE_30_FPS; videoparam.wb = PSP_USBCAM_WB_INCANDESCENT; videoparam.saturation = 125; videoparam.brightness = 100; videoparam.contrast = 64; videoparam.sharpness = 0; videoparam.effectmode = PSP_USBCAM_EFFECTMODE_NORMAL; videoparam.framesize = MAX_VIDEO_FRAME_SIZE; videoparam.evlevel = PSP_USBCAM_EVLEVEL_0_0; if (sceUsbCamSetupVideo(&videoparam, work, sizeof(work)) < 0) sceKernelExitDeleteThread(0); sceUsbCamAutoImageReverseSW(1); if (sceUsbCamStartVideo() < 0) sceKernelExitDeleteThread(0); while (running) { int i, j, lum = 0, tracking = 0; first.x = 0; first.y = 0; last.x = 0; last.y = 0; mid.x = old.x; mid.y = old.y; clearScreen(0xFFFFFFFF); // Capture the camera image into the framebuffer. bufsize = sceUsbCamReadVideoFrameBlocking(buffer, MAX_VIDEO_FRAME_SIZE); if (bufsize > 0) sceJpegDecodeMJpeg(buffer, bufsize, framebuffer, 0); // Analyze the camera image. for (i = 0; i < 272; i++) { for (j = 0; j < 480; j++) { if (showvideo) putPixelScreen(framebuffer[i * CAM_LINE_SIZE + j], j, i); // Show video input. // Calculate luminance (brightness as perceived by the eye) and compare versus threshhold. lum = (299 * R(framebuffer[i * CAM_LINE_SIZE + j]) + 587 * G(framebuffer[i * CAM_LINE_SIZE + j]) + 114 * B(framebuffer[i * CAM_LINE_SIZE + j])) / 1000; if (lum > threshold) { tracking = 1; if (aligned) putPixelScreen(0xFF0000FF, j, i); if ((first.x == 0) || (j < first.x)) first.x = j; if ((first.y == 0) || (i < first.y)) first.y = i; if ((last.x == 0) || (j > last.x)) last.x = j; if ((last.y == 0) || (i > last.y)) last.y = i; } } } if (tracking) { // Calculate directional movement and determine cursor position. mid.x = first.x + (abs((last.x - first.x)) / 2); mid.y = first.y + (abs((last.y - first.y)) / 2); checkDirection(mid, old); switch (direction) { case 0: cursor.x = old.x; cursor.y = old.y; break; case 1: cursor.x = first.x; cursor.y = first.y + (abs((last.y - first.y)) / 2); break; case 2: cursor.x = first.x; cursor.y = first.y; break; case 3: cursor.x = first.x + (abs((last.x - first.x)) / 2); cursor.y = first.y; break; case 4: cursor.x = last.x; cursor.y = first.y; break; case 5: cursor.x = last.x; cursor.y = first.y + (abs((last.y - first.y)) / 2); break; case 6: cursor.x = last.x; cursor.y = last.y; break; case 7: cursor.x = first.x + (abs((last.x - first.x)) / 2); cursor.y = last.y; break; case 8: cursor.x = first.x; cursor.y = last.y; break; }; //Uncomment the following lines to draw 'directional' markers on screen. /*if ((abs(last.x - first.x) > 15) || (abs(last.y - first.y) > 15)) { if ((direction > 0) && (direction <= 4)) { drawLineScreen(first.x, first.y, last.x, last.y, 0xFFC0C0C0); } else { drawLineScreen(last.x, last.y, first.x, first.y, 0xFFC0C0C0); } switch (direction) { case 0: break; case 1: drawLineScreen(last.x, last.y + ((last.y - first.y) / 2), first.x, first.y + ((last.y - first.y) / 2), 0xFFC0C0C0); break; // W case 2: drawLineScreen(last.x, last.y, first.x, first.y, 0xFFC0C0C0); break; // NW case 3: drawLineScreen(first.x + ((last.x - first.x) / 2), last.y, first.x + ((last.x - first.x) / 2), first.y, 0xFFC0C0C0); break; // N case 4: drawLineScreen(first.x, last.y, last.x, first.y, 0xFFC0C0C0); break; // NE case 5: drawLineScreen(first.x, first.y + ((last.y - first.y) / 2), last.x, first.y + ((last.y - first.y) / 2), 0xFFC0C0C0); break; // E case 6: drawLineScreen(first.x, first.y, last.x, last.y, 0xFFC0C0C0); break; // SE case 7: drawLineScreen(first.x + ((last.x - first.x) / 2), first.y, first.x + ((last.x - first.x) / 2), last.y, 0xFFC0C0C0); break; // S case 8: drawLineScreen(last.x, first.y, first.x, last.y, 0xFFC0C0C0); break; // SW }; drawLineScreen((first.x > last.x) ? last.x : first.x, (first.y > last.y) ? last.y : first.y, (first.x < last.x) ? last.x : first.x, (first.y < last.y) ? last.y : first.y, 0xFFC0C0C0); } else { drawRectScreen(0xFFC0C0C0, first.x, first.y, last.x - first.x, last.y - first.y); }*/ } else { printTextScreenCenter(10, "Please return to the playing area.", 0xFF0000FF); if (lastdirection == 0) { cursor.x = old.x; cursor.y = old.y; } //if ((aligned) && (!menu) && (_gameState = GAME_RUNNING)) HandlePauseGame(); } if (!aligned) { showvideo = 1; // Alignment Screen: wait for camera to be aligned to the playing area. printTextScreenCenter(126, "Please align the camera to the playing area.", 0xFFFFFFFF); printTextScreenCenter(136, "Drag the cursor to the \"Start\" button to continue.", 0xFFFFFFFF); if (checkCoordButton(cursor, btnStart)) { btnStart.fillcolor = 0xFF00FF00; aligned = 1; menu = 1; } drawButtonScreen(btnStart); if (aligned) { btnStart.fillcolor = 0xFF00FFFF; btnStart.x = 240 - (btnStart.w / 2); btnStart.y = 200; } } else if (menu) { showvideo = 0; // Menu Screen: show a splash, logo, menu, etc. printTextScreenCenter(126, "eyePSP Pong", 0xFF009900); printTextScreenCenter(136, "Please press the \"Start\" button to continue.", 0xFFFF0000); if (checkCoordButton(cursor, btnStart)) { btnStart.fillcolor = 0xFFC0FFC0; menu = 0; } drawButtonScreen(btnStart); } else { // Draw any game objects here. if (_gameState == GAME_PAUSED) { printTextScreenCenter(100, "Game Paused", COLOR_RED); if (tracking) _gameState = GAME_RUNNING; } else if (_gameState == GAME_RUNNING) { DrawMainText(); // Draw main graphics and supporting text to the screen. DrawPaddle(&_paddle); // Draws the paddle to the screen } else if (_gameState == GAME_CONTINUE) { char sbuffer[50]; sprintf(sbuffer, "%d Ball%s Remaining...", _resBalls, (_resBalls == 1) ? "" : "s"); printTextScreenCenter(100, sbuffer, 0xFF000088); if (checkCoordButton(cursor, btnStart)) { btnStart.fillcolor = 0xFFC0FFC0; _gameState = GAME_RUNNING; } drawButtonScreen(btnStart); } else if (_gameState == GAME_OVER) { // Draws game over graphics and waits for user to continue DrawGameOverMenu(); if (checkCoordButton(cursor, btnStart)) { btnStart.fillcolor = 0xFFC0FFC0; _gameState = GAME_RUNNING; } drawButtonScreen(btnStart); } } // Draw cursor (within boundaries) . if (tracking) { for (i = cursor.y - 5; i <= cursor.y + 5; i++) { if ((i > 0) && (i < 272)) putPixelScreen(!tracking ? 0xFF0000FF : 0xFF009900, cursor.x, i); } // y-axis for (j = cursor.x - 5; j <= cursor.x + 5; j++) { if ((j > 0) && (j < 480)) putPixelScreen(!tracking ? 0xFF0000FF : 0xFF009900, j, cursor.y); } // x-axis } old.x = cursor.x; old.y = cursor.y; lastdirection = direction; flipScreen(); sceDisplayWaitVblankStart(); sceKernelDelayThread(2000); } sceKernelExitDeleteThread(0); return 0; }
void luaS_freeall (lua_State *L) { lua_assert(G(L)->strt.nuse==0); luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size, TString *); }
main() { int i,k,j; int nbArcs =0; double eval=0; double nimp =0; Graphe G(72000,8760,0,0,nimp); // cout<< "sommet créé"<<endl; G.genererArcs(); int nbSommets =G.getNbSommet(); cout<< "Arbre créé de " <<nbSommets<<" sommets \n"; // nombre arcs: //for(i=0; i<G.getNbSommet(); i++) /* { nbArcs= nbArcs + G.getListeSommets()[i].getNbSuccesseurs(); } cout <<"et de " << nbArcs << " arcs \n";*/ //Algorithme de Bellman //G.getSommet(0)->setPoids(0); //cout <<G.getSommet(0)->getPoids() << " le poids \n" ; /*for(i=0; i<nbSommets-1; i++) { for(j=1; j<nbSommets; j++) { Sommet* s =G.getSommet(j); double poids= s->getPoids(); for(k=0;k<s->getNbSuccesseurs();k++) { //on regarde tt les ars kj double poidsK = s->getPredecesseurs(k)->getPoids(); double valArc = s->getValeurArc(k); if( poidsK + valArc>=poids) { s->setPred(k); //cout << s->getPredecesseurs(k)->getPoids() <<"\n\n"; s->setPoids(poidsK + valArc); poids= s->getPoids(); } } } } //Calcul valeur : Sommet s=G.getListeSommets()[nbSommets-1]; //cout <<"debut evaluation \n"; for(i=0;i<168;i++) { //cout << "heure :" << s.getHeure()<<":\n"; int pred = s.getPred(); eval= eval+ s.getValeurArc(pred); s = *(s.getPredecesseurs(pred)); }*/ eval=G.plusCourtChemin(); cout << eval << "\n"; }
void test_allocate() { Class* sub = ontology::new_class(state, "ArraySub", G(array), 0); Array* ary = Array::allocate(state, sub); TS_ASSERT_EQUALS(ary->klass(), sub); }
void init_main_0(const unsigned short & A, const unsigned short & m_max, const unsigned short & K_min, const unsigned short & K_max, const unsigned short & S_tot, const Init_Corpi_LS & Corpi, const bool & modo_clust){ unsigned short ordine = 200; unsigned short N = A - 1; unsigned short P = 2; std::string s, s_0, s_0_p, s_0_d, s_1 , s_l, s_misurabili; std::string s_ext_txt = ".txt"; std::string s_ext_dat = ".dat"; std::string s_ext_p = "_p"; std::string s_ext_d = "_d"; std::string s_completa = "_tot"; std::string s_cluster,s_masse; std::vector <unsigned short> clus; if (modo_clust && A==4) { clus.push_back(2); clus.push_back(2); s_cluster = "_Modo_H"; } else { clus.push_back(A); s_cluster = ""; } if(Corpi.M_u()){ s_masse = "_M_u"; } else { s_masse = ""; } { s = "N_HH_" + scrivi(A) + "_" + Corpi.scrivi_corpi() + "__m_max_" + scrivi(m_max) + "_K_max_[" + scrivi(K_min) + "-" + scrivi(K_max) + "]_S_" + scrivi(S_tot); s_0 = "N_HH_tab_" + scrivi(A) + "_" + Corpi.scrivi_corpi() + "__m_max_" + scrivi(m_max) + "_K_max_[" + scrivi(K_min) + "-" + scrivi(K_max) + "]_S_" + scrivi(S_tot); s_0_p = "N_HH_tab_" + scrivi(A) + "_" + Corpi.scrivi_corpi() + "__m_max_" + scrivi(m_max) + "_K_max_[" + scrivi(K_min) + "-" + scrivi(K_max) + "]_S_" + scrivi(S_tot); s_0_d = "N_HH_tab_" + scrivi(A) + "_" + Corpi.scrivi_corpi() + "__m_max_" + scrivi(m_max) + "_K_max_[" + scrivi(K_min) + "-" + scrivi(K_max) + "]_S_" + scrivi(S_tot); s_1 = "N_HH_" + scrivi(A) + "_" + Corpi.scrivi_corpi() + "__m_max_" + scrivi(m_max) + "_K_max_[" + scrivi(K_min) + "-" + scrivi(K_max) + "]_S_" + scrivi(S_tot); s_l = "N_HH_Livelli_E_0_" + scrivi(A) + "_" + Corpi.scrivi_corpi() + "__m_max_" + scrivi(m_max) + "_K_max_[" + scrivi(K_min) + "-" + scrivi(K_max) + "]_S_" + scrivi(S_tot); s_misurabili = "N_HH_Misurabili_" + scrivi(A) + "_" + Corpi.scrivi_corpi() + "__m_max_" + scrivi(m_max) + "_K_max_[" + scrivi(K_min) + "-" + scrivi(K_max) + "]_S_" + scrivi(S_tot); } { s += s_cluster + s_masse + s_ext_dat; s_0 += s_cluster + s_masse + s_ext_txt; s_0_p += s_cluster + s_masse + s_ext_p + s_ext_txt; s_0_d += s_cluster + s_masse + s_ext_d + s_ext_txt; s_1 += s_cluster + s_masse + s_ext_txt; s_l += s_cluster + s_masse + s_ext_txt; s_misurabili += s_cluster + s_masse + s_ext_txt; } std::string s_vec,s_vec_temp,s_vec_temp_c,s_vec_temp_1,s_vec_temp_c_1; { s_vec = "./lista_vettori/Vec_"+ scrivi(A) + "_" + Corpi.scrivi_corpi() + "__m_max_" + scrivi(m_max) + "_S_" + scrivi(S_tot); //s_vec += s_cluster /*+ s_masse*/; } std::fstream myfile_vec; myfile_vec.precision(10); std::fstream myfile_vec_1; myfile_vec_1.precision(10); bool scrivi_vettore,scrivi_vettore_p,scrivi_vettore_c,scrivi_vettore_pc; std::ofstream myfile; std::ofstream myfile_1; std::ofstream myfile_tabella; std::ofstream myfile_tabella_p; std::ofstream myfile_tabella_d; std::ofstream myfile_livelli; std::ofstream myfile_misurabili; { myfile.open (s.c_str()); myfile_1.open (s_1.c_str()); myfile_tabella.open (s_0.c_str()); myfile_tabella_p.open (s_0_p.c_str()); myfile_tabella_d.open (s_0_d.c_str()); myfile_livelli.open (s_l.c_str()); myfile_misurabili.open (s_misurabili.c_str()); myfile.precision(std::numeric_limits<long double>::digits10); myfile_1.precision(std::numeric_limits<long double>::digits10); myfile_tabella.precision(10); myfile_tabella_p.precision(10); myfile_tabella_d.precision(10); myfile_livelli.precision(10); myfile_misurabili.precision(10); std::cerr.precision(10); std::cout.precision(10); } { myfile_1 << "Binding Energy per " << A << " nucleoni : "; myfile_tabella << "Binding Energy per " << A << " nucleoni : "; myfile_tabella_p << "Binding Energy per " << A << " nucleoni : "; myfile_tabella_d << "Binding Energy per " << A << " nucleoni : "; myfile_livelli << "Primi Livelli Energetici per " << A << " nucleoni : "; for (short i = 0; i<A; ++i) { myfile_1<< Corpi.CORPI(i)<< " "; myfile_tabella<< Corpi.CORPI(i)<< " "; myfile_tabella_p<< Corpi.CORPI(i)<< " "; myfile_tabella_d<< Corpi.CORPI(i)<< " "; myfile_livelli<< Corpi.CORPI(i)<< " "; } myfile_1 << std::endl; myfile_tabella << std::endl; myfile_tabella_p << std::endl; myfile_tabella_d << std::endl; myfile_livelli << std::endl; myfile_1 << " m_max = " << m_max << " K_max = " << K_max << " S_tot = " << S_tot <<"/2" << std::endl; myfile_tabella << " m_max = " << m_max << " K_max = " << K_max << " S_tot = " << S_tot <<"/2"<< std::endl; myfile_tabella_p << " m_max = " << m_max << " K_max = " << K_max << " S_tot = " << S_tot <<"/2"<< std::endl; myfile_tabella_d << " m_max = " << m_max << " K_max = " << K_max << " S_tot = " << S_tot <<"/2"<< std::endl; myfile_livelli << " m_max = " << m_max << " K_max = " << K_max << " S_tot = " << S_tot <<"/2"<< std::endl; } if(Corpi.M_u() && A==3) { myfile_tabella << "K_max N_hh Parita' E E_ppp E_ppn E_nnp E_nnn E_c" << std::endl; myfile_tabella_p << "K_max N_hh Parita' E E_ppp E_ppn E_nnp E_nnn E_c" << std::endl; myfile_tabella_d << "K_max N_hh Parita' E E_ppp E_ppn E_nnp E_nnn E_c" << std::endl; } else{ myfile_tabella << "K_max N_hh Parita' E E_c" << std::endl; myfile_tabella_p << "K_max N_hh Parita' E E_c" << std::endl; myfile_tabella_d << "K_max N_hh Parita' E E_c" << std::endl; } boost::timer t6; unsigned short incremento = 2; Gauss_Laguerre G(ordine); HyperInt HI(ordine/2); Integrazioni_3_P INT_3P(N); Accoppiamenti_Spinoriali_S SS (Corpi.D_s(),clus,S_tot,Corpi.D_Z_min()); Accoppiamenti_Iperangolari_K_max KK (N, 0, 0, K_min,P,clus,0); // Energia_radiale_spin ER ( SS, N, G, HI, K_min, m_max, Corpi.C(), Corpi.M(), Corpi.M_R(),clus); // Energia_spin EN ( HI, &INT_3P, ER, KK ); //lancsoz VETTORI mygen(m_max + 1); VETTORI mygen_c(m_max + 1); VETTORI mygen1(m_max + 1); VETTORI mygen1_c(m_max + 1); VETTORI mygen2(m_max + 1); VETTORI mygen2_c(m_max + 1); typedef boost::lagged_fibonacci607 Gen_i; typedef ietl::vectorspace<VETTORI> Vecspace; Gen_i mygen_i; bool primopasso = true; bool primopasso1 = true; bool primopasso2 = true; bool primopasso_c = true; bool primopasso1_c = true; bool primopasso2_c = true; tipo_matrici rel_tol = 500000000*std::numeric_limits<double>::epsilon(); tipo_matrici abs_tol = 1000000*std::pow(std::numeric_limits<double>::epsilon(),2./3); int n_lowest_eigenval = 1; //lancsoz for (unsigned short K_max_temp = K_min; K_max_temp <= K_max; K_max_temp+=incremento) { //if (K_max_temp == 30) incremento = 10; boost::timer t; { myfile_1 << std::endl; myfile_1 << std::endl; myfile_1 << "**************************************************************************"; myfile_1 << std::endl; myfile_1 << " K_max_temp = " << K_max_temp << std::endl; std::cerr << " K_max_temp = " << K_max_temp << std::endl; } { myfile_livelli << std::endl; myfile_livelli << std::endl; myfile_livelli << "**************************************************************************"; myfile_livelli << std::endl; myfile_livelli << " K_max_temp = " << K_max_temp << std::endl; } KK.PLUS(K_max_temp - KK.K_M(),P,clus); Accoppiamenti_Parita BASE(KK,SS,m_max + 1); { myfile_1 << " N_hh = " << KK.D() << std::endl; std::cerr << " N_hh = " << KK.D() << std::endl; myfile_1 << "BASE.D_h()" << BASE.D_h() << std::endl; std::cerr << "Accoppiamenti_Iperangolari_K_max T = " << t.elapsed() << std::endl; myfile << "Accoppiamenti_Iperangolari_K_max T = " << t.elapsed() << std::endl; for (unsigned long i = 0; i < KK.D() ; ++i){ myfile << i+1 << " K = " << KK.k(i) << " n = [ "; for(unsigned short j = 0; j < KK.n(i).size() ; ++j){ myfile << KK.n(i)[j]; myfile << " "; } myfile << "] l = [ "; for(unsigned short j = 0; j < KK.l(i).size() ; ++j){ myfile << KK.l(i)[j]; myfile << " "; } myfile << "] L = [ "; for(unsigned short j = 0; j < KK.L(i).size() ; ++j){ myfile << KK.L(i)[j]; myfile << " "; } myfile << "]"; myfile << " parita = [ "; for(unsigned short j = 0; j < KK.P_l(i).size() ; ++j){ myfile << KK.P_l(i)[j]; myfile << " "; } myfile << "] somma quadra dei coefficienti dello sviluppo = "; myfile << quad_sum(KK.cm(i)); myfile << std::endl; } myfile << "Dimensione della base = " << KK.D() << " combinazioni." << std::endl; for (unsigned long i = 0; i < SS.D() ; ++i){ myfile << i+1 << " S = [ "; for(unsigned short j = 0; j < SS.D_S(i).size() ; ++j){ myfile << SS.D_S(i)[j]; myfile << " "; } myfile << "] S_z = [ "; myfile << SS.D_Z(i); myfile << " "; myfile << "]"; myfile << " parita = [ "; for(unsigned short j = 0; j < SS.P_S(i).size() ; ++j){ myfile << SS.P_S(i)[j]; myfile << " "; } myfile << "] somma quadra dei coefficienti dello sviluppo = "; myfile << quad_sum(SS.cm(i)); myfile << std::endl; } myfile << "Dimensione della base - SPIN = " << SS.D() << " combinazioni." << std::endl; } boost::timer t1; { std::cerr << "Energia T = " << t1.elapsed() << std::endl; myfile << "Energia T = " << t1.elapsed() << std::endl; } int max_iter = 5*BASE.D(); myfile_tabella_p << K_max_temp << " "; myfile_tabella_d << K_max_temp << " "; myfile_tabella_p << BASE.D_h_p() << std::endl; myfile_tabella_d << BASE.D_h_d() << std::endl; } std::cerr << "Esecuzione T = " << t6.elapsed() << std::endl; myfile << "Esecuzione T = " << t6.elapsed() << std::endl; myfile.close(); myfile_1.close(); myfile_tabella.close(); myfile_tabella_p.close(); myfile_tabella_d.close(); myfile_livelli.close(); myfile_misurabili.close(); }
void Time::init(STATE) { GO(time_class).set(ontology::new_class(state, "Time", G(object))); G(time_class)->set_object_type(state, TimeType); }
/*p.d.f of Poisson distribution*/ double Poisson(double lambda, int k) { if(k==0) return exp(-lambda); return exp(-lambda)*pow(lambda, k)/G(k+1); }
void gpio_enable(int gpio) { gpio_writel(gpio, 1 << G(gpio), DMW96_GPIO_EN_SET); }
static void sweepstrings (lua_State *L, int all) { int i; for (i=0; i<G(L)->strt.size; i++) { /* for each list */ G(L)->strt.nuse -= sweeplist(L, &G(L)->strt.hash[i], all); } }
void gpio_disable(int gpio) { gpio_writel(gpio, 1 << G(gpio), DMW96_GPIO_EN_CLR); }
void luaC_link (lua_State *L, GCObject *o, lu_byte tt) { o->gch.next = G(L)->rootgc; G(L)->rootgc = o; o->gch.marked = 0; o->gch.tt = tt; }
void gpio_set_value(int gpio, int value) { int reg = value ? DMW96_GPIO_DATA_SET : DMW96_GPIO_DATA_CLR; gpio_writel(gpio, 1 << G(gpio), reg); }
LUA_API const lua_Number *lua_version (lua_State *L) { static const lua_Number version = LUA_VERSION_NUM; if (L == NULL) return &version; else return G(L)->version; }
void gpio_direction_output(int gpio, int value) { gpio_writel(gpio, 1 << G(gpio), DMW96_GPIO_DIR_OUT); gpio_set_value(gpio, value); }
void VariableScope::init(STATE) { GO(variable_scope).set(ontology::new_class(state, "VariableScope", G(object), G(rubinius))); G(variable_scope)->set_object_type(state, VariableScopeType); }
#define Fx(n) (int)((FSCALE<<(n-1))*1.68179) /* 2^(9/12) */ #define G(n) (int)((FSCALE<<(n-1))*1.78180) /* 2^(10/12) */ #define Gx(n) (int)((FSCALE<<(n-1))*1.88775) /* 2^(11/12) */ #define A(n) (int)((FSCALE<<n)) /* A */ #define Ax(n) (int)((FSCALE<<n)*1.05946) /* 2^(1/12) */ #define B(n) (int)((FSCALE<<n)*1.12246) /* 2^(2/12) */ /* * Alarm sound? * It is unknown what this sound is like. Until somebody manages * trigger sound #1 of the Phoenix PCB sound chip I put just something * 'alarming' in here. */ static const int tune1[96*6] = { C(3), 0, 0, C(2), 0, 0, G(3), 0, 0, 0, 0, 0, C(3), 0, 0, 0, 0, 0, G(3), 0, 0, 0, 0, 0, C(3), 0, 0, 0, 0, 0, G(3), 0, 0, 0, 0, 0, C(3), 0, 0, 0, 0, 0, G(3), 0, 0, 0, 0, 0, C(3), 0, 0, C(4), 0, 0, G(3), 0, 0, 0, 0, 0, C(3), 0, 0, 0, 0, 0, G(3), 0, 0, 0, 0, 0, C(3), 0, 0, 0, 0, 0, G(3), 0, 0, 0, 0, 0, C(3), 0, 0, 0, 0, 0, G(3), 0, 0, 0, 0, 0, C(3), 0, 0, C(2), 0, 0,
/*! Computes the conserved Axial vector current using the \f[ {\cal O}_{5\mu} = i \overline{q} \gamma_5 \gamma_\mu q \f] all possible mometa are inserted */ void AlgNuc3pt::calc_Cons_Axial_Vector(int Nmom, ThreeMom* mom) { Gamma G5z(G5,Z); Nuc3ptCons AxialCurr(Complex(0.0,1.0),G5z); const int MaxNmom=50; if(Nmom>MaxNmom) ERR.General(cname,"calc_Cons_Vector","Nmom(%d)>MaxNmom(%d)",Nmom,MaxNmom); Nuc3ptCons *AxialCurrp[MaxNmom][4]; for(int ip(0);ip<Nmom;ip++) for (int i(X);i<4;i++){ DIR d = DIR(i); Gamma G5d(G5,d); AxialCurrp[ip][i] = new Nuc3ptCons(mom[ip],Complex(0.0,1.0),G5d); } Nuc3ptCons *VectCurrp[MaxNmom][4]; for(int ip(0);ip<Nmom;ip++) for (int i(X);i<4;i++){ DIR d = DIR(i) ; Gamma G(d); VectCurrp[ip][i] = new Nuc3ptCons(mom[ip],G) ; } for ( int n = 0; n < num_qprop; n++ ) { QPropW* quark = new QPropWGaussSrc(*q_prop[n]); AxialCurr.Calc3pt(*u_s_prop,*quark); for(int ip(0);ip<Nmom;ip++) for (int i(X);i<4;i++){ AxialCurrp[ip][i]->Calc3pt(*u_s_prop,*quark); VectCurrp[ip][i]->Calc3pt(*u_s_prop,*quark); } u_s_prop->DeleteQPropLs(); if(Nuc3pt_arg->DoConserved == 1) { char dummy[30]; d_s_prop->RestoreQPropLs_ftom(dummy); } AxialCurr.Calc3pt(*d_s_prop,*quark); for(int ip(0);ip<Nmom;ip++) for (int i(X);i<4;i++) { AxialCurrp[ip][i]->Calc3pt(*d_s_prop,*quark); VectCurrp[ip][i]->Calc3pt(*d_s_prop,*quark); } d_s_prop->DeleteQPropLs(); OpenFile(); AxialCurr.Print(fp) ; for(int ip(0);ip<Nmom;ip++) { for (int i(X);i<4;i++) { VectCurrp[ip][i]->Print(fp) ; } for (int i(X);i<4;i++) { AxialCurrp[ip][i]->Print(fp) ; } } CloseFile(); delete quark; } for(int ip(0);ip<Nmom;ip++) for (int i(X);i<4;i++) { delete AxialCurrp[ip][i]; delete VectCurrp[ip][i]; } }
void finalout() { INT c ; INT bbtop, bbbottom, bbleft, bbright ; /* dump the results of the placement to graphics file */ G( graphics_dump() ) ; G( TWsetMode(1) ) ; G( draw_the_data() ) ; G( TWsetMode(0) ) ; /* we known wire area at this point don't need to estimate */ turn_wireest_on(FALSE) ; /* let the user know which pins we couldn't place */ set_pin_verbosity( TRUE ) ; /* before channel graph generation and global routing let use tweak */ /* placement if desired */ if( doGraphicsG && wait_for_userG ){ G( TWmessage( "TimberWolfMC waiting for your response" ) ) ; G( process_graphics() ) ; } savewolf( TRUE ) ; /* for debug purposes force save to occur */ if( scale_dataG > 1 ){ /* end of the line for scaled case - will return to parent to continue using saved placement. */ closegraphics() ; YexitPgm( PGMOK ) ; } grid_cells() ; /* force cells to grid locations */ compact(VIOLATIONSONLY); /* remove cell overlap */ /* if this is a partitioning run determine row placement */ if( doPartitionG && !(quickrouteG) ){ set_determine_side( FALSE ) ; /* allow SC to pick side */ G( set_graphic_context( PARTITION_PLACEMENT ) ) ; config_rows() ; print_paths() ; /* print path information */ Output( 0 ) ; return ; } /* do final placement of pads using virtual core to insure pads */ /* are outside of core */ setVirtualCore( TRUE ) ; placepads() ; /* before channel graph generation and global routing let use tweak */ /* placement if desired */ check_graphics() ; if( !scale_dataG ){ /* reload bins to get new overlap penalty */ loadbins(FALSE) ; /* wireArea not known */ } prnt_cost( "\nFINAL PLACEMENT RESULTS AFTER VIOLATION REMOVAL ARE:\n" ) ; print_paths() ; /* print path information */ Output( 0 ) ; if( doCompactionG > 0 || quickrouteG ) { gmain( CHANNELGRAPH ) ; rmain( NOCONSTRAINTS ) ; gmain( UPDATE_ROUTING ) ; adapt_wire_estimator() ; check_graphics() ; if( quickrouteG ){ return ; } for( c = 1 ; c <= doCompactionG ; c++ ) { funccostG = findcost() ; sprintf(YmsgG,"\n\nCompactor Pass Number: %d begins with:\n", c ) ; prnt_cost( YmsgG ) ; wirecosts() ; grid_cells() ; /* force cells to grid locations */ compact(COMPACT); /* remove white space */ reorigin() ; check_graphics() ; sprintf(YmsgG,"\n\nCompactor Pass Number: %d after cost:\n", c ) ; prnt_cost( YmsgG ) ; Output( c ) ; gmain( CHANNELGRAPH ) ; if( c == doCompactionG ){ rmain( CONSTRAINTS ) ; } else { rmain( NOCONSTRAINTS ) ; gmain( UPDATE_ROUTING ) ; adapt_wire_estimator() ; check_graphics() ; } } /* end compaction - global route loop */ } else { if( doChannelGraphG ) { gmain( CHANNELGRAPH ) ; } if( doGlobalRouteG ) { rmain( CONSTRAINTS ) ; } } prnt_cost("\nTIMBERWOLFMC FINAL RESULTS ARE:\n" ) ; return ; } /* end finalout */