Eigen::MatrixXd GenerateData(const unsigned int numberOfSamplesPerGroup, const unsigned int dimensionality) { std::default_random_engine generator(0); // Seed with 0, so results are repeatable // Mean 0, Standard deviation 1 for both dimensions Eigen::MatrixXd data1(dimensionality, numberOfSamplesPerGroup); std::normal_distribution<double> normalDistribution1(0,sqrt(1)); for(unsigned int i = 0; i < numberOfSamplesPerGroup; i++) { Eigen::VectorXd v(dimensionality); v(0) = normalDistribution1(generator); v(1) = normalDistribution1(generator); data1.col(i) = v; } // Mean 10, Standard deviation 2 for both dimensions Eigen::MatrixXd data2(dimensionality, numberOfSamplesPerGroup); std::normal_distribution<double> normalDistribution2(10,sqrt(2)); for(unsigned int i = 0; i < numberOfSamplesPerGroup; i++) { Eigen::VectorXd v(dimensionality); v(0) = normalDistribution2(generator); v(1) = normalDistribution2(generator); data2.col(i) = v; } // Concatentate the matrices horiztonally Eigen::MatrixXd data(dimensionality, data1.cols() + data2.cols()); data << data1, data2; return data; }
int test_Matrix::serialtest2() { testData* testdata = new testData(localProc_, numProcs_); std::vector<int>& idTypes = testdata->idTypes; std::vector<int>& ids = testdata->ids; fei::SharedPtr<fei::VectorSpace> vspc(new fei::VectorSpace(comm_, "sU_Mat")); vspc->defineIDTypes(idTypes.size(), &idTypes[0]); fei::SharedPtr<fei::MatrixGraph> matgraph(new fei::MatrixGraph_Impl2(vspc, vspc, "sU_Mat")); int numIDs = ids.size(); int idType = idTypes[0]; int patternID = matgraph->definePattern(numIDs, idType); CHK_ERR( matgraph->initConnectivityBlock(0, 1, patternID) ); CHK_ERR( matgraph->initConnectivity(0, 0, &ids[0]) ); CHK_ERR( matgraph->initComplete() ); fei::SharedPtr<fei::FillableMat> ssmat(new fei::FillableMat), ssmatT(new fei::FillableMat); int localsize = matgraph->getRowSpace()->getNumIndices_Owned(); fei::Matrix* matrix = new fei::Matrix_Impl<fei::FillableMat>(ssmat, matgraph, localsize); fei::Matrix* matrixT = new fei::Matrix_Impl<fei::FillableMat>(ssmatT, matgraph, localsize); std::vector<int> indices(numIDs); CHK_ERR( matgraph->getConnectivityIndices(0, 0, numIDs, &indices[0], numIDs) ); std::vector<double> data1(numIDs*numIDs); std::vector<double*> data2d(numIDs); int i; for(i=0; i<numIDs; ++i) { data2d[i] = &(data1[i*numIDs]); } for(i=0; i<numIDs*numIDs; ++i) { data1[i] = 1.0*i; } CHK_ERR( matrix->sumIn(numIDs, &indices[0], numIDs, &indices[0], &data2d[0], 0) ); CHK_ERR( matrixT->sumIn(numIDs, &indices[0], numIDs, &indices[0], &data2d[0], 3) ); if (*ssmat != *ssmatT) { ERReturn(-1); } delete matrix; delete matrixT; delete testdata; return(0); }
int main(void) { Foo data1(5); Bar* data2 = (Bar*)malloc(SIZE*sizeof(Bar)); auto acc = hc::accelerator(); Bar* data2_d = (Bar*)hc::am_alloc(SIZE*sizeof(Bar), acc, 0); grid_launch_parm lp; grid_launch_init(&lp); lp.grid_dim = gl_dim3(GRID_SIZE, 1); lp.group_dim = gl_dim3(TILE_SIZE, 1); hc::completion_future cf; lp.cf = &cf; kernel1(lp, data1, data2_d); lp.cf->wait(); hc::am_copy(data2, data2_d, SIZE*sizeof(Bar)); bool ret = 0; for(int i = 0; i < SIZE; ++i) { if((data2[i].x != i + data1.y)) { ret = 1; break; } } hc::am_free(data2_d); free(data2); return ret; }
void serialize() { // create a small test file int mode = saga::filesystem::Create | saga::filesystem::ReadWrite; saga::filesystem::file f1 (saga::url("test.txt"), mode); std::string data("This is a test file!"); f1.write(saga::buffer(data)); std::string url1(f1.get_url().get_string()); // serialize file std::string data1(saga::adaptors::serialize(f1)); f1.close(); // re-create a saga::file saga::filesystem::file f2 (saga::adaptors::deserialize(data1)); BOOST_CHECK_EQUAL(url1, f2.get_url()); // check if position has been re-created correctly saga::off_t offset = f2.seek(0, saga::filesystem::Current); BOOST_CHECK_EQUAL(offset, (saga::off_t)data.size()); std::string data2(saga::adaptors::serialize(f2)); BOOST_CHECK_EQUAL(data1, data2); f2.close(); boost::filesystem::remove("test.txt"); }
void treiber(unsigned int wert) { begin0(); int index[16]; int i; for(i=0; wert > 0; i++) { index[i]=wert%2; wert=wert/2; } for(;i < 16; i++) { index[i]=0; } for (; i > 0; i--) { if(i == 8) { } if(index[i-1] == 0) { data0(); } else { data1(); } } end0(); }
void Vehicle::RemovePassenger(Unit *unit) { SeatMap::iterator seat; for(seat = m_Seats.begin(); seat != m_Seats.end(); ++seat) { if((seat->second.flags & (SEAT_FULL | SEAT_VEHICLE_FREE | SEAT_VEHICLE_FULL)) && seat->second.passenger == unit) { unit->SetVehicleGUID(0); if(seat->second.vs_flags & SF_MAIN_RIDER) { RemoveSpellsCausingAura(SPELL_AURA_CONTROL_VEHICLE); if(unit->GetTypeId() == TYPEID_PLAYER) { ((Player*)unit)->SetMover(unit); ((Player*)unit)->SetClientControl(unit, 1); ((Player*)unit)->SetMoverInQueve(NULL); ((Player*)unit)->RemovePetActionBar(); if(((Player*)unit)->GetGroup()) ((Player*)unit)->SetGroupUpdateFlag(GROUP_UPDATE_VEHICLE); } unit->SetCharm(NULL); SetCharmerGUID(NULL); setFaction(GetCreatureInfo()->faction_A); } if(GetVehicleFlags() & VF_NON_SELECTABLE) RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE); if(seat->second.vs_flags & SF_UNATTACKABLE) unit->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE); // restore player control if(unit->GetTypeId() == TYPEID_PLAYER) { ((Player*)unit)->GetCamera().ResetView(); if(seat->second.vs_flags & SF_CAN_CAST) { WorldPacket data0(SMSG_FORCE_MOVE_UNROOT, 10); data0 << unit->GetPackGUID(); data0 << (uint32)(2); // can rotate unit->SendMessageToSet(&data0,true); } else { WorldPacket data1(SMSG_FORCE_MOVE_UNROOT, 10); data1 << unit->GetPackGUID(); data1 << (uint32)(0); // cannot rotate unit->SendMessageToSet(&data1,true); } } unit->m_movementInfo.ClearTransportData(); seat->second.passenger = NULL; seat->second.flags = SEAT_FREE; unit->m_movementInfo.RemoveMovementFlag(MOVEFLAG_ONTRANSPORT); EmptySeatsCountChanged(); break; } } }
int test_image_process_bgr2bgr565() { // Blog: http://blog.csdn.net/fengbingchun/article/details/78995720 #ifdef __linux__ const std::string image_name{ "test_data/images/lena.png" }; #else const std::string image_name{ "E:/GitCode/CUDA_Test/test_data/images/lena.png" }; #endif cv::Mat mat = cv::imread(image_name, 1); CHECK(mat.data); const int width{ 1513 }, height{ 1473 }; cv::resize(mat, mat, cv::Size(width, height)); std::unique_ptr<unsigned char[]> data1(new unsigned char[width * height * 2]), data2(new unsigned char[width * height * 2]); float elapsed_time1{ 0.f }, elapsed_time2{ 0.f }; // milliseconds cv::Mat bgr565; cv::cvtColor(mat, bgr565, cv::COLOR_BGR2BGR565); CHECK(bgr2bgr565_cpu(mat.data, width, height, data1.get(), &elapsed_time1) == 0); CHECK(bgr2bgr565_gpu(mat.data, width, height, data2.get(), &elapsed_time2) == 0); fprintf(stdout, "image bgr to bgr565: cpu run time: %f ms, gpu run time: %f ms\n", elapsed_time1, elapsed_time2); CHECK(compare_result(data1.get(), bgr565.data, width*height * 2) == 0); CHECK(compare_result(data1.get(), data2.get(), width*height*2) == 0); return 0; }
int main (int argc, char **argv) { { MachineLearning::Dataset_f32 dataset; dataset.read(FILENAME); } { MachineLearning::Data_f32 data1(0, 0, "data1"); data1.push_back(MachineLearning::Element_f32 (1, 10)); data1.push_back(MachineLearning::Element_f32 (3, 15)); data1.push_back(MachineLearning::Element_f32 (2, 20)); MachineLearning::Data_f32 data2(0, 0, "data2"); data2.push_back(MachineLearning::Element_f32 (2, 20)); data2.push_back(MachineLearning::Element_f32 (6, 30)); data2.push_back(MachineLearning::Element_f32 (4, 40)); MachineLearning::Dataset_f32 dataset; dataset.push_back(data1); dataset.push_back(data2); std::cout << dataset.getMaxIndexOfElement() << std::endl; std::cout << dataset.getMinIndexOfElement() << std::endl; std::cout << dataset.getMaxValueOfElement() << std::endl; std::cout << dataset.getMinValueOfElement() << std::endl; dataset.write(FILENAME); } return 0; }
void prob2b(){ std::cout << "Problem 2 Part B ======== " << std::endl; Matrix data1(10000,std::vector<double>(2)); Matrix data2(10000,std::vector<double>(2)); loadFile(data1, "sample_data/output1"); loadFile(data2, "sample_data/output3"); Matrix points1 = randSample(data1, 1000); Matrix points2 = randSample(data2, 1000); std::vector<double> mean1 = getSampleMean(points1); std::vector<double> mean2 = getSampleMean(points2); std::cout << "sample_mean1 = "; print_vec(mean1); std::cout << "sample_mean2 = "; print_vec(mean2); Matrix cov1 = getSampleVar(points1, mean1); Matrix cov2 = getSampleVar(points2, mean2); std::cout << "sample_cov1 = "; print_matrix(cov1); std::cout << "sample_cov2 = "; print_matrix(cov2); std::cout << "With estimated params: " << std::endl; QuadraticDiscriminant classifier1(mean1, mean2, cov1, cov2); calcError(classifier1,data1,data2, "sample_data/labels1"); std::cout << std::endl; }
int test_layer_prior_vbox() { // Blog: http://blog.csdn.net/fengbingchun/article/details/77850422 std::vector<float> vec1{423.f, 245.f, 1333.f, 1444.f, 123.f, 23.f, 32.f, 66.f}; std::vector<float> vec2(vec1[6]); std::vector<float> vec3(4); int length = int(vec1[0] * vec1[1] * vec1[6] * 4 * 2); std::unique_ptr<float[]> data1(new float[length]), data2(new float[length]); std::for_each(data1.get(), data1.get() + length, [](float& n) {n = 0.f; }); std::for_each(data2.get(), data2.get() + length, [](float& n) {n = 0.f; }); generator_random_number(vec2.data(), vec2.size(), 10.f, 100.f); generator_random_number(vec3.data(), vec3.size(), 1.f, 10.f); float elapsed_time1{ 0.f }, elapsed_time2{ 0.f }; // milliseconds int ret = layer_prior_vbox_cpu(data1.get(), length, vec1, vec2, vec3, &elapsed_time1); if (ret != 0) PRINT_ERROR_INFO(layer_prior_vbox_cpu); ret = layer_prior_vbox_gpu(data2.get(), length, vec1, vec2, vec3, &elapsed_time2); if (ret != 0) PRINT_ERROR_INFO(layer_prior_vbox_gpu); compare_result(data1.get(), data2.get(), length); fprintf(stderr, "test layer prior vbox: cpu run time: %f ms, gpu run time: %f ms\n", elapsed_time1, elapsed_time2); return 0; }
void InstanceScript::SendEncounterUnit(uint32 type, Unit* unit /*= NULL*/, uint8 param1 /*= 0*/, uint8 param2 /*= 0*/) { switch (type) { case ENCOUNTER_FRAME_ADD: { WorldPacket data1(SMSG_UPDATE_INSTANCE_ENCOUNTER_UNIT, 5); data1 << uint8(0); data1 << uint8(0); data1 << uint8(0); data1 << uint8(0); data1 << uint8(3); instance->SendToPlayers(&data1); WorldPacket data2(SMSG_UPDATE_INSTANCE_ENCOUNTER_UNIT, 13); data2 << uint8(2); data2 << uint8(0); data2 << uint8(0); data2 << uint8(0); data2.append(unit->GetPackGUID()); data2 << uint8(1); instance->SendToPlayers(&data2); } break; case ENCOUNTER_FRAME_REMOVE: { WorldPacket data1(SMSG_UPDATE_INSTANCE_ENCOUNTER_UNIT, 13); data1 << uint8(3); data1 << uint8(0); data1 << uint8(0); data1 << uint8(0); data1.append(unit->GetPackGUID()); data1 << uint8(0); instance->SendToPlayers(&data1); WorldPacket data2(SMSG_UPDATE_INSTANCE_ENCOUNTER_UNIT, 4); data2 << uint8(0); data2 << uint8(0); data2 << uint8(0); data2 << uint8(0); data2 << uint8(3); instance->SendToPlayers(&data2); } break; default: break; } }
void SimpleParagraphWidget::fillListButtons() { KoZoomHandler zoomHandler; zoomHandler.setZoom(1.2); zoomHandler.setDpi(72, 72); KoInlineTextObjectManager itom; KoTextRangeManager tlm; TextShape textShape(&itom, &tlm); textShape.setSize(QSizeF(300, 100)); QTextCursor cursor (textShape.textShapeData()->document()); foreach(const Lists::ListStyleItem &item, Lists::genericListStyleItems()) { QPixmap pm(48,48); pm.fill(Qt::transparent); QPainter p(&pm); p.translate(0, -1.5); p.setRenderHint(QPainter::Antialiasing); if(item.style != KoListStyle::None) { KoListStyle listStyle; KoListLevelProperties llp = listStyle.levelProperties(1); llp.setStyle(item.style); if (KoListStyle::isNumberingStyle(item.style)) { llp.setStartValue(1); llp.setListItemSuffix("."); } listStyle.setLevelProperties(llp); cursor.select(QTextCursor::Document); QTextCharFormat textCharFormat=cursor.blockCharFormat(); textCharFormat.setFontPointSize(11); textCharFormat.setFontWeight(QFont::Normal); cursor.setCharFormat(textCharFormat); QTextBlock cursorBlock = cursor.block(); KoTextBlockData data(cursorBlock); cursor.insertText("----"); listStyle.applyStyle(cursor.block(),1); cursorBlock = cursor.block(); KoTextBlockData data1(cursorBlock); cursor.insertText("\n----"); cursorBlock = cursor.block(); KoTextBlockData data2(cursorBlock); cursor.insertText("\n----"); cursorBlock = cursor.block(); KoTextBlockData data3(cursorBlock); KoTextDocumentLayout *lay = dynamic_cast<KoTextDocumentLayout*>(textShape.textShapeData()->document()->documentLayout()); if(lay) lay->layout(); KoShapePaintingContext paintContext; //FIXME textShape.paintComponent(p, zoomHandler, paintContext); widget.bulletListButton->addItem(pm, static_cast<int> (item.style)); } }
OBV_OBV_TruncatableTest::Extra1::Extra1 ( ::CORBA::ULong _tao_init_basic_data, ::CORBA::ULong _tao_init_data1, ::CORBA::ULong _tao_init_edata1) : require_truncation_ (false) { basic_data (_tao_init_basic_data); data1 (_tao_init_data1); edata1 (_tao_init_edata1); }
static void TestFlate(skiatest::Reporter* reporter, SkMemoryStream* testStream, size_t dataSize) { if (testStream == NULL) return; SkMemoryStream testData(dataSize); uint8_t* data = (uint8_t*)testData.getMemoryBase(); srand(0); // Make data deterministic. for (size_t i = 0; i < dataSize; i++) data[i] = rand() & 0xFF; testStream->setMemory(testData.getMemoryBase(), dataSize, true); SkDynamicMemoryWStream compressed; bool status = SkFlate::Deflate(testStream, &compressed); REPORTER_ASSERT(reporter, status); // Check that the input data wasn't changed. size_t inputSize = testStream->getLength(); if (inputSize == 0) inputSize = testStream->read(NULL, SkZeroSizeMemStream::kGetSizeKey); REPORTER_ASSERT(reporter, testData.getLength() == inputSize); REPORTER_ASSERT(reporter, memcmp(testData.getMemoryBase(), testStream->getMemoryBase(), testData.getLength()) == 0); // Assume there are two test sizes, big and small. if (dataSize < 1024) REPORTER_ASSERT(reporter, compressed.getOffset() < 1024); else REPORTER_ASSERT(reporter, compressed.getOffset() > 1024); SkAutoDataUnref data1(compressed.copyToData()); testStream->setData(data1.get())->unref(); SkDynamicMemoryWStream uncompressed; status = SkFlate::Inflate(testStream, &uncompressed); REPORTER_ASSERT(reporter, status); // Check that the input data wasn't changed. inputSize = testStream->getLength(); if (inputSize == 0) inputSize = testStream->read(NULL, SkZeroSizeMemStream::kGetSizeKey); REPORTER_ASSERT(reporter, data1->size() == inputSize); REPORTER_ASSERT(reporter, memcmp(testStream->getMemoryBase(), data1->data(), data1->size()) == 0); // Check that the uncompressed data matches the source data. SkAutoDataUnref data2(uncompressed.copyToData()); REPORTER_ASSERT(reporter, testData.getLength() == uncompressed.getOffset()); REPORTER_ASSERT(reporter, memcmp(testData.getMemoryBase(), data2->data(), testData.getLength()) == 0); }
void RegressionTest::charComparisonForOccurrence(const std::string& keyword, int occurrence1, int occurrence2) const { ecl_kw_type* ecl_kw1 = nullptr; ecl_kw_type* ecl_kw2 = nullptr; const unsigned int numCells = getEclKeywordData(ecl_kw1, ecl_kw2, keyword, occurrence1, occurrence2); for (size_t cell = 0; cell < numCells; cell++) { std::string data1(ecl_kw_iget_char_ptr(ecl_kw1, cell)); std::string data2(ecl_kw_iget_char_ptr(ecl_kw2, cell)); if (data1.compare(data2) != 0) { printValuesForCell(keyword, occurrence1, occurrence2, cell, data1, data2); OPM_THROW(std::runtime_error, "Values of char type differ."); } } }
int __cdecl wmain() { // Ignoring the return value because we want to continue running even in the // unlikely event that HeapSetInformation fails. HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0); if (SUCCEEDED(CoInitialize(NULL))) { PlotData data1(200); for(size_t i = 0; i < 200; ++i) { data1[i * 2] = i / 200.0f; data1[i * 2 + 1] = pow(i, 1.6f) / 8.0f; } PlotData data2(200); for(size_t i = 0; i < 200; ++i) { data2[i * 2] = i / 200.0f; data2[i * 2 + 1] = i; //data2[100 + i * 2] = 1; //data2[101 + i * 2] = 1; } PlotData data3(200); for(size_t i = 0; i < 200; ++i) { data3[i * 2] = i / 200.0f; data3[i * 2 + 1] = i * 2; } PlotData data4(200); for(size_t i = 0; i < 200; ++i) { data4[i * 2 ] = i / 200.0f; data4[i * 2 + 1] = 0.125f * pow(i, 1.3f); } PlotData *data[] = { &data1, &data2, &data3, &data4, 0 }; HRESULT hr = SaveToImageFile(data, 800, 600, 1.0f, 600.0f, 50.0f, 40.0f, 0.1f, 100.0f); if (FAILED(hr)) { wprintf(L"Unexpected error: 0x%x", hr); } CoUninitialize(); } return 0; }
int U_EXPORT main (int argc, char* argv[]) { U_ULIB_INIT(argv); U_TRACE(5,"main(%d)",argc) UTimeDate data1(31,12,99), data2("31/12/99"); U_ASSERT( UTimeDate("14/09/1752").getJulian() == 2361222 ) U_ASSERT( UTimeDate("31/12/1900").getJulian() == 2415385 ) U_ASSERT( UTimeDate("01/01/1970").getJulian() == 2440588 ) U_ASSERT( data1 == data2 ) U_ASSERT( data1.getDayOfWeek() == 5 ) // Venerdi U_ASSERT( data2.getDayOfYear() == 365 ) U_ASSERT( UTimeDate("1/3/00").getDayOfWeek() == 3 ) // Mercoledi U_ASSERT( UTimeDate(31,12,00).getDayOfYear() == 366 ) UTimeDate data3(60,2000); UTimeDate data4("29/02/00"); U_ASSERT( data3 == data4 ) U_ASSERT( data3.getDayOfYear() == 60 ) UTimeDate data5(60,1901); UTimeDate data6("1/3/1901"); U_ASSERT( data5 == data6 ) U_ASSERT( UTimeDate(17, 5, 2002).isValid() == true ) // TRUE May 17th 2002 is valid U_ASSERT( UTimeDate(30, 2, 2002).isValid() == false ) // FALSE Feb 30th does not exist U_ASSERT( UTimeDate(29, 2, 2004).isValid() == true ) // TRUE 2004 is a leap year UTimeDate data7(29, 2, 2004); UString x = data7.strftime("%Y-%m-%d"); U_ASSERT( x == U_STRING_FROM_CONSTANT("2004-02-29") ) U_ASSERT( UTimeDate("14/09/1752").getJulian() == 2361222 ) cout << "Date: " << data6.strftime("%d/%m/%y") << '\n'; while (cin >> data6) cout << data6 << '\n'; U_ASSERT( UTimeDate::getSecondFromTime("19030314104248Z", true, "%4u%2u%2u%2u%2u%2uZ") < u_now->tv_sec ) }
int main() { AFile_AString file; AOSSessionData data0(ASWNL("ABC123")); data0.toAFile(file); AOSSessionData data1(file); file.debugDump(); std::cout << data0 << std::endl; std::cout << sizeof(data0) << std::endl; std::cout << data1 << std::endl; std::cout << sizeof(data1) << std::endl; return 0; }
void StreamDataBufferTest::test_getWritable() { QByteArray data1("data1"); { // Use case: // getWritable() called with no service data // Expect a valid object with no associate data. StreamDataBuffer buffer("test"); buffer.setDataManager(_dataManager); WritableData data = buffer.getWritable(data1.size()); CPPUNIT_ASSERT( data.isValid() ); data.write(data1.data(),data1.size()); CPPUNIT_ASSERT( data.isValid() ); CPPUNIT_ASSERT_EQUAL(0, static_cast<LockableStreamData*>(data.data())->associateData().size() ); } // Setup data manager with a service data buffer for remaining test cases ServiceDataBuffer* serveBuffer = new ServiceDataBuffer("test"); QString service1("Service1"); _dataManager->setServiceDataBuffer(service1,serveBuffer); { // Use case: // getWritable() called with service data supported, but no data // expect valid object with no associate data StreamDataBuffer b("test"); b.setDataManager(_dataManager); WritableData data = b.getWritable(data1.size()); CPPUNIT_ASSERT( data.isValid() ); data.write(data1.data(),data1.size()); CPPUNIT_ASSERT( data.isValid() ); CPPUNIT_ASSERT_EQUAL(0, static_cast<LockableStreamData*>(data.data())->associateData().size() ); } // inject some data into the service buffer for remaining tests serveBuffer->getWritable(1); _app->processEvents(); { // Use case: // getWritable() called with service data supported, with data // expect valid object with associate data StreamDataBuffer b("test"); b.setDataManager(_dataManager); WritableData data = b.getWritable(data1.size()); CPPUNIT_ASSERT( data.isValid() ); data.write(data1.data(),data1.size()); CPPUNIT_ASSERT( data.isValid() ); CPPUNIT_ASSERT_EQUAL(1, static_cast<LockableStreamData*>(data.data())->associateData().size() ); } }
void TestHelpers() { /* Test helper functions */ // Some constants for testing u32 proto_id = 0x12345678; u16 peer_id = 123; u8 channel = 2; SharedBuffer<u8> data1(1); data1[0] = 100; Address a(127,0,0,1, 10); u16 seqnum = 34352; con::BufferedPacket p1 = con::makePacket(a, data1, proto_id, peer_id, channel); /* We should now have a packet with this data: Header: [0] u32 protocol_id [4] u16 sender_peer_id [6] u8 channel Data: [7] u8 data1[0] */ assert(readU32(&p1.data[0]) == proto_id); assert(readU16(&p1.data[4]) == peer_id); assert(readU8(&p1.data[6]) == channel); assert(readU8(&p1.data[7]) == data1[0]); //infostream<<"initial data1[0]="<<((u32)data1[0]&0xff)<<std::endl; SharedBuffer<u8> p2 = con::makeReliablePacket(data1, seqnum); /*infostream<<"p2.getSize()="<<p2.getSize()<<", data1.getSize()=" <<data1.getSize()<<std::endl; infostream<<"readU8(&p2[3])="<<readU8(&p2[3]) <<" p2[3]="<<((u32)p2[3]&0xff)<<std::endl; infostream<<"data1[0]="<<((u32)data1[0]&0xff)<<std::endl;*/ assert(p2.getSize() == 3 + data1.getSize()); assert(readU8(&p2[0]) == TYPE_RELIABLE); assert(readU16(&p2[1]) == seqnum); assert(readU8(&p2[3]) == data1[0]); }
int test_image_process_laplacian() { // Blog: http://blog.csdn.net/fengbingchun/article/details/79321200 #ifdef __linux__ cv::Mat src = cv::imread("test_data/images/lena.png", 0); #else cv::Mat src = cv::imread("E:/GitCode/CUDA_Test/test_data/images/lena.png", 0); #endif if (!src.data || src.channels() != 1) { fprintf(stderr, "read image fail\n"); return -1; } int width{ 400 }, height{ 400 }; cv::resize(src, src, cv::Size(width, height)); std::unique_ptr<unsigned char[]> data1(new unsigned char[width * height]), data2(new unsigned char[width * height]); float elapsed_time1{ 0.f }, elapsed_time2{ 0.f }; // milliseconds int ksize{ 1 }; CHECK(laplacian_cpu(src.data, width, height, ksize, data1.get(), &elapsed_time1) == 0); //CHECK(laplacian_gpu(src.data, width, height, data2.get(), &elapsed_time2) == 0); //fprintf(stdout, "gray image edge detection: laplacian: cpu run time: %f ms, gpu run time: %f ms\n", elapsed_time1, elapsed_time2); cv::Mat dst; cv::Laplacian(src, dst, src.depth(), ksize); #ifdef __linux__ cv::imwrite("test_data/images/laplacian.png", dst); #else cv::imwrite("E:/GitCode/CUDA_Test/test_data/images/laplacian.png", dst); #endif CHECK(compare_result(data1.get(), dst.data, width*height) == 0); //CHECK(compare_result(data1.get(), data2.get(), width*height) == 0); #ifdef __linux__ save_image(src, dst, width, height / 2, "test_data/images/laplacian_result.png"); #else save_image(src, dst, width, height / 2, "E:/GitCode/CUDA_Test/test_data/images/laplacian_result.png"); #endif return 0; }
std::vector<std::string> * HostnameModule::getDatas(void) { char hname[128] = ""; char uname[128] = ""; std::ostringstream s; if (gethostname(hname, 128)) return this->_datas; if (getlogin_r(uname, 128)) return this->_datas; this->_datas = new std::vector<std::string>; int l = strlen("HOSTNAME"); int pos = static_cast<int>((34 - l) / 2); int i; s.str(std::string()); s << '<'; for (i = 0; i + 1 < pos - 1; i++) { s << '-'; } s << " HOSTNAME "; for (i = pos + l + 2; i < 34; i++) { s << '-'; } s << '>'; std::string name(s.str()); this->_datas->push_back(name); s.clear(); s.str(std::string()); // this->_datas->push_back("<------ Hostname ------>"); s << "Hostname : " << hname; std::string data0(s.str()); this->_datas->push_back(data0); s.clear(); s.str(std::string()); s << "Username : " << uname; std::string data1(s.str()); this->_datas->push_back(data1); return this->_datas; }
void shiftOut(char output, char pin){ outputDisable(pin); for(int i = 0; i <= 7; i++){ int set = (output >> i) & 0x01; if(set == 1){ data1(); } else { data0(); } pulseClock(); } pulseClock(); outputEnable(pin); __delay_us(100); outputDisable(pin); return; }
void ComponentEventTest::testConvertValue() { std::map<std::string, std::string> attributes; attributes["id"] = "1"; attributes["name"] = "DataItemTest1"; attributes["type"] = "ACCELERATION"; attributes["category"] = "SAMPLE"; std::string time("NOW"), value("2.0"); attributes["nativeUnits"] = "REVOLUTION/MINUTE"; DataItem data1 (attributes); ComponentEvent event1(data1, 123, time, value); CPPUNIT_ASSERT_EQUAL(2.0f, event1.getFValue()); CPPUNIT_ASSERT(event1.getSValue().empty()); attributes["nativeUnits"] = "REVOLUTION/SECOND"; DataItem data2 (attributes); ComponentEvent event2 (data2, 123, time, value); CPPUNIT_ASSERT_EQUAL(2.0f * 60.0f, event2.getFValue()); CPPUNIT_ASSERT(event2.getSValue().empty()); attributes["nativeUnits"] = "GRAM/INCH"; DataItem data3 (attributes); ComponentEvent event3 (data3, 123, time, value); CPPUNIT_ASSERT_EQUAL((2.0f / 1000.0f) / 25.4f, event3.getFValue()); CPPUNIT_ASSERT(event3.getSValue().empty()); attributes["nativeUnits"] = "MILLIMETER/MINUTE^3"; DataItem data4 (attributes); ComponentEvent event4 (data4, 123, time, value); CPPUNIT_ASSERT_EQUAL((2.0f) / (60.0f * 60.0f * 60.0f), event4.getFValue()); CPPUNIT_ASSERT(event4.getSValue().empty()); attributes["nativeUnits"] = "MILLIMETER/MINUTE^3"; attributes["nativeScale"] = "0.5"; DataItem data5 (attributes); ComponentEvent event5 (data5, 123, time, value); CPPUNIT_ASSERT_EQUAL((2.0f) / (60.0f * 60.0f * 60.0f * 0.5f), event5.getFValue()); CPPUNIT_ASSERT(event5.getSValue().empty()); }
void Player::DoForgetPlayersInBG(Battleground* pBattleGround) { for (Battleground::BattlegroundPlayerMap::const_iterator itr = pBattleGround->GetPlayers().begin(); itr != pBattleGround->GetPlayers().end(); ++itr) { // Here we invalidate players in the bg to the added player WorldPacket data1(SMSG_INVALIDATE_PLAYER, 8); data1 << itr->first; GetSession()->SendPacket(&data1); if (Player* pPlayer = ObjectAccessor::FindPlayer(itr->first)) { GetSession()->SendNameQueryOpcode(pPlayer->GetGUID()); // Send namequery answer instantly if player is available // Here we invalidate the player added to players in the bg WorldPacket data2(SMSG_INVALIDATE_PLAYER, 8); data2 << GetGUID(); pPlayer->GetSession()->SendPacket(&data2); pPlayer->GetSession()->SendNameQueryOpcode(GetGUID()); } } }
void tappend() { Button Data,Pass; Data.init(221,57,"Data ",FLAT); Data.show( ); Pass.init(221,77,"Password ",FLAT); Pass.show( ); int i= selc(Data,Pass,32,25); if(i==1) { data1(); } else if(i==2) { modif(); } }
int test_image_process_histogram_equalization() { // Blog: http://blog.csdn.net/fengbingchun/article/details/79188021 #ifdef __linux__ const std::string image_name{ "test_data/images/lena.png" }; #else const std::string image_name{ "E:/GitCode/CUDA_Test/test_data/images/lena.png" }; #endif cv::Mat mat = cv::imread(image_name, 0); CHECK(mat.data); const int width{ mat.cols/*1513*/ }, height{ mat.rows/*1473*/ }; cv::resize(mat, mat, cv::Size(width, height)); std::unique_ptr<unsigned char[]> data1(new unsigned char[width * height]), data2(new unsigned char[width * height]); float elapsed_time1{ 0.f }, elapsed_time2{ 0.f }; // milliseconds CHECK(histogram_equalization_cpu(mat.data, width, height, data1.get(), &elapsed_time1) == 0); //CHECK(histogram_equalization_gpu(mat.data, width, height, data2.get(), &elapsed_time2) == 0); //fprintf(stdout, "image histogram equalization: cpu run time: %f ms, gpu run time: %f ms\n", elapsed_time1, elapsed_time2); cv::Mat dst; cv::equalizeHist(mat, dst); #ifdef __linux__ cv::imwrite("test_data/images/histogram_equalization.png", dst); #else cv::imwrite("E:/GitCode/CUDA_Test/test_data/images/histogram_equalization.png", dst); #endif CHECK(compare_result(data1.get(), dst.data, width*height) == 0); //CHECK(compare_result(data1.get(), data2.get(), width*height) == 0); #ifdef __linux__ save_image(mat, dst, width, height/2, "test_data/images/histogram_equalization_result.png"); #else save_image(mat, dst, width, height/2, "E:/GitCode/CUDA_Test/test_data/images/histogram_equalization_result.png"); #endif return 0; }
DEF_TEST(Writer32_data, reporter) { const char* str = "0123456789"; sk_sp<SkData> data0(SkData::MakeWithCString(str)); sk_sp<SkData> data1(SkData::MakeEmpty()); const size_t sizes[] = { SkWriter32::WriteDataSize(nullptr), SkWriter32::WriteDataSize(data0.get()), SkWriter32::WriteDataSize(data1.get()), }; SkSWriter32<1000> writer; size_t sizeWritten = 0; writer.writeData(nullptr); sizeWritten += sizes[0]; REPORTER_ASSERT(reporter, sizeWritten == writer.bytesWritten()); writer.writeData(data0.get()); sizeWritten += sizes[1]; REPORTER_ASSERT(reporter, sizeWritten == writer.bytesWritten()); writer.writeData(data1.get()); sizeWritten += sizes[2]; REPORTER_ASSERT(reporter, sizeWritten == writer.bytesWritten()); auto result(writer.snapshotAsData()); SkReader32 reader(result->data(), result->size()); auto d0(reader.readData()), d1(reader.readData()), d2(reader.readData()); REPORTER_ASSERT(reporter, 0 == d0->size()); REPORTER_ASSERT(reporter, strlen(str)+1 == d1->size()); REPORTER_ASSERT(reporter, !memcmp(str, d1->data(), strlen(str)+1)); REPORTER_ASSERT(reporter, 0 == d2->size()); REPORTER_ASSERT(reporter, reader.offset() == sizeWritten); REPORTER_ASSERT(reporter, reader.eof()); }
void Correlatoin_Pearsn(vector <double> dv1, vector <double> dv2, double &zd, double &probd, double &rs){ // DP d, zd, probd, rs, probrs; int nRows=dv1.size(); int i; Vec_DP data1(nRows),data2(nRows); //double nr array for(i=0;i<nRows;i++) { data1[i]=dv1[i]; } rs=0.; probd=-1.; zd=0.; for(i=0;i<nRows;i++) { data2[i]=dv2[i]; } NR::pearsn(data1,data2,rs,probd,zd); }
// Add new email void api::settings_add_email() { session().load(); // allow only POST if(request().request_method() != "POST") { response().status(404); response().out() << "http POST is only method allowed on this endpoint"; return; } // ensure logged in if(!Pages::logged_in(session())) { json::send("DX-REJECTED", "Must be logged in", response().out()); return; } // ensure we've been given a valid email if(!form::validEmail(request().post("email"))) { json::send("DX-REJECTED", "Not a valid email address", response().out()); return; } // check if email is in use if(db::check_exist::email(db, to_lowercase(request().post("email")))) { json::send("DX-REJECTED", "Email in use", response().out()); return; } // add email to user's account std::pair<std::string, std::string> data1("secondary_email", to_lowercase(request().post("email"))); try { // add the user to the database db::update::user::by_username(db, session().get("USERNAME"), data1); // send email to user telling them email has been added mail::external::notice_new_email(request().post("email"), session().get("USERNAME")); } catch(std::exception &e) { json::send("DX-FAILED", "Server error occurred, please try again", response().out()); return; } // update session session().set("SECONDARY_EMAIL", to_lowercase(request().post("email"))); // added email, return ok json::send("DX-OK", "Email added!", response().out()); return; }