void operator () () const { try { V v1 (N), v2 (N), v3 (N); (*this) (v1, v2, v3); #ifdef USE_RANGE ublas::vector_range<V> vr1 (v1, ublas::range (0, N)), vr2 (v2, ublas::range (0, N)), vr3 (v3, ublas::range (0, N)); (*this) (vr1, vr2, vr3); #endif #ifdef USE_SLICE ublas::vector_slice<V> vs1 (v1, ublas::slice (0, 1, N)), vs2 (v2, ublas::slice (0, 1, N)), vs3 (v3, ublas::slice (0, 1, N)); (*this) (vs1, vs2, vs3); #endif } catch (std::exception &e) { std::cout << e.what () << std::endl; } catch (...) { std::cout << "unknown exception" << std::endl; } }
void test_obj_setprop() { HandleScope handle_scope; Persistent<Context> context = Context::New(); Context::Scope context_scope(context); Handle<Object> obj = Object::New(); Handle<String> k = String::New("someprop"); Handle<String> v = String::New("somevalue"); obj->Set(k, v); Handle<Value> v2 = obj->Get(k); String::AsciiValue vs(v); String::AsciiValue vs2(v2); do_check_eq(vs.length(), vs2.length()); do_check_eq(0, strcmp(*vs,*vs2)); context.Dispose(); }
void run_cross_type_vector_tests(const char *test_name) { tbb::tick_count t0; typedef std::vector<T, tbb::tbb_allocator<T> > container_type; for (int p = MinThread; p <= MaxThread; ++p) { REMARK("Testing parallel %s on %d thread(s)... ", test_name, p); tbb::task_scheduler_init init(p); T sum; test_helper<T>::init(sum); for (int t = -1; t < REPETITIONS; ++t) { if (Verbose && t == 0) t0 = tbb::tick_count::now(); typedef typename tbb::enumerable_thread_specific< container_type, tbb::cache_aligned_allocator<container_type>, tbb::ets_no_key > ets_nokey_type; typedef typename tbb::enumerable_thread_specific< container_type, tbb::cache_aligned_allocator<container_type>, tbb::ets_key_per_instance > ets_tlskey_type; ets_nokey_type vs; ASSERT( vs.empty(), NULL); tbb::parallel_for ( tbb::blocked_range<int> (0, N, 10000), parallel_vector_for_body<T>( vs ) ); ASSERT( !vs.empty(), NULL); // copy construct ets_tlskey_type vs2(vs); // assign ets_nokey_type vs3; vs3 = vs2; parallel_vector_reduce_body< typename tbb::enumerable_thread_specific< std::vector< T, tbb::tbb_allocator<T> > >::const_range_type, T > pvrb; tbb::parallel_reduce ( vs3.range(1), pvrb ); test_helper<T>::sum(sum, pvrb.sum); ASSERT( vs3.size() == pvrb.count, NULL); tbb::flattened2d<ets_nokey_type> fvs = flatten2d(vs3); size_t ccount = fvs.size(); size_t elem_cnt = 0; for(typename tbb::flattened2d<ets_nokey_type>::const_iterator i = fvs.begin(); i != fvs.end(); ++i) { ++elem_cnt; }; ASSERT(ccount == elem_cnt, NULL); elem_cnt = 0; for(typename tbb::flattened2d<ets_nokey_type>::iterator i = fvs.begin(); i != fvs.end(); ++i) { ++elem_cnt; }; ASSERT(ccount == elem_cnt, NULL); } double result_value = test_helper<T>::get(sum); ASSERT( EXPECTED_SUM == result_value, NULL); REMARK("done\nparallel %s, %d, %g, %g\n", test_name, p, result_value, ( tbb::tick_count::now() - t0).seconds()); } }
void RunParallelVectorTests(const char *test_name) { tbb::tick_count t0; tbb::task_scheduler_init init(tbb::task_scheduler_init::deferred); typedef std::vector<T, tbb::tbb_allocator<T> > ContainerType; for (int p = MinThread; p <= MaxThread; ++p) { if (p == 0) continue; REMARK("Testing parallel %s on %d thread(s)... ", test_name, p); init.initialize(p); T sum = 0; T sum2 = 0; T sum3 = 0; for (int t = -1; t < REPETITIONS; ++t) { if (Verbose && t == 0) t0 = tbb::tick_count::now(); typedef typename tbb::combinable< ContainerType > CombinableType; CombinableType vs; tbb::parallel_for ( tbb::blocked_range<int> (0, N, 10000), ParallelVectorForBody<T>( vs ) ); // copy construct CombinableType vs2(vs); // this causes an assertion failure, related to allocators... // assign CombinableType vs3; vs3 = vs; CombineEachVectorHelper<T> MyCombineEach(sum); vs.combine_each(MyCombineEach); CombineEachVectorHelper<T> MyCombineEach2(sum2); vs2.combine_each(MyCombineEach2); CombineEachVectorHelper<T> MyCombineEach3(sum3); vs2.combine_each(MyCombineEach3); // combine_each sums all elements of each vector into the result. } double ResultValue = sum; ASSERT( EXPECTED_SUM == ResultValue, NULL); ResultValue = sum2; ASSERT( EXPECTED_SUM == ResultValue, NULL); ResultValue = sum3; ASSERT( EXPECTED_SUM == ResultValue, NULL); REMARK("done\nparallel %s, %d, %g, %g\n", test_name, p, ResultValue, ( tbb::tick_count::now() - t0).seconds()); init.terminate(); } }
void operator () () const { V v1 (N), v2 (N), v3 (N); test_expression_with (v1, v2, v3); test_container_with (v1); #ifdef USE_RANGE ublas::vector_range<V> vr1 (v1, ublas::range (0, N)), vr2 (v2, ublas::range (0, N)), vr3 (v3, ublas::range (0, N)); test_expression_with (vr1, vr2, vr3); #endif #ifdef USE_SLICE ublas::vector_slice<V> vs1 (v1, ublas::slice (0, 1, N)), vs2 (v2, ublas::slice (0, 1, N)), vs3 (v3, ublas::slice (0, 1, N)); test_expression_with (vs1, vs2, vs3); #endif }
Main() { mScale = 0.1f; mOffset = 1.0f; mDataOffset = 0; isClicked = false; screen = Vec2<unsigned int>(800, 600); std::setlocale(LC_ALL, "en_US.UTF-8"); glfwInit(); glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); //glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); GLFWwindow* window = glfwCreateWindow(screen.x, screen.y, "test", nullptr, nullptr); if (window == nullptr) { printf("cant create window"); return; } glfwSetWindowSizeCallback(window, windowSizeCallback); glfwSetKeyCallback(window, keyCallback); glfwSetMouseButtonCallback(window, clickCallback); glfwSetCursorPosCallback(window, mouseCallback); glfwMakeContextCurrent(window); glewExperimental = true; glewInit(); int tmp; glGetIntegerv(GL_MAX_ELEMENTS_VERTICES , &tmp); std::cout << "GL_MAX_ELEMENTS_VERTICES: " << tmp << std::endl; int err = Pa_Initialize(); if (err != paNoError) printf("error"); int num = Pa_GetDeviceCount(); const PaDeviceInfo* devInfo; const PaHostApiInfo* apiInfo; for (int i = 0; i < num; ++i) { devInfo = Pa_GetDeviceInfo(i); apiInfo = Pa_GetHostApiInfo(devInfo->hostApi); printf("%i, %s on %s\n", i, devInfo->name, apiInfo->name); } float sampleRate = 44100.0f; double t = glfwGetTime(); Kern k(sampleRate, 12, 4 * 16.352f, sampleRate / 2); BlockMatrix<std::complex<double>> b(k.K, k.mN0, k.mB, 0.01); mAudioData = new double[b.getWidth()]; mAudioLength = b.getWidth(); for (unsigned int i = 0; i < mAudioLength; ++i) { mAudioData[i] = wave(55, sampleRate, i) + wave(110, sampleRate, i) + wave(220, sampleRate, i) + wave(440, sampleRate, i) + wave(880, sampleRate, i) + wave(1760, sampleRate, i) + wave(3520, sampleRate, i) + wave(7040, sampleRate, i); } printf("kernel time:%f\n", glfwGetTime() - t); float drawArray[k.mB * 2]; std::complex<double> out[k.mB]; CQT::transform(mAudioData, out, b, mAudioLength); t = glfwGetTime(); printf("transform time:%f\n", glfwGetTime() - t); //glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); glDebugMessageCallback(debugCallback, nullptr); //glEnable(GL_DEBUG_OUTPUT); printf("%s\n", glGetString(GL_VERSION)); Shader fs("res/shader/fragment.c", true, GL_FRAGMENT_SHADER); Shader vs("res/shader/vertex.c", true, GL_VERTEX_SHADER); Program* p = new Program(); p->attach(fs); p->attach(vs); p->build(); p->use(); Program p2; Shader fs2("res/shader/fragment2.c", true, GL_FRAGMENT_SHADER); Shader vs2("res/shader/vertex2.c", true, GL_VERTEX_SHADER); p2.attach(fs2); p2.attach(vs2); p2.build(); p2.use(); int uniformData = p2.getUniformLocation("data"); unsigned int waterfallSize = 512; tm = new TextureManager(); unsigned int waterfallTexture; unsigned int waterfallId = tm->getFreeTexture(); glGenTextures(1, &waterfallTexture); glActiveTexture(GL_TEXTURE0 + waterfallId); glBindTexture( GL_TEXTURE0, waterfallTexture ); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); unsigned char* textureTmp = new unsigned char[waterfallSize * b.getWidth()]; glTexImage2D( GL_TEXTURE_2D_ARRAY, 0, GL_R8, b.getWidth(), waterfallSize, 0, GL_RED, GL_UNSIGNED_BYTE, textureTmp); delete textureTmp; float max = 0; for (unsigned int i = 0; i < k.mB; ++i) { drawArray[2 * i + 0] = (float)i / k.mB * 2.0f - 1.0f; float tmp = std::abs(out[i]); drawArray[2 * i + 1] = tmp; max = std::max(tmp, max); } font = new Font(512, "res/font/DroidSans.woff", 32, tm); print = new Print(font); //print.set(&font, "res/shader/fontVertex.c", "res/shader/fontFragment.c"); print->setScreenSize(screen); glm::vec2* vert = new glm::vec2[1024]; glm::vec2* debug = new glm::vec2[b.getWidth()]; for (unsigned int i = 0; i < b.getWidth(); ++i) { debug[i].x = (float)i / b.getWidth() * 2.0f - 1.0f; } uint32_t vao; glGenVertexArrays(1, &vao); glBindVertexArray(vao); uint32_t vbo[2]; glGenBuffers(1, vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo[0]); glEnableVertexAttribArray(0); glBufferData(GL_ARRAY_BUFFER, k.mB * sizeof(glm::vec2), drawArray, GL_DYNAMIC_DRAW); glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_BLEND); glfwSetWindowUserPointer(window, this); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); double time, timeo; glfwSwapInterval(1); PaStream* stream; PaStreamParameters params; params.device = 21; params.channelCount = 1; params.sampleFormat = paFloat32; params.hostApiSpecificStreamInfo = nullptr; params.suggestedLatency = 0.5; err = Pa_OpenStream(&stream, ¶ms, nullptr, sampleRate, paFramesPerBufferUnspecified, 0, paCallback, this); if (err != paNoError) printf("error %i", err); Pa_StartStream(stream); while(!glfwWindowShouldClose(window)) { timeo = time; time = glfwGetTime(); CQT::transform(mAudioData, out, b, mAudioLength); max = 0.0f; for (unsigned int i = 0; i < k.mB; ++i) { drawArray[2 * i + 0] = (float)i / k.mB * 2.0f - 1.0f; float tmp = std::abs(out[i]); drawArray[2 * i + 1] = tmp; max = std::max(tmp, max); } for (unsigned int i = 0; i < k.mB; ++i) { drawArray[2 * i + 1] = std::log(drawArray[2 * i +1]) * mScale + mOffset; } //printf("%f\n", drawArray[1]); glBindVertexArray(vao); glBindBuffer(GL_ARRAY_BUFFER, vbo[0]); glBufferData(GL_ARRAY_BUFFER, k.mB * sizeof(glm::vec2), drawArray, GL_DYNAMIC_DRAW); p->use(); glDrawArrays(GL_LINE_STRIP, 0, k.mB); for (unsigned int i = 0; i < b.getWidth(); ++i) { debug[i].y = mAudioData[i] / 15.0; } glBufferData(GL_ARRAY_BUFFER, b.getWidth() * sizeof(glm::vec2), debug, GL_DYNAMIC_DRAW); glDrawArrays(GL_LINE_STRIP, 0, b.getWidth()); print->printfAt(-300.0f, 100.0f, 16.0f, 16.0f, u8"Fps:%03.3f", 1/(time-timeo)); glfwSwapBuffers(window); glClear(GL_COLOR_BUFFER_BIT); glfwPollEvents(); } Pa_StopStream(stream); Pa_CloseStream(stream); Pa_Terminate(); std::cout << "Hello World. I'm Peach." << std::endl; }
TEST(SharedValueTest, ctorInt) { int i = -324523; unsigned u = 0x334234u; char c = -22; short s = 289; unsigned char uc = 244; unsigned short us = 3467; long long ll = -20398574395872907ll; unsigned long long ull = 985734209239847656ull; EXPECT_NO_THROW(Value v(i)); EXPECT_NO_THROW(Value v(u)); EXPECT_NO_THROW(Value v(c)); EXPECT_NO_THROW(Value v(s)); EXPECT_NO_THROW(Value v(uc)); EXPECT_NO_THROW(Value v(us)); EXPECT_NO_THROW(Value v(ll)); EXPECT_NO_THROW(Value v(ull)); Value vi(i); EXPECT_EQ(vi.as<int>(), i); Value vu(u); EXPECT_EQ(vu.as<unsigned>(), u); Value vc(c); EXPECT_EQ(vc.as<char>(), c); Value vs(s); EXPECT_EQ(vs.as<short>(), s); Value vuc(uc); EXPECT_EQ(vuc.as<unsigned char>(), uc); Value vus(us); EXPECT_EQ(vus.as<unsigned short>(), us); Value vll(ll); EXPECT_NE(vll.as<long long>(), ll); // 32 bit storage overfflow EXPECT_EQ(vll.as<long long>(), static_cast<long long>(int(ll))); Value vull(ull); EXPECT_NE(vull.as<unsigned long long>(), ull); // 32 bit storage overfflow EXPECT_EQ(vull.as<unsigned long long>(), static_cast<unsigned long long>(int(ull))); Value vllNoOverflow(-42424ll); // no 32 bit storage overflow EXPECT_EQ(vllNoOverflow.as<long long>(), -42424ll); Value vullNoOverflow(0x43424242ull); // no 32 bit storage overflow EXPECT_EQ(vullNoOverflow.as<unsigned long long>(), 0x43424242ull); EXPECT_EQ(vi.type(), typeid(int)); EXPECT_EQ(vu.type(), typeid(int)); EXPECT_EQ(vc.type(), typeid(int)); EXPECT_EQ(vs.type(), typeid(int)); EXPECT_EQ(vuc.type(), typeid(int)); EXPECT_EQ(vus.type(), typeid(int)); EXPECT_EQ(vll.type(), typeid(int)); EXPECT_EQ(vull.type(), typeid(int)); // copy EXPECT_NO_THROW(Value v(vi)); EXPECT_NO_THROW(Value v(vu)); EXPECT_NO_THROW(Value v(vc)); EXPECT_NO_THROW(Value v(vs)); EXPECT_NO_THROW(Value v(vuc)); EXPECT_NO_THROW(Value v(vus)); EXPECT_NO_THROW(Value v(vll)); EXPECT_NO_THROW(Value v(vull)); Value vi2(vi); EXPECT_EQ(vi2.as<int>(), i); Value vu2(vu); EXPECT_EQ(vu2.as<unsigned>(), u); Value vc2(vc); EXPECT_EQ(vc2.as<char>(), c); Value vs2(vs); EXPECT_EQ(vs2.as<short>(), s); Value vuc2(vuc); EXPECT_EQ(vuc2.as<unsigned char>(), uc); Value vus2(vus); EXPECT_EQ(vus2.as<unsigned short>(), us); Value vll2(vll); EXPECT_NE(vll.as<long long>(), ll); EXPECT_EQ(vll2.as<long long>(), static_cast<long long>(int(vll))); Value vull2(vull); EXPECT_NE(vull.as<unsigned long long>(), ull); EXPECT_EQ(vull2.as<unsigned long long>(), static_cast<unsigned long long>(int(vull))); EXPECT_EQ(vi2.type(), typeid(int)); EXPECT_EQ(vu2.type(), typeid(int)); EXPECT_EQ(vc2.type(), typeid(int)); EXPECT_EQ(vs2.type(), typeid(int)); EXPECT_EQ(vuc2.type(), typeid(int)); EXPECT_EQ(vus2.type(), typeid(int)); EXPECT_EQ(vll2.type(), typeid(int)); EXPECT_EQ(vull2.type(), typeid(int)); }
int main () { printf ("Results of xmesh_saver_test:\n"); try { VertexStream vs1 (4, make_vertex_declaration<CustomVertex> ()); CustomVertex* verts1 = vs1.Data<CustomVertex> (); if (verts1) { for (uint32_t i=0; i<vs1.Size (); i++) { verts1 [i].position = vec3f ((float)i, (float)i * 2, (float)i * 3); verts1 [i].normal = vec3f ((float)(i & 1), (float)((i + 1) & 1), 0); verts1 [i].texcoord0 = vec2f (0, -(float)i, 0); verts1 [i].color = vec4ub (0, i, 0, i); verts1 [i].tangent = vec3f (1.0f, 0.0f, 0.0f); } } VertexWeightStream vws (5); VertexWeight* weights = vws.Data (); for (uint32_t i=0; i<vws.Size (); i++) { weights [i].joint_index = i; weights [i].joint_weight = float (i) / float (vws.Size ()); } typedef Vertex<VertexInfluence, Position3f> MyVertex; VertexStream vs2 (4, make_vertex_declaration<MyVertex> ()); MyVertex* verts2 = vs2.Data<MyVertex> (); if (verts2) { for (uint32_t i=0; i<vs1.Size (); i++) { verts2 [i].first_weight = i; verts2 [i].weights_count = 1; verts2 [i].position = 0.0f; } } IndexBuffer ib (5); for (uint32_t i=0; i<ib.Size (); i++) ib.Data<unsigned int> () [i] = i; Mesh mesh1; mesh1.Rename ("mesh1"); VertexBuffer vb1; vb1.Attach (vs1); mesh1.Attach (vb1); mesh1.Attach (ib); mesh1.AddPrimitive (PrimitiveType_TriangleList, 0, 0, 1, "material1"); mesh1.AddPrimitive (PrimitiveType_TriangleStrip, 0, 1, 1, "material2"); Mesh mesh2; mesh2.Rename ("mesh2"); VertexBuffer vb2; vb2.Attach (vs1); vb2.Attach (vs2); vb2.AttachWeights (vws); mesh2.Attach (vb2); mesh2.AddPrimitive (PrimitiveType_LineList, 0, 0, 1, "material1"); mesh2.AddPrimitive (PrimitiveType_LineStrip, 0, 1, 2, "material2"); MeshLibrary mesh_library; mesh_library.Rename ("my_mesh_library"); mesh_library.Attach ("mesh1", mesh1); mesh_library.Attach ("mesh2", mesh2); mesh_library.Save (DST_FILE_NAME); } catch (std::exception& exception) { printf ("exception: %s\n", exception.what ()); } return 0; }