TEST(algorithmTest, transform_image) { const int width = 10; const int height = 10; cv::Mat_<int> src1(height, width); for(int y=0; y<src1.rows; ++y) { for(int x=0; x<src1.cols; ++x) { src1(y, x) = y*src1.cols + x; } } cv::Mat_<int> src2(height, width); for(int y=0; y<src2.rows; ++y) { for(int x=0; x<src2.cols; ++x) { src2(y, x) = x*src2.cols + y; } } cv::Mat_<int> src3(height, width); for(int y=0; y<src3.rows; ++y) { for(int x=0; x<src3.cols; ++x) { src3(y, x) = x*y; } } cv::Mat_<int> dst1(height, width); cv::Mat_<int> dst2(height, width); cvutil::transform_image(src1, dst1, [](int x){ return x*2; }); for(int y=0; y<dst2.rows; ++y) { for(int x=0; x<dst2.cols; ++x) { dst2(y, x) = src1(y, x)*2; } } ASSERT_TRUE(std::equal(dst2.begin(), dst2.end(), dst2.begin())); cvutil::transform_image(src1, src2, dst1, [](int x, int y){ return x*2 + y*2; }); for(int y=0; y<dst2.rows; ++y) { for(int x=0; x<dst2.cols; ++x) { dst2(y, x) = src1(y, x)*2 + src2(y, x)*2; } } ASSERT_TRUE(std::equal(dst2.begin(), dst2.end(), dst2.begin())); cvutil::transform_image(src1, src2, src3, dst1, [](int x, int y, int z){ return x + y + z; }); for(int y=0; y<dst2.rows; ++y) { for(int x=0; x<dst2.cols; ++x) { dst2(y, x) = src1(y, x) + src2(y, x) + src3(y, x); } } ASSERT_TRUE(std::equal(dst2.begin(), dst2.end(), dst2.begin())); }
GPU_PERF_TEST(GEMM, cv::gpu::DeviceInfo, cv::Size) { cv::gpu::DeviceInfo devInfo = GET_PARAM(0); cv::Size size = GET_PARAM(1); cv::gpu::setDevice(devInfo.deviceID()); cv::Mat src1_host(size, CV_32FC1); cv::Mat src2_host(size, CV_32FC1); cv::Mat src3_host(size, CV_32FC1); fill(src1_host, 0.0, 10.0); fill(src2_host, 0.0, 10.0); fill(src3_host, 0.0, 10.0); cv::gpu::GpuMat src1(src1_host); cv::gpu::GpuMat src2(src2_host); cv::gpu::GpuMat src3(src3_host); cv::gpu::GpuMat dst; declare.time(5.0); TEST_CYCLE() { cv::gpu::gemm(src1, src2, 1.0, src3, 1.0, dst); } }
void test_single_dest() { // push only tbb::flow::graph g; tbb::flow::source_node<T> src(g, source_body<T>() ); test_push_receiver<T> dest; tbb::flow::make_edge( src, dest ); g.wait_for_all(); for (int i = 0; i < N; ++i ) { ASSERT( dest.get_count(i) == 1, NULL ); } // push only tbb::atomic<int> counters3[N]; tbb::flow::source_node<T> src3(g, source_body<T>() ); function_body<T> b3( counters3 ); tbb::flow::function_node<T,bool> dest3(g, tbb::flow::unlimited, b3 ); tbb::flow::make_edge( src3, dest3 ); g.wait_for_all(); for (int i = 0; i < N; ++i ) { int v = counters3[i]; ASSERT( v == 1, NULL ); } // push & pull tbb::flow::source_node<T> src2(g, source_body<T>() ); tbb::atomic<int> counters2[N]; function_body<T> b2( counters2 ); tbb::flow::function_node<T,bool> dest2(g, tbb::flow::serial, b2 ); tbb::flow::make_edge( src2, dest2 ); #if TBB_PREVIEW_FLOW_GRAPH_FEATURES ASSERT(src2.successor_count() == 1, NULL); typename tbb::flow::source_node<T>::successor_vector_type my_succs; src2.copy_successors(my_succs); ASSERT(my_succs.size() == 1, NULL); #endif g.wait_for_all(); for (int i = 0; i < N; ++i ) { int v = counters2[i]; ASSERT( v == 1, NULL ); } // test copy constructor tbb::flow::source_node<T> src_copy(src); test_push_receiver<T> dest_c; ASSERT( src_copy.register_successor(dest_c), NULL ); g.wait_for_all(); for (int i = 0; i < N; ++i ) { ASSERT( dest_c.get_count(i) == 1, NULL ); } }
void test_single_dest() { // push only tbb::flow::graph g; tbb::flow::source_node<T> src(g, source_body<T>() ); test_push_receiver<T> dest; tbb::flow::make_edge( src, dest ); g.wait_for_all(); for (int i = 0; i < N; ++i ) { ASSERT( dest.get_count(i) == 1, NULL ); } // push only tbb::atomic<int> counters3[N]; tbb::flow::source_node<T> src3(g, source_body<T>() ); function_body<T> b3( counters3 ); tbb::flow::function_node<T,bool> dest3(g, tbb::flow::unlimited, b3 ); tbb::flow::make_edge( src3, dest3 ); g.wait_for_all(); for (int i = 0; i < N; ++i ) { int v = counters3[i]; ASSERT( v == 1, NULL ); } // push & pull tbb::flow::source_node<T> src2(g, source_body<T>() ); tbb::atomic<int> counters2[N]; function_body<T> b2( counters2 ); tbb::flow::function_node<T,bool> dest2(g, tbb::flow::serial, b2 ); tbb::flow::make_edge( src2, dest2 ); g.wait_for_all(); for (int i = 0; i < N; ++i ) { int v = counters2[i]; ASSERT( v == 1, NULL ); } // test copy constructor tbb::flow::source_node<T> src_copy(src); test_push_receiver<T> dest_c; ASSERT( src_copy.register_successor(dest_c), NULL ); g.wait_for_all(); for (int i = 0; i < N; ++i ) { ASSERT( dest_c.get_count(i) == 1, NULL ); } }
TEST(SAVE, SaveGraph) { std::string expect_pbfile = testdir + "/graph.pb"; std::string got_pbfile = "got_graph.pb"; cortenn::Graph graph; std::vector<ade::TensptrT> roots; pbm::PathedMapT labels; // subtree one ade::Shape shape({3, 7}); ade::TensptrT osrc(new MockTensor(shape)); ade::Shape shape2({7, 3}); ade::TensptrT osrc2(new MockTensor(shape2)); labels[osrc] = {"global", "osrc"}; labels[osrc2] = {"global", "osrc2"}; { ade::TensptrT src(new MockTensor(shape)); ade::Shape shape3({3, 1, 7}); ade::TensptrT src2(new MockTensor(shape3)); ade::TensptrT dest(ade::Functor::get(ade::Opcode{"-", 0}, { {src2, ade::identity}, {ade::TensptrT(ade::Functor::get(ade::Opcode{"@", 1}, { {ade::TensptrT(ade::Functor::get(ade::Opcode{"/", 2}, { {ade::TensptrT(ade::Functor::get(ade::Opcode{"neg", 3}, { {osrc, ade::identity}, })), ade::identity}, {ade::TensptrT(ade::Functor::get(ade::Opcode{"+", 4}, { {ade::TensptrT( ade::Functor::get(ade::Opcode{"sin", 5}, { {src, ade::identity}})), ade::identity}, {src, ade::identity}, })), ade::identity} })), ade::permute({1, 0})}, {osrc2, ade::identity} })), ade::permute({1, 2, 0})}, })); roots.push_back(dest); labels[src] = {"subtree", "src"}; labels[src2] = {"subtree", "src2"}; labels[dest] = {"subtree", "dest"}; } // subtree two { ade::Shape mshape({3, 3}); ade::TensptrT src(new MockTensor(mshape)); ade::TensptrT src2(new MockTensor(mshape)); ade::TensptrT src3(new MockTensor(mshape)); ade::TensptrT dest(ade::Functor::get(ade::Opcode{"-", 0}, { {src, ade::identity}, {ade::TensptrT(ade::Functor::get(ade::Opcode{"*", 6}, { {ade::TensptrT(ade::Functor::get(ade::Opcode{"abs", 7}, { {src, ade::identity}, })), ade::identity}, {ade::TensptrT(ade::Functor::get(ade::Opcode{"exp", 8}, { {src2, ade::identity}, })), ade::identity}, {ade::TensptrT(ade::Functor::get(ade::Opcode{"neg", 3}, { {src3, ade::identity}, })), ade::identity}, })), ade::identity}, })); roots.push_back(dest); labels[src] = {"subtree2", "src"}; labels[src2] = {"subtree2", "src2"}; labels[src3] = {"subtree2", "src3"}; labels[dest] = {"subtree2", "dest"}; } pbm::GraphSaver<TestSaver> saver; for (auto& root : roots) { root->accept(saver); } saver.save(graph, labels); { std::fstream gotstr(got_pbfile, std::ios::out | std::ios::trunc | std::ios::binary); ASSERT_TRUE(gotstr.is_open()); ASSERT_TRUE(graph.SerializeToOstream(&gotstr)); } std::fstream expect_ifs(expect_pbfile, std::ios::in | std::ios::binary); std::fstream got_ifs(got_pbfile, std::ios::in | std::ios::binary); ASSERT_TRUE(expect_ifs.is_open()); ASSERT_TRUE(got_ifs.is_open()); std::string expect; std::string got; // skip the first line (it contains timestamp) expect_ifs >> expect; got_ifs >> got; for (size_t lineno = 1; expect_ifs && got_ifs; ++lineno) { expect_ifs >> expect; got_ifs >> got; EXPECT_STREQ(expect.c_str(), got.c_str()) << "line number " << lineno; } }
void Hud::renderRadar(const float dt, sdlx::Surface &window, const std::vector<v3<int> > &specials, const std::vector<v3<int> > &flags, const sdlx::Rect &viewport) { if (!Map->loaded()) { _radar.free(); _radar_bg.free(); return; } if (_map_mode == MapNone || !_enable_radar) return; if (!_radar.isNull() && !_update_radar.tick(dt)) { const int x = window.get_width() - _radar.get_width(), y = _background->get_height(); window.blit(_radar, x, y); return; } if (_radar_bg.isNull()) generateRadarBG(viewport); //needed for destructable layers. v2<int> radar_size; if (_map_mode == MapSmall) { radar_size.x = math::min(window.get_width() / 8, _radar_bg.get_width()); radar_size.y = math::min(window.get_height() / 8, _radar_bg.get_height()); } else { radar_size.x = _radar_bg.get_width(); radar_size.y = _radar_bg.get_height(); } if (_radar.isNull()) { _radar.create_rgb(radar_size.x, radar_size.y, 32); _radar.display_format_alpha(); } const int x = window.get_width() - _radar.get_width(), y = _background->get_height(); v2<int> msize = Map->get_size(); v2<int> radar_shift; if (_map_mode == MapSmall || Map->torus()) { radar_shift.x = viewport.x + viewport.w / 2 - msize.x / 2 - msize.x * (_radar.get_width() - _radar_bg.get_width()) / 2 / _radar_bg.get_width(); radar_shift.y = viewport.y + viewport.h / 2 - msize.y / 2 - msize.y * (_radar.get_height() - _radar_bg.get_height()) / 2 / _radar_bg.get_height(); Map->validate(radar_shift); } if (Map->torus()) { /* 2x2 split [12] [34] */ v2<int> split = radar_shift; //LOG_DEBUG(("split: %d %d %d %d", split.x, split.y, viewport.x, viewport.y)); split *= v2<int>(_radar_bg.get_width(), _radar_bg.get_height()); split /= msize; //int split_x = (viewport.w - viewport.x) * _radar_bg.get_width() / msize.x, split_y = (viewport.h - viewport.y) * _radar_bg.get_width() / msize.x; _radar.fill(_radar.map_rgba(0,0,0,255)); sdlx::Rect src1(split.x - _radar_bg.get_width(), split.y - _radar_bg.get_height(), _radar_bg.get_width(), _radar_bg.get_height()); sdlx::Rect src2(split.x, split.y - _radar_bg.get_height(), _radar_bg.get_width(), _radar_bg.get_height()); sdlx::Rect src3(split.x - _radar_bg.get_width(), split.y, _radar_bg.get_width(), _radar_bg.get_height()); sdlx::Rect src4(split.x, split.y, _radar_bg.get_width(), _radar_bg.get_height()); _radar.blit(_radar_bg, src1, 0, 0); _radar.blit(_radar_bg, src2, 0, 0); _radar.blit(_radar_bg, src3, 0, 0); _radar.blit(_radar_bg, src4, 0, 0); } else { if (radar_shift.x < 0) radar_shift.x = 0; if (radar_shift.y < 0) radar_shift.y = 0; v2<int> radar_map_size = radar_size * msize / v2<int>(_radar_bg.get_width(), _radar_bg.get_height()); if (radar_shift.x + radar_map_size.x > msize.x) radar_shift.x = msize.x - radar_map_size.x; if (radar_shift.y + radar_map_size.y > msize.y) radar_shift.y = msize.y - radar_map_size.y; v2<int> shift = radar_shift * v2<int>(_radar_bg.get_width(), _radar_bg.get_height()) / msize; sdlx::Rect src(shift.x, shift.y, _radar.get_width(), _radar.get_height()); _radar.blit(_radar_bg, src, 0, 0); } //LOG_DEBUG(("radar shift: %d %d", radar_shift.x, radar_shift.y)); _radar.lock(); size_t n = PlayerManager->get_slots_count(); for(size_t i = 0; i < n; ++i) { PlayerSlot &slot = PlayerManager->get_slot(i); const Object *obj = slot.getObject(); if (obj == NULL) continue; v2<int> pos; obj->get_center_position(pos); pos -= radar_shift; Map->validate(pos); _radar.put_pixel(pos.x * _radar_bg.get_width() / msize.x, pos.y * _radar_bg.get_height() / msize.y, index2color(_radar, i + 1, 255)); _radar.put_pixel(pos.x * _radar_bg.get_width() / msize.x, pos.y * _radar_bg.get_height() / msize.y + 1, index2color(_radar, i + 1, 200)); _radar.put_pixel(pos.x * _radar_bg.get_width() / msize.x, pos.y * _radar_bg.get_height() / msize.y - 1, index2color(_radar, i + 1, 200)); _radar.put_pixel(pos.x * _radar_bg.get_width() / msize.x + 1, pos.y * _radar_bg.get_height() / msize.y, index2color(_radar, i + 1, 200)); _radar.put_pixel(pos.x * _radar_bg.get_width() / msize.x - 1, pos.y * _radar_bg.get_height() / msize.y, index2color(_radar, i + 1, 200)); } static bool blink; blink = !blink; if (blink) { //format me n = specials.size(); for(size_t i = 0; i < n; ++i) { v3<int> pos = specials[i]; { v2<int> p(pos.x, pos.y); p -= radar_shift; Map->validate(p); pos.x = p.x; pos.y = p.y; } Uint32 color[2]; color[0] = index2color(_radar, i + 1, 255); color[1] = index2color(_radar, i + 1, 200); for(int b = 0; b < 2; ++b) { _radar.put_pixel(b + pos.x * _radar_bg.get_width() / msize.x, pos.y * _radar_bg.get_height() / msize.y, color[b]); for(int l = 1; l <= 2; ++l) { _radar.put_pixel(b + pos.x * _radar_bg.get_width() / msize.x + l, pos.y * _radar_bg.get_height() / msize.y + l, color[b]); _radar.put_pixel(b + pos.x * _radar_bg.get_width() / msize.x - l, pos.y * _radar_bg.get_height() / msize.y - l, color[b]); _radar.put_pixel(b + pos.x * _radar_bg.get_width() / msize.x + l, pos.y * _radar_bg.get_height() / msize.y - l, color[b]); _radar.put_pixel(b + pos.x * _radar_bg.get_width() / msize.x - l, pos.y * _radar_bg.get_height() / msize.y + l, color[b]); } } } n = flags.size(); if (n > 2) n = 2; for(size_t i = 0; i < n; ++i) { v3<int> pos = flags[i]; { v2<int> p(pos.x, pos.y); p -= radar_shift; Map->validate(p); pos.x = p.x; pos.y = p.y; } Uint32 color[2] = { _radar.map_rgb(255, 0, 0), _radar.map_rgb(0, 255, 0), }; _radar.put_pixel(0 + pos.x * _radar_bg.get_width() / msize.x, 0 + pos.y * _radar_bg.get_height() / msize.y, color[i]); _radar.put_pixel(1 + pos.x * _radar_bg.get_width() / msize.x, 0 + pos.y * _radar_bg.get_height() / msize.y, color[i]); _radar.put_pixel(2 + pos.x * _radar_bg.get_width() / msize.x, 0 + pos.y * _radar_bg.get_height() / msize.y, color[i]); _radar.put_pixel(0 + pos.x * _radar_bg.get_width() / msize.x, 1 + pos.y * _radar_bg.get_height() / msize.y, color[i]); _radar.put_pixel(1 + pos.x * _radar_bg.get_width() / msize.x, 1 + pos.y * _radar_bg.get_height() / msize.y, color[i]); _radar.put_pixel(0 + pos.x * _radar_bg.get_width() / msize.x, 2 + pos.y * _radar_bg.get_height() / msize.y, color[i]); _radar.put_pixel(1 + pos.x * _radar_bg.get_width() / msize.x, 2 + pos.y * _radar_bg.get_height() / msize.y, color[i]); _radar.put_pixel(2 + pos.x * _radar_bg.get_width() / msize.x, 2 + pos.y * _radar_bg.get_height() / msize.y, color[i]); _radar.put_pixel(0 + pos.x * _radar_bg.get_width() / msize.x, 3 + pos.y * _radar_bg.get_height() / msize.y, color[i]); } } //blink _radar.unlock(); window.blit(_radar, x, y); }