void find_tight_bounds(const Cubic& cubic, _Rect& bounds) { CubicPair cubicPair; chop_at(cubic, cubicPair, 0.5); if (!tiny(cubicPair.first()) && !controls_inside(cubicPair.first())) { find_tight_bounds(cubicPair.first(), bounds); } else { bounds.add(cubicPair.first()[0]); bounds.add(cubicPair.first()[3]); } if (!tiny(cubicPair.second()) && !controls_inside(cubicPair.second())) { find_tight_bounds(cubicPair.second(), bounds); } else { bounds.add(cubicPair.second()[0]); bounds.add(cubicPair.second()[3]); } }
/* tsin_cos prec [N] performs N tests with prec bits */ int main (int argc, char *argv[]) { tests_start_mpfr (); if (argc > 1) { if (argc != 3 && argc != 4) { fprintf (stderr, "Usage: tsin_cos x prec [n]\n"); exit (1); } large_test (argv[1], atoi (argv[2]), (argc > 3) ? atoi (argv[3]) : 1); goto end; } bug20091013 (); bug20091008 (); bug20091007 (); bug20091122 (); consistency (); test_mpfr_sincos_fast (); check_nans (); /* worst case from PhD thesis of Vincent Lefe`vre: x=8980155785351021/2^54 */ check53 ("4.984987858808754279e-1", "4.781075595393330379e-1", "8.783012931285841817e-1", MPFR_RNDN); check53 ("4.984987858808754279e-1", "4.781075595393329824e-1", "8.783012931285840707e-1", MPFR_RNDD); check53 ("4.984987858808754279e-1", "4.781075595393329824e-1", "8.783012931285840707e-1", MPFR_RNDZ); check53 ("4.984987858808754279e-1", "4.781075595393330379e-1", "8.783012931285841817e-1", MPFR_RNDU); check53 ("1.00031274099908640274", "8.416399183372403892e-1", "0.540039116973283217504", MPFR_RNDN); check53 ("1.00229256850978698523", "8.427074524447979442e-1", "0.538371757797526551137", MPFR_RNDZ); check53 ("1.00288304857059840103", "8.430252033025980029e-1", "0.537874062022526966409", MPFR_RNDZ); check53 ("1.00591265847407274059", "8.446508805292128885e-1", "0.53531755997839769456", MPFR_RNDN); /* check one argument only */ check53sin ("1.00591265847407274059", "8.446508805292128885e-1", MPFR_RNDN); check53cos ("1.00591265847407274059", "0.53531755997839769456", MPFR_RNDN); overflowed_sin_cos0 (); tiny (); test20071214 (); coverage_01032011 (); end: tests_end_mpfr (); return 0; }
std::set<world_vector> sphere::chunks() const { std::set<world_vector> result; sphere tiny (center_ / (float)chunk_size, radius_ / (float)chunk_size); aabb<vec3i> span (cast_to<vec3i>(tiny.bounding_box())); for (auto p : range<vec3i>(span)) { if (tiny.intersects(vec3f(p))) result.insert(p); } return result; }
void cgComparisonTest(){ CL::TinyCL tiny(CL::DEVICE::GPU); SparseMatrix sMat("../res/bcsstk05.mtx"); std::cout << "Computing CG on matrix of dim: " << sMat.dim << std::endl; std::vector<float> b; for (int i = 0; i < sMat.dim; ++i) b.push_back(i); //Compare my kernel with the book kernel to make sure it's correct std::vector<float> localRes, myRes; //Measure elapsed time for my kernel and book kernel std::cout << "Book CG:\n"; std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now(); localRes = localConjGradSolve(sMat, b, tiny); std::chrono::high_resolution_clock::duration bookTime = std::chrono::high_resolution_clock::now() - start; std::cout << "------\nMy CG:\n"; start = std::chrono::high_resolution_clock::now(); myRes = conjugateGradient(sMat, b, tiny); std::chrono::high_resolution_clock::duration myTime = std::chrono::high_resolution_clock::now() - start; std::cout << "-----\nBook solve time: " << std::chrono::duration_cast<std::chrono::milliseconds>(bookTime).count() << "ms\n" << "My solve time: " << std::chrono::duration_cast<std::chrono::milliseconds>(myTime).count() << "ms\n" << "Time difference, mine - book: " << std::chrono::duration_cast<std::chrono::milliseconds>(myTime - bookTime).count() << "ms" << std::endl; //If the results are differ at a digit higher than the some minimal //error then my implementation is wrong float avgDiff = 0, maxDif = 1e-6; int nDifferent = 0; for (int i = 0; i < localRes.size(); ++i){ float diff = std::abs(localRes.at(i) - myRes.at(i)); if (diff > maxDif){ avgDiff += diff; ++nDifferent; } } if (nDifferent != 0) avgDiff /= nDifferent; std::cout << "# of values differing by more than " << std::scientific << maxDif << " : " << nDifferent << " of " << myRes.size() << "\nAverage difference between values: " << avgDiff << std::endl; }
int main (int argc, char *argv[]) { tests_start_mpfr (); special (); special_overflow (); exprange (); tiny (argc == 1); test_generic (2, 100, 2); gamma_integer (); test20071231 (); test20100709 (); data_check ("data/gamma", mpfr_gamma, "mpfr_gamma"); tests_end_mpfr (); return 0; }
int main() { double z = 1.0; cout << "Some inquiries into the nature of double:" << endl << "digits(z) = " << digits(z) << endl << "epsilon(z) = " << epsilon(z) << endl << "huge(z) = " << huge(z) << endl << "tiny(z) = " << tiny(z) << endl << "max_exponent(z) = " << max_exponent(z) << endl << "min_exponent(z) = " << min_exponent(z) << endl << "max_exponent10(z) = " << max_exponent10(z) << endl << "min_exponent10(z) = " << min_exponent10(z) << endl << "precision(z) = " << precision(z) << endl << "radix(z) = " << radix(z) << endl; Range r = range(z); cout << "range(z) = [ " << r.first() << ", " << r.last() << " ]" << endl; cout << endl << "More obscure properties:" << endl << "is_signed(z) = " << is_signed(z) << endl << "is_integer(z) = " << is_integer(z) << endl << "is_exact(z) = " << is_exact(z) << endl << "round_error(z) = " << round_error(z) << endl << "has_infinity(z) = " << has_infinity(z) << endl << "has_quiet_NaN(z) = " << has_quiet_NaN(z) << endl << "has_signaling_NaN(z) = " << has_signaling_NaN(z) << endl << "has_denorm(z) = " << has_denorm(z) << endl << "has_denorm_loss(z) = " << has_denorm_loss(z) << endl << "infinity(z) = " << infinity(z) << endl << "quiet_NaN(z) = " << quiet_NaN(z) << endl << "signaling_NaN(z) = " << signaling_NaN(z) << endl << "denorm_min(z) = " << denorm_min(z) << endl << "is_iec559(z) = " << is_iec559(z) << endl << "is_bounded(z) = " << is_bounded(z) << endl << "is_modulo(z) = " << is_modulo(z) << endl << "traps(z) = " << traps(z) << endl << "tinyness_before(z) = " << tinyness_before(z) << endl; return 0; }
void operator()() const { //------------------------------------------------------- // Data generation : get 4 nearly coplanar points //------------------------------------------------------- Point_creator creator; FT little(1e-10); FT tiny(1e-25); Point p1 = creator(little,1,tiny); Point p2 = creator(1,little,0); Point p3 = creator(-1*little,1,0); Point p4 = creator(1,-1*little,0); Point p5 = creator(0,0,1); Point p6 = creator(0,1,0); std::cerr << "Using points: p1[" << p1 << "]\tp2[" << p2 << "]\tp3[" << p3 << "]\tp4[" << p4 << "]\tp5[" << p5 << "]\tp6[" << p6 << "]\n"; //------------------------------------------------------- // Test correctness //------------------------------------------------------- typename Gt::Construct_weighted_circumcenter_3 circumcenter = Gt().construct_weighted_circumcenter_3_object(); Point center = circumcenter(p1,p2); std::cerr << "\tcircumcenter(p1,p2)=[" << center << "]\n"; center = circumcenter(p1,p3,p6); std::cerr << "\tcircumcenter(p1,p3,p6)=[" << center << "]\n"; center = circumcenter(p1,p2,p5); std::cerr << "\tcircumcenter(p1,p3,p5)=[" << center << "]\n"; // Use positive orientation center = circumcenter(p2,p3,p4,p1); std::cerr << "\tcircumcenter(p2,p3,p4,p1)=[" << center << "]\n"; center = circumcenter(p1,p3,p2,p5); std::cerr << "\tcircumcenter(p1,p3,p2,p5)=[" << center << "]\n"; //------------------------------------------------------- // Test speed //------------------------------------------------------- std::cerr << "Test speed: compute loops of: 999*c(p1,p3,p2,p5) " << "and 1*c(p2,p3,p4,p1)\n"; CGAL::Timer timer; timer.start(); int nb_loop = 0; while ( timer.time() < 0.5 ) { // Compute 1000 fast queries for ( int i = 0 ; i < 999 ; ++i) circumcenter(p1,p3,p2,p5); // Compute 1 exact query circumcenter(p2,p3,p4,p1); ++nb_loop; } timer.stop(); std::cerr << "\t" << nb_loop*1000/timer.time() << " circumcenter computation / second\n"; std::cerr << "Test speed: compute loops of: 999*c(p2,p3,p4,p1) " << "and 1*c(p1,p3,p2,p5)\n"; timer.reset(); timer.start(); nb_loop = 0; while ( timer.time() < 0.5 ) { // Compute 1 exact queries for ( int i = 0 ; i < 999 ; ++i) circumcenter(p2,p3,p4,p1); // Compute 1 fast query circumcenter(p1,p3,p2,p5); ++nb_loop; } timer.stop(); std::cerr << "\t" << nb_loop*1000/timer.time() << " circumcenter computation / second\n"; }
PRIVATE void synthesize_notes (void) /* generate well-spaced notes */ { char *s; s = notes; while (true) { if (debug > 0) fprintf (stderr, "\nIn synthesize s=%s\n", s); if (*s == '\0') { if (spacing == 0) { if (*notes == '\0') return; /* to avoid \znotes\en */ fprintf (outfile,"\\znotes"); } output_notes (s); fprintf (outfile,"\\en"); spacing = 0; return; } if ( prefix ("\\h", s) && !prefix ("\\hs", s) && !prefix ("\\hqsk", s) && !prefix ("\\hroff", s) && !prefix ("\\hloff", s) ) s = spacing_note (s, 2); else if ( prefix ("\\hs", s) && !prefix ("\\hsk", s) ) s = spacing_note (s, 32); else if ( prefix ("\\q", s) && !prefix ("\\qb", s) && !prefix ("\\qs", s) && !prefix ("\\qqsk", s) ) s = spacing_note (s, 4); else if ( prefix ("\\qs", s) && !prefix ("\\qsk", s) ) s = spacing_note (s, 16); else if ( prefix("\\qb", s) ) s = beam_note (s); else if ( prefix ("\\ccccc", s) ) s = spacing_note (s, 128); else if ( prefix ("\\cccc", s) ) s = spacing_note (s, 64); else if ( prefix ("\\ccc", s) ) s = spacing_note (s, 32); else if ( prefix ("\\cc", s) && !prefix ("\\ccharnote", s) ) s = spacing_note (s, 16); else if ( prefix ("\\c", s) && !prefix ("\\cna", s) && !prefix ("\\csh", s) && !prefix ("\\cfl", s) && !prefix ("\\curve", s) && !prefix ("\\ccharnote", s) ) s = spacing_note (s, 8); else if ( prefix ("\\ds", s ) && !prefix ("\\dsh", s) ) s = spacing_note (s, 8); else if ( prefix ("\\wh", s) || prefix ("\\pa", s) || prefix ("\\breve", s) ) s = spacing_note (s, 1); else if ( prefix ("\\Hpause", s) ) s = spacing_note (s, 2); else if ( prefix("\\ib",s) || prefix("\\Ib",s) || prefix("\\nb",s) ) s = beam_initiation (s); else if ( prefix("\\Dq",s) || prefix("\\Tq",s) || prefix("\\Qq",s) ) s = semiautomatic_beam (s); else if ( prefix("\\tb", s) ) s = beam_termination (s); else if ( prefix("\\tq", s) ) s = beam_completion (s); else if ( prefix("\\ztq", s) ) s = nonspacing_beam_termination (s); else if ( prefix("\\tinynotesize", s)) s = tiny (s); else if ( prefix("\\slur", s) || prefix("\\tie", s) || prefix("\\sslur", s) || prefix("\\bslur", s) ) s = simple (s); else if ( prefix("\\zchar", s) || prefix("\\lchar", s) || prefix("\\cchar", s) ) { char *t; /* need to skip two arguments */ s = strchr (s+1, '}'); /* first } */ s = strchr (s+1, '}'); /* second } */ t = strchr(s+1,'\\'); if (t == NULL) t = s + strlen(s); s = t; } else /* non-spacing; skip to next command */ { char *t; t = strchr(s+1,'\\'); if (t == NULL) t = s + strlen(s); s = t; } } }
void liveAdvectTexture(){ Window::init(); Window window("Realtime Texture Advection"); //Set an fps cap const float FPS = 60.0f; //Setup a quad to draw too GL::VertexArray vao; vao.elementBuffer(quadElems); GL::VertexBuffer vbo(quad, GL::USAGE::STATIC_DRAW); //Setup program GL::Program prog("../res/shader.v.glsl", "../res/shader.f.glsl"); //Setup the attributes vao.setAttribPointer(vbo, prog.getAttribute("position"), 3, GL_FLOAT, GL_FALSE); vao.setAttribPointer(vbo, prog.getAttribute("texIn"), 3, GL_FLOAT, GL_FALSE, 0, (void*)(sizeof(glm::vec3) * 4)); glm::mat4 view = glm::lookAt<float>(glm::vec3(0, 0, 1), glm::vec3(0, 0, -1), glm::vec3(0, 1, 0)); glm::mat4 proj = glm::perspective(60.0f, (float)(window.box().w) / (float)(window.box().h), 0.1f, 100.0f); glm::mat4 model = glm::scale(0.55f, 0.55f, 1.0f); glm::mat4 mvp = proj * view * model; prog.uniformMat4x4("mvp", mvp); /* * I don't think OpenCL or OpenGL provide a simple method for copying images/textures so * instead we'll flip the in/out image each step and draw the out image by setting active = out */ //Make textures to work with GL::Texture texA("../res/map.png", true, SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB); GL::Texture texB("../res/blank.png", true, SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB); //Active is the actual texture we will draw GL::Texture active = texB; //Setup our OpenCL context + program and kernel CL::TinyCL tiny(CL::DEVICE::GPU, true); cl::Program program = tiny.loadProgram("../res/simpleAdvect.cl"); cl::Kernel kernel = tiny.loadKernel(program, "simpleAdvect"); //Setup our OpenCL data #ifdef CL_VERSION_1_2 cl::ImageGL imgA = tiny.imageFromTexture(CL::MEM::READ_WRITE, texA); cl::ImageGL imgB = tiny.imageFromTexture(CL::MEM::READ_WRITE, texB); #else cl::Image2DGL imgA = tiny.imageFromTexture(CL::MEM::READ_WRITE, texA); cl::Image2DGL imgB = tiny.imageFromTexture(CL::MEM::READ_WRITE, texB); #endif const float speed = 0.2f; float velocity[2] = { 0.0f, 0.0f }; cl::Buffer velBuf = tiny.buffer(CL::MEM::READ_ONLY, 2 * sizeof(float), velocity); //Setup our GL objects vector std::vector<cl::Memory> glObjs; glObjs.push_back(imgA); glObjs.push_back(imgB); //The time step will be constant and velocity won't change each step, so set'em now float dt = 1.0f / FPS; kernel.setArg(0, sizeof(float), &dt); kernel.setArg(1, velBuf); //Query the preferred work group size int workSize = tiny.preferredWorkSize(kernel); //fixed for now int imgSize = 256; cl::NDRange local(workSize, workSize); cl::NDRange global(imgSize, imgSize); //Track the run number so we know which texture to set as in/out and which to draw int run = 0; //Our event structure SDL_Event e; //Limit framerate with a timer Timer delta; //For tracking if we want to quit bool quit = false, paused = false; while (!quit){ delta.Start(); //Event Polling while (SDL_PollEvent(&e)){ //If user closes he window if (e.type == SDL_QUIT) quit = true; //If user presses any key if (e.type == SDL_KEYDOWN){ switch (e.key.keysym.sym){ //So we can change velocity case SDLK_w: velocity[1] = speed; tiny.writeData(velBuf, 2 * sizeof(float), velocity); break; case SDLK_s: velocity[1] = -speed; tiny.writeData(velBuf, 2 * sizeof(float), velocity); break; case SDLK_a: velocity[0] = -speed; tiny.writeData(velBuf, 2 * sizeof(float), velocity); break; case SDLK_d: velocity[0] = speed; tiny.writeData(velBuf, 2 * sizeof(float), velocity); break; case SDLK_r: velocity[0] = 0.0f; velocity[1] = 0.0f; tiny.writeData(velBuf, 2 * sizeof(float), velocity); break; //Toggle pause case SDLK_SPACE: paused = !paused; break; //For quitting, escape key case SDLK_ESCAPE: quit = true; break; default: break; } } } //Run the kernel, setting the in/out textures properly. On even runs the output will be //in texB, on odd runs output will be in texA if (!paused){ try { //On even runs and the first run texB/imgB is our output, on odd runs it's flipped //Is this really the best way to do this? Maybe there is some faster way to copy the image over //instead of updating this each time if (run % 2 == 0 || run == 0){ kernel.setArg(2, imgA); kernel.setArg(3, imgB); active = texB; } else { kernel.setArg(2, imgB); kernel.setArg(3, imgA); active = texA; } glFinish(); tiny.mQueue.enqueueAcquireGLObjects(&glObjs); tiny.runKernel(kernel, local, global); tiny.mQueue.enqueueReleaseGLObjects(&glObjs); tiny.mQueue.finish(); ++run; } catch (const cl::Error &e){ std::cout << "Error: " << e.what() << " code: " << e.err() << std::endl; } } //RENDERING window.clear(); prog.use(); glBindVertexArray(vao); glActiveTexture(GL_TEXTURE0); //Shouldn't we be drawing active here? glBindTexture(GL_TEXTURE_2D, texA); glDrawElements(GL_TRIANGLES, vao.numElements(), GL_UNSIGNED_SHORT, NULL); window.present(); //Cap fps if (delta.Ticks() < 1000 / FPS) SDL_Delay(1000 / FPS - delta.Ticks()); } window.close(); Window::quit(); }