Ejemplo n.º 1
0
Archivo: rng.cpp Proyecto: TRIQS/triqs
// This test that std::random and boost::random are the same for MT and uniform distribution
// Conclusion : the std and boost generator give the same numbers.
// However the uniform_real_distrib differ. Anyway, this is not guaranteed to be implementation dep.
// by the std.
TEST(Random, Mersenne) {

  int seed = 1352;

  std::mt19937 gen(seed);

  // Testing the generator itself
  std::vector<long> result = {869874994,  3205046262, 2119020267, 2669095628, 275633191,  335224535,  1399249061, 4059871834, 1506360241, 2646120513,
                              932791869,  1038906848, 391582322,  2962159196, 1246635690, 589901067,  1065559423, 91395844,   4212208358, 3609786960,
                              2429350836, 614673344,  566349528,  3453660734, 1803951428, 2872537556, 2290263138, 303337700,  1592633174, 918874404,
                              1142687065, 222876524,  2795340428, 2430863508, 634253287,  2430641383, 4085971400, 1898206763, 4124349013, 1443009189,
                              3764761512, 186462643,  3075725912, 331081090,  3404927489, 1600419147, 3150852496, 2733533252, 2808125817, 1223983741,
                              3283812587, 3661621427, 2081695262, 3535349663, 2829108992, 1063226049, 1109558379, 3780004780, 4023168629, 2812834780,
                              1801392963, 3151601571, 1439050999, 2986946488, 1629341800, 3471040045, 135632356,  2852529214, 2486605945, 1895271125,
                              763145322,  132788317,  1803634386, 4063571019, 478127399,  22977226,   3759004003, 1935982873, 2024725320, 3279517291,
                              2588561942, 3364937223, 3236324186, 2508746520, 1305720758, 3713056371, 4291396099, 4172364413, 1255934297, 2575364421,
                              157096516,  567018849,  1964661445, 3336536577, 162680414,  997947546,  2422402185, 234663097,  1843361535, 1752705663};

  for (int i = 0; i < 100; ++i) EXPECT_EQ(result[i], gen());

  // our Mersenne code is different
  // triqs::mc_tools::RandomGenerators::RandMT RAN(seed);
  // for (int i = 0; i < 100; ++i) EXPECT_EQ(result[i], RAN.randomMT());

  boost::mt19937 gb(seed);
  for (int i = 0; i < 100; ++i) EXPECT_EQ(result[i], gb());
}
Ejemplo n.º 2
0
Archivo: rng.cpp Proyecto: TRIQS/triqs
TEST(Random, MersenneUniform) {

  int seed = 1352;

  std::mt19937 gen(seed);
  std::mt19937 gen2(seed);
  std::uniform_real_distribution<double> generator;

  // Testing the uniform distribution of the std lib
  std::vector<double> result = {
     0.746232984169,   0.6214472531558, 0.07805054426756, 0.9452625723383,  0.6160979423092,  0.2418893501668,  0.6896814322311, 0.1373470451893,
     0.02127975324357, 0.8404690215785, 0.1431147904521,  0.80411805169,    0.6688147681812,  0.07062631205964, 0.2139421190067, 0.0518924846002,
     0.5659795153539,  0.56592779773,   0.4419607026389,  0.3359767584969,  0.04341421739118, 0.07708582345306, 0.3726266202966, 0.6364503066832,
     0.2849809223911,  0.8525376738432, 0.8231377376906,  0.2475516054916,  0.8801009460023,  0.6549141325375,  0.7337894224141, 0.6954526734387,
     0.808164487914,   0.6641562129444, 0.4412771960671,  0.03091718935819, 0.9461238559848,  0.00534980234488, 0.4507561386272, 0.7635721218473,
     0.7834604996263,  0.5841130671914, 0.8645133048538,  0.9714542920699,  0.5996237558528,  0.1320193635851,  0.7768479589041, 0.2323527694768,
     0.05463676004764, 0.408083587752,  0.6369825399466,  0.5685970584032,  0.1235360900372,  0.9202423981236,  0.7115838618262, 0.02983485111151,
     0.76981373137,    0.0867099417063, 0.07104946619888, 0.6242631153853,  0.9333818935535,  0.2555663074641,  0.5992051313843, 0.5401568983755,
     0.7769657207188,  0.1981726659902, 0.1661893182446,  0.834562142064,   0.9424356488108,  0.04133228686251, 0.4650720410434, 0.07820202766968,
     0.9884859219395,  0.1590063209914, 0.6488666015855,  0.7387352915971,  0.7585917578883,  0.5503377983743,  0.9244397353327, 0.6447530066677,
     0.6129745757522,  0.2542404394466, 0.2026888834774,  0.2527748172769,  0.6740506770768,  0.9107106919416,  0.6213113793034, 0.1554119577284,
     0.7805296694581,  0.660779124941,  0.7750959913801,  0.0938933767948,  0.6609784932051,  0.6148894861399,  0.4792942971708, 0.6545062197143,
     0.6110897641314,  0.3611626664627, 0.2771070578171,  0.5601750233273};

  //std::cout<< std::setprecision(13);
  for (int i = 0; i < 100; ++i)
    //std::cout  << ", "<<generator(gen);
    EXPECT_NEAR(result[i], generator(gen), 1.e-12);

  // boost
  boost::uniform_real<> dis;
  boost::variate_generator<boost::mt19937, boost::uniform_real<>> gb(boost::mt19937(seed), dis);

  // the std uniform distrib takes one number over 2 ?!
  gb();
  gen2();
  std::cout << std::setprecision(13);
  for (int i = 0; i < 100; ++i, gb(), gen2()) {
    double x = gb();
    std::cout << result[i] - x << " " << x << "  " << x - double(gen2()) / (double(gen2.max()) + 1) << std::endl;
    //EXPECT_NEAR(result[i], gb(), 1.e-12);
  }

  std::cout << "min " << gen.min() << " max " << gen.max() << std::endl;

  //triqs::mc_tools::RandomGenerators::RandMT RAN(seed);
  //for (int i = 0; i < 100; ++i) EXPECT_EQ(result[i], RAN());
}
Ejemplo n.º 3
0
int main(int argc, char* argv[])
{
	GraphBuilder gb(argv[1], true);
	std::string malware_program(argv[2]);

	int num_files = 0;
	std::ifstream bf(argv[3]);
	std::string tmp_string;
	std::vector<std::string> benign_programs;
	std::vector<Graph*> malspecs;

	bf>>num_files;
	std::getline(bf, tmp_string);
	for(int i = 0; i < num_files; i++) {
		std::getline(bf, tmp_string);
		benign_programs.push_back(tmp_string);
	}

	malspecs = malspec_mining(gb, malware_program, benign_programs);
	std::cout<<std::endl<<"Malspecs found:"<<std::endl;
	for(unsigned int i = 0; i < malspecs.size(); i++) {
		std::cout<<"Malspec "<<i<<std::endl;
		std::cout<<*malspecs[i]<<std::endl;
	}

	for(unsigned int i = 0; i < malspecs.size(); i++)
		delete malspecs[i];
	return 0;
}
Ejemplo n.º 4
0
Archivo: main.cpp Proyecto: mjkoo/mjkgb
int
main(int argc, char **argv)
{
    mjkgb::Gameboy gb("");

    return 0;
}
Ejemplo n.º 5
0
double time_gpu_multiply() {
    mean_delta_time = 0;
    cv::randu(a, cv::Scalar(0), cv::Scalar(100));
    cv::randu(b, cv::Scalar(0), cv::Scalar(100));
    
    cv::cuda::GpuMat ga(2048, 2048, CV_32F);
    cv::cuda::GpuMat gb(2048, 2048, CV_32F);

    ga.upload(a);
    gb.upload(b);

    // transfer both the gpu
    for (int i=0; i < N; i++) {
        gettimeofday(&start_time, NULL);

        cv::cuda::multiply(ga, gb, gb);

        gettimeofday(&end_time, NULL);
        timersub(&end_time, &start_time, &delta_times[i]);
        std::cout << "gpu: multiply took: " << (delta_times[i].tv_usec + 1000000 * delta_times[i].tv_sec) / 1000. << std::endl;
        mean_delta_time += (delta_times[i].tv_usec + 1000000 * delta_times[i].tv_sec) / 1000.;

    }

    mean_delta_time /= N;
    std::cout << "gpu: mean time: " << mean_delta_time << std::endl;
    return mean_delta_time;
}
Ejemplo n.º 6
0
HRESULT CMpeg2DataParser::ParsePMT(CDVBChannel& Channel)
{
    HRESULT hr;
    CComPtr<ISectionList> pSectionList;
    DWORD dwLength;
    PSECTION data;
    WORD wTSID;
    WORD wSectionLength;

    Channel.SetVideoFps(DVB_FPS_NONE);
    Channel.SetVideoChroma(DVB_Chroma_NONE);

    CheckNoLog(m_pData->GetSection((PID)Channel.GetPMT(), SI_PMT, &m_Filter, 15000, &pSectionList));
    CheckNoLog(pSectionList->GetSectionData(0, &dwLength, &data));

    CGolombBuffer gb((BYTE*)data, dwLength);

    // TS_program_map_section()
    CheckNoLog(ParseSIHeader(gb, SI_PMT, wSectionLength, wTSID));

    gb.BitRead(3);                                              // reserved
    Channel.SetPCR((ULONG)gb.BitRead(13));                      // PCR_PID
    gb.BitRead(4);                                              // reserved
    BeginEnumDescriptors(gb, nType, nLength) {                  // for (i=0;i<N;i++) {
        SkipDescriptor(gb, nType, nLength);                     // descriptor()
    }
Ejemplo n.º 7
0
HRESULT CMpeg2DataParser::ParsePAT()
{
    HRESULT hr;
    CComPtr<ISectionList> pSectionList;
    DWORD dwLength;
    PSECTION data;
    WORD wTSID;
    WORD wSectionLength;

    CheckNoLog(m_pData->GetSection(PID_PAT, SI_PAT, &m_Filter, 15000, &pSectionList));
    CheckNoLog(pSectionList->GetSectionData(0, &dwLength, &data));

    CGolombBuffer gb((BYTE*)data, dwLength);

    // program_association_section()
    CheckNoLog(ParseSIHeader(gb, SI_PAT, wSectionLength, wTSID));
    while (gb.GetSize() - gb.GetPos() > 4) {
        WORD program_number = (WORD)gb.BitRead(16);         // program_number
        gb.BitRead(3);                                      // reserved
        if (program_number == 0) {
            gb.BitRead(13);                                 // network_PID
        } else {
            WORD program_map_PID = (WORD)gb.BitRead(13);    // program_map_PID
            if (Channels.Lookup(program_number)) {
                Channels [program_number].SetPMT(program_map_PID);
                ParsePMT(Channels [program_number]);
            }
        }
    }

    return S_OK;
}
Ejemplo n.º 8
0
int main(void){
  const int vecSize = 128;

  // Alloc & init input data
  Concurrency::extent<1> e(vecSize);
  Concurrency::tiled_extent<16> et(e);
  Concurrency::tiled_extent<16> et2 = e.tile<16>();
  assert(et.tile_dim0 == 16);
  assert(et2.tile_dim0 == 16);
  Concurrency::array<int, 1> a(vecSize);
  Concurrency::array<int, 1> b(vecSize);
  Concurrency::array<int, 1> c(vecSize);
  int sum = 0;
  for (Concurrency::index<1> i(0); i[0] < vecSize; i++) {
    a[i] = 100.0f * rand() / RAND_MAX;
    b[i] = 100.0f * rand() / RAND_MAX;
    sum += a[i] + b[i];
  }

  Concurrency::array_view<int> ga(a);
  Concurrency::array_view<int> gb(b);
  Concurrency::array_view<int> gc(c);
  Concurrency::parallel_for_each(
    et,
    [=](Concurrency::tiled_index<16> idx) restrict(amp) {
    gc[idx] = ga[idx]+gb[idx];
  });
Ejemplo n.º 9
0
int main(int argc, char *argv[])
{
#if defined(Q_WS_X11)
    QApplication::setGraphicsSystem("raster");
#elif defined (Q_WS_WIN)
    qputenv("QML_ENABLE_TEXT_IMAGE_CACHE", "true");
#endif

#if defined(Q_WS_S60)
    QApplication app(argc, argv);
#else
    // Check for single running instance    
    QtSingleApplication app(argc, argv);
    if (app.isRunning()) {
        app.sendMessage("FOREGROUND");
        return 0;
    }
#endif

    DuktoWindow viewer;
#ifndef Q_WS_S60
    app.setActivationWindow(&viewer, true);
#endif
    GuiBehind gb(&viewer);
    viewer.showExpanded();
    app.installEventFilter(&gb);

    return app.exec();
}
Ejemplo n.º 10
0
//-------------------------------------------------------------------------------------------------
void ConsoleMenu::EditMsg(tty_save_state& tty, const FieldTable::Pair *fld, Message *msg) const
{
	string txt;
	int rval(-1);
	if (fld->_value._rlm)
		rval = SelectRealm(fld->_key, fld->_value._rlm);
	else
	{
		_os << endl << fld->_value._name << ": " << flush;
		GetString(tty, txt);
		if (msg->get_fp().is_group(fld->_key))
		{
			int cnt(GetValue<int>(txt));
			GroupBase *gb(msg->find_group(fld->_key));
			if (gb && cnt)
			{
				for (int ii(0); ii < cnt; ++ii)
				{
					Message *gmsg(static_cast<Message *>(gb->create_group()));
					const FieldTable::Pair *fld;
					while((fld = SelectField(gmsg, ii + 1)))
						EditMsg(tty, fld, gmsg);
					_os << endl << endl << *static_cast<MessageBase *>(gmsg) << endl;
					if (get_yn("Add group to msg? (y/n):", true))
						*gb += gmsg;
				}
			}
		}
	}

	BaseField *bf(fld->_value._create(txt, fld->_value._rlm, rval));
	msg->add_field(bf->get_tag(), msg->get_fp().get_presence().end(), 0, bf, true);
}
Ejemplo n.º 11
0
//-------------------------------------------------------------------------------------------------
// copy all fields from this message to 'to' where the field is legal for 'to' and it is not
// already present in 'to'; includes repeating groups;
// if force, copy all fields regardless, replacing any existing, adding any new
unsigned MessageBase::copy_legal(MessageBase *to, bool force) const
{
	unsigned copied(0);
	for (Presence::const_iterator itr(_fp.get_presence().begin()); itr != _fp.get_presence().end(); ++itr)
	{
		if (itr->_field_traits & FieldTrait::present && (force || (to->_fp.has(itr->_fnum) && !to->_fp.get(itr->_fnum))))
		{
			if (itr->_field_traits & FieldTrait::group)
			{
				GroupBase *gb(find_group(itr->_fnum)), *gb1(to->find_group(itr->_fnum));

				for (GroupElement::const_iterator gitr(gb->_msgs.begin()); gitr != gb->_msgs.end(); ++gitr)
				{
					MessageBase *grc(gb1->create_group());
					(*gitr)->copy_legal(grc, force);
					*gb1 += grc;
				}
			}

			BaseField *nf(get_field(itr->_fnum)->copy());
#if defined POPULATE_METADATA
			to->check_set_rlm(nf);
#endif
			Presence::const_iterator fpitr(_fp.get_presence().end());
			if (force && to->_fp.get(itr->_fnum, fpitr, FieldTrait::present))
				delete to->replace(itr->_fnum, fpitr, nf);
			else
				to->add_field(nf);
			++copied;
		}
	}

	return copied;
}
Ejemplo n.º 12
0
int main(void){
  const int vecSize = 1280;
#define TILE 128
  // Alloc & init input data
  Concurrency::extent<1> e(vecSize);
  Concurrency::tiled_extent<TILE> et(e);
  Concurrency::tiled_extent<TILE> et2 = e.tile<TILE>();
  assert(et.tile_dim0 == TILE);
  assert(et2.tile_dim0 == TILE);
  Concurrency::array<int, 1> a(vecSize);
  Concurrency::array<int, 1> b(vecSize);
  Concurrency::array<int, 1> c(vecSize);
  int sum = 0;
  Concurrency::array_view<int> ga(a);
  Concurrency::array_view<int> gb(b);
  Concurrency::array_view<int> gc(c);
  for (Concurrency::index<1> i(0); i[0] < vecSize; i++) {
    ga[i] = 100.0f * rand() / RAND_MAX;
    gb[i] = 100.0f * rand() / RAND_MAX;
    sum += a[i] + b[i];
  }

  Concurrency::parallel_for_each(
    et,
    [=](Concurrency::tiled_index<TILE> idx) restrict(amp) {
    tile_static int shm[TILE];
    shm[idx.local[0]] = ga[idx];
    idx.barrier.wait();
    gc[idx] = shm[(TILE-1)-idx.local[0]]+gb[idx];
  });
Ejemplo n.º 13
0
std::vector<NS_CORE W> CalcKinCharacteristics::calcW(const NS_CORE Code code, const NS_CORE InternalGearRatios& intRatios, const NS_CORE Z& tooth)
{
	const auto n = intRatios.size();
	std::vector<NS_CORE W> ret;

	GearBoxWithChangerSpecialFrictionProcess gb( code );
	gb.createChains();

	do
	{
		NS_CORE MappedSystem_p systemW = NS_CORE MappedSystem::createW( gb.getChainsForCurrentGear(), intRatios, s_inVelocity );
		NS_CORE Gaus::solve( systemW );

		auto solution = systemW->getSolution();

		for ( NS_CORE GearSetNumber set( 1 ); set <= NS_CORE GearSetNumber( n ); ++set )
		{
			const auto k = intRatios[set.getValue() - 1].getValue();
			const auto w3 = solution[NS_CORE Element(NS_CORE eMainElement::CARRIER, set)];
			const auto w1 = solution[NS_CORE Element(NS_CORE eMainElement::SUN_GEAR, set)];
			if (k < 0)
				solution[NS_CORE Element(NS_CORE eMainElement::SATTELITE, set)] = 2.0f * (w1 - w3) / (k + 1);
			else
				solution[NS_CORE Element(NS_CORE eMainElement::SATTELITE, set)] = 0;
		}

		ret.push_back( solution );

	} while ( gb.turnOnNextGear() );


	return ret;
}
Ejemplo n.º 14
0
int main (void)
{
	int num1, num2, gy_m, gb_m;
	puts("Please enter two numbers:");
	scanf ("%d %d", &num1, &num2);
	gy_m = gy(num1, num2);
	gb_m = gb(num1, num2, gy_m);
	printf ("%d和%d的最小公倍数为%d; 最大公约数为%d;\n", num1, num2,
		 gb_m, gy_m);
	return 0;
}
Ejemplo n.º 15
0
TEST(GapBuffer, test_capacity_01) {
    const int growthSize = 1;
    GapBuffer<int> gb(growthSize);
    ASSERT_EQ(0, gb.size());
    int capacity = gb.capacity();
    ASSERT_EQ(growthSize, capacity);
    int val = 123;
    gb.push_back(val);
    ASSERT_EQ(growthSize, gb.capacity()); // not yet grow
    gb.push_back(val);
    ASSERT_LT(growthSize * 2, gb.capacity()); // has been grown
}
Ejemplo n.º 16
0
TEST(GapBuffer, test_insert_b_04) {
    const int growthSize = 1;
    GapBuffer<int> gb(growthSize);
    ASSERT_EQ(0, gb.size());
    int pos = 0;
    int val = 123;
    int num = 200;
    gb.insert(pos, num, val);
    ASSERT_EQ(num, gb.size());
    for (int i = 0; i < gb.size(); i++) {
        ASSERT_EQ(val, gb[i]);
    }
}
Ejemplo n.º 17
0
Archivo: odbc.c Proyecto: kevinarpe/kx
K eval(K x,K y,K z){K*k;S*b,s;SQLULEN w;SQLLEN*nb;SQLINTEGER*wb;H*tb,u,t,j=0,p,m;F f;C c[128];I n=xj<0;D d=d1(n?-xj:xj);U(d)x=y;Q(z->t!=-KJ||xt!=-KS&&xt!=KC,"type")
 if(z->j)SQLSetStmtAttr(d,SQL_ATTR_QUERY_TIMEOUT,(SQLPOINTER)(SQLULEN)z->j,0);
 if(xt==-KS)Q1(SQLColumns(d,(S)0,0,(S)0,0,xs,S0,(S)0,0))else{I e;K q=kpn(xG,xn);ja(&q,"\0");e=SQLExecDirect(d,q->G0,xn);r0(q);Q1(e)}
 SQLNumResultCols(d,&j);P(!j,(d0(d),knk(0)))
 b=malloc(j*SZ),tb=malloc(j*2),wb=malloc(j*SZ),nb=malloc(j*SZ),x=ktn(KS,j),y=ktn(0,j);// sqlserver: no bind past nonbind
 DO(j,Q1(SQLDescribeCol(d,(H)(i+1),c,128,&u,&t,&w,&p,&m))xS[i]=sn(c,u);
if(t>90)t-=82;
Q(t<-11||t>12,xS[i])wb[i]=ut[tb[i]=t=t>0?t:12-t]==KS&&w?w+1:wt[t];if(ut[t]==KS&&(n||!wb[i]||wb[i]>9))tb[i]=13)
 DO(j,kK(y)[i]=ktn(ut[t=tb[i]],0);if(w=wb[i])Q1(SQLBindCol(d,(H)(i+1),ct[t],b[i]=malloc(w),w,nb+i)))
 for(;SQL_SUCCEEDED(SQLFetch(d));)DO(j,k=kK(y)+i;u=ut[t=tb[i]];s=b[i];n=SQL_NULL_DATA==(int)nb[i];
if(!u)jk(k,n?ktn(ct[t]?KC:KG,0):wb[i]?kp(s):gb(d,(H)(i+1),t));
else ja(k,n?nu(u):u==KH&&wb[i]==1?(t=(H)*s,(S)&t):u==KS?(s=dtb(s,nb[i]),(S)&s):u<KD?s:u==KZ?(f=ds(s)+(vs(s+6)+*(I*)(s+12)/1e9)/8.64e4,(S)&f):(w=u==KD?ds(s):vs(s),(S)&w))) 
 if(!SQLMoreResults(d))O("more\n");DO(j,if(wb[i])free(b[i]))R free(b),free(tb),free(wb),free(nb),d0(d),xT(xD(x,y));}
Ejemplo n.º 18
0
TEST(GapBuffer, test_constructor_b_01) {
    const int growthSize = 4;
    GapBuffer<int> gb(growthSize);
    ASSERT_EQ(0, gb.size());
    ASSERT_EQ(growthSize, gb.capacity());
    int val = 123;
    for (int i = 0; i < growthSize; i++) {
        gb.push_back(val);
    }
    ASSERT_EQ(growthSize, gb.capacity());
    gb.push_back(val);
    ASSERT_LT(growthSize, gb.capacity());
    ASSERT_LE(growthSize * 2, gb.capacity());
}
Ejemplo n.º 19
0
TEST(GapBuffer, test_capacity_02) {
    const int growthSize = 1;
    GapBuffer<int> gb(growthSize);
    ASSERT_EQ(0, gb.size());
    int capacity = gb.capacity();
    ASSERT_EQ(growthSize, capacity);
    int pos = 0;
    int val = 123;
    int num = 100;
    gb.insert(pos , num, val);
    ASSERT_EQ(num, gb.size());
    ASSERT_LT(growthSize * num, gb.capacity());
    ASSERT_LT(gb.size(), gb.capacity());
}
Ejemplo n.º 20
0
    void OnPaint(wxPaintEvent& WXUNUSED(event))
    {
        wxPaintDC dc(this);
        wxScopedPtr<wxGraphicsContext> gc(wxGraphicsContext::Create(dc));
        wxGraphicsBitmap gb(gc->CreateBitmapFromImage(m_image));

        gc->SetFont(*wxNORMAL_FONT, *wxBLACK);
        gc->DrawText("Bitmap", 0, HEIGHT/2);
        gc->DrawBitmap(m_bitmap, 0, 0, WIDTH, HEIGHT);

        wxGraphicsFont gf = gc->CreateFont(wxNORMAL_FONT->GetPixelSize().y, "");
        gc->SetFont(gf);
        gc->DrawText("Graphics bitmap", 0, (3*HEIGHT)/2);
        gc->DrawBitmap(gb, 0, HEIGHT, WIDTH, HEIGHT);
    }
Ejemplo n.º 21
0
void CompositionObject::RenderDvb(SubPicDesc& spd, SHORT nX, SHORT nY)
{
    if(m_pRLEData)
    {
        CGolombBuffer	gb(m_pRLEData, m_nRLEDataSize);
        SHORT			sTopFieldLength;
        SHORT			sBottomFieldLength;

        sTopFieldLength		= gb.ReadShort();
        sBottomFieldLength	= gb.ReadShort();

        DvbRenderField(spd, gb, nX, nY,   sTopFieldLength);
        DvbRenderField(spd, gb, nX, nY + 1, sBottomFieldLength);
    }
}
Ejemplo n.º 22
0
 void monitorTimeouts(HBClients& clients, HBMap& lastHeartbeats, SocketRouter& router, uint msTimeout)
 {
   for (auto addr : clients)
   {
     auto msElapsed = std::chrono::duration_cast < std::chrono::milliseconds > (hrc::now() - lastHeartbeats[addr]).count();
     if (msElapsed > msTimeout)
     {
       stateline::comms::Message gb( { addr }, stateline::comms::GOODBYE);
       VLOG(1) << "Heartbeat system sending GOODBYE on behalf of " << addr;
       router.send(SocketID::HEARTBEAT, Message( { addr }, stateline::comms::GOODBYE));
       clients.erase(clients.find(addr));
       lastHeartbeats.erase(addr);
     }
   }
 }
Ejemplo n.º 23
0
void CompositionObject::RenderDvb(SubPicDesc& spd, short nX, short nY)
{
    if (!m_pRLEData) {
        return;
    }

    CGolombBuffer gb(m_pRLEData, m_nRLEDataSize);
    short sTopFieldLength;
    short sBottomFieldLength;

    sTopFieldLength    = gb.ReadShort();
    sBottomFieldLength = gb.ReadShort();

    DvbRenderField(spd, gb, nX, nY,     sTopFieldLength);
    DvbRenderField(spd, gb, nX, nY + 1, sBottomFieldLength);
}
Ejemplo n.º 24
0
TEST(GapBuffer, test_insert_c_03) {
    const int growthSize = 1;
    GapBuffer<int> gb(growthSize);
    ASSERT_EQ(0, gb.size());
    int num = 200;
    int pos = 0;
    int array[num];
    for (int i = 0; i < num; i++) {
        array[i] = i;
    }
    gb.insert(pos, array, array + num);
    ASSERT_EQ(num, gb.size());
    for (int i = 0; i < gb.size(); i++) {
        ASSERT_EQ(i, gb[i]);
    }
}
Ejemplo n.º 25
0
int main(int argc, char** argv)
{
  if (argc != 2)
  {
    extern char* __progname; /* from crt0.o */
    std::cerr << "usage: " << __progname << " ROM" << std::endl;
    return 1;
  }

  /* open the rom */
  gbemu::utils::mapped_file rom(argv[1]);
  rom.map();

  /* create the emulator and run */
  gbemu::gb gb(rom);
  gb.run();
}
Ejemplo n.º 26
0
void 
PFEMElement2DBubble::getdL(const Vector& p, Matrix& dl) const {
    Matrix gb(2,3);
    getGbub(gb);

    double invmb = getinvMbub();

    getdGbt(gb*p*invmb, dl);

    Matrix dmb(2,6);
    getdinvMbub(gb*p, dmb);

    dl.addMatrixTransposeProduct(1.0,gb,dmb,1.0);
            
    Matrix dgb(2,6);
    getdGb(p,dgb);
    dl.addMatrixTransposeProduct(1.0,gb,dgb,invmb);
}
Ejemplo n.º 27
0
status_t Camera3StreamSplitter::attachBufferToOutputs(ANativeWindowBuffer* anb,
        const std::vector<size_t>& surface_ids) {
    ATRACE_CALL();
    status_t res = OK;

    Mutex::Autolock lock(mMutex);

    sp<GraphicBuffer> gb(static_cast<GraphicBuffer*>(anb));
    uint64_t bufferId = gb->getId();

    // Initialize buffer tracker for this input buffer
    auto tracker = std::make_unique<BufferTracker>(gb, surface_ids);

    for (auto& surface_id : surface_ids) {
        sp<IGraphicBufferProducer>& gbp = mOutputs[surface_id];
        int slot = BufferItem::INVALID_BUFFER_SLOT;
        //Temporarly Unlock the mutex when trying to attachBuffer to the output
        //queue, because attachBuffer could block in case of a slow consumer. If
        //we block while holding the lock, onFrameAvailable and onBufferReleased
        //will block as well because they need to acquire the same lock.
        mMutex.unlock();
        res = gbp->attachBuffer(&slot, gb);
        mMutex.lock();
        if (res != OK) {
            SP_LOGE("%s: Cannot acquireBuffer from GraphicBufferProducer %p: %s (%d)",
                    __FUNCTION__, gbp.get(), strerror(-res), res);
            return res;
        }
        auto& outputSlots = *mOutputSlots[gbp];
        if (outputSlots[slot] != nullptr) {
            // If the buffer is attached to a slot which already contains a buffer,
            // the previous buffer will be removed from the output queue. Decrement
            // the reference count accordingly.
            decrementBufRefCountLocked(outputSlots[slot]->getId(), gbp);
        }
        SP_LOGV("%s: Attached buffer %p to slot %d on output %p.",__FUNCTION__, gb.get(),
                slot, gbp.get());
        outputSlots[slot] = gb;
    }

    mBuffers[bufferId] = std::move(tracker);

    return res;
}
Ejemplo n.º 28
0
std::vector<NS_CORE M> ari::CalcKinCharacteristics::calcM( const NS_CORE Code code, const NS_CORE InternalGearRatios& intRatios )
{
	std::vector<NS_CORE M> ret;

	GearBoxWithChangerSpecialFrictionProcess gb( code );
	gb.createChains();

	do
	{
		NS_CORE MappedSystem_p systemM = NS_CORE MappedSystem::createM( gb.getChainsForCurrentGear(), intRatios, s_inTorque );
		NS_CORE Gaus::solve( systemM );

		ret.push_back( systemM->getSolution() );

	} while ( gb.turnOnNextGear() );


	return ret;
}
Ejemplo n.º 29
0
NS_CORE InternalGearRatios DefKNuton::findK( const NS_CORE Code& code, const NS_CORE InternalGearRatios& initialKValues, const NS_CORE Ratios& iTarget )
{
	System system;
	system.init( initialKValues );

	NS_CORE GearBoxWithChanger gb( code );
	gb.createChains();

	int i = 0;
	do
	{
		system.addGearChains( gb.getChainsForCurrentGear(), NS_CORE GearNumber( i + 1 ), iTarget[i] );
		i++;
	} while ( gb.turnOnNextGear() );

	auto jacobian = createJacobian( system );

	return solveNuton( jacobian, system );
}
Ejemplo n.º 30
0
	int      Make(String& s) const {
		static ScreenDraw w;
		w.SetFont(fc.fnt);
		GLYPHMETRICS gm;
		MAT2 m_matrix;
	    memset(&m_matrix, 0, sizeof(m_matrix));
	    m_matrix.eM11.value = 1;
	    m_matrix.eM22.value = 1;
   		s.Clear();
		int gsz = GetGlyphOutlineW(w.GetHandle(), fc.chr, GGO_NATIVE, &gm, 0, NULL, &m_matrix);
		if(gsz < 0)
			return 0;
		StringBuffer gb(gsz);
		gsz = GetGlyphOutlineW(w.GetHandle(), fc.chr, GGO_NATIVE, &gm, gsz, ~gb, &m_matrix);
		if(gsz < 0)
			return 0;
		s = gb;
		return gsz;
	}