Exemple #1
0
static void
_fop1d(jit_state_t *_jit, jit_int32_t op,
       jit_int32_t r0, jit_int32_t r1, jit_float64_t *i0)
{
    jit_int32_t		reg;
    reg = jit_get_reg(jit_class_fpr);
    movi_d(rn(reg), i0);
    FPop1(r0, r1, op, rn(reg));
    jit_unget_reg(reg);
}
Exemple #2
0
static void
_stxi_d(jit_state_t *_jit, jit_word_t i0, jit_int32_t r0, jit_int32_t r1)
{
    jit_int32_t		reg;
    if (s13_p(i0))
	STDFI(r1, r0, i0);
    else {
	reg = jit_get_reg(jit_class_gpr);
	movi(rn(reg), i0);
	stxr_d(rn(reg), r0, r1);
	jit_unget_reg(reg);
    }
}
Exemple #3
0
static void
_ldxi_d(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0)
{
    jit_int32_t		reg;
    if (s13_p(i0))
	LDDFI(r1, i0, r0);
    else {
	reg = jit_get_reg(jit_class_gpr);
	movi(rn(reg), i0);
	ldxr_d(r0, r1, rn(reg));
	jit_unget_reg(reg);
    }
}
Exemple #4
0
static void
_sti_f(jit_state_t *_jit, jit_word_t i0, jit_int32_t r0)
{
    jit_int32_t		reg;
    if (s13_p(i0))
	STFI(r0, 0, i0);
    else {
	reg = jit_get_reg(jit_class_gpr);
	movi(rn(reg), i0);
	str_f(rn(reg), r0);
	jit_unget_reg(reg);
    }
}
Exemple #5
0
static void
_dcw(jit_state_t *_jit, jit_int32_t cc,
     jit_int32_t r0, jit_int32_t r1, jit_float64_t *i0)
{
    jit_int32_t		reg;
    reg = jit_get_reg(jit_class_fpr);
    movi_d(rn(reg), i0);
    FCMPD(r1, rn(reg));
    jit_unget_reg(reg);
    FBa(cc, 3);
    movi(r0, 1);
    movi(r0, 0);
}
Exemple #6
0
ADDS
#undef X

#undef HEADER_ARG
#undef HEADER_NONE

#undef BODY_ARG
#undef BODY_NONE

#undef ADDS

void Assembler::addi(const Reg64& rt, const Reg64& ra, Immed imm) {
  assert(imm.fits(HPHP::sz::word) && "Immediate is too big");
  EmitDForm(14, rn(rt), rn(ra), imm.w());
}
Exemple #7
0
Spectrum DensityRegion::tau(const Ray &r, float stepSize,
                            float u) const {
    float t0, t1;
    float length = r.d.Length();
    if (length == 0.f) return 0.f;
    Ray rn(r.o, r.d / length, r.mint * length, r.maxt * length, r.time);
    if (!IntersectP(rn, &t0, &t1)) return 0.;
    Spectrum tau(0.);
    t0 += u * stepSize;
    while (t0 < t1) {
        tau += sigma_t(rn(t0), -rn.d, r.time);
        t0 += stepSize;
    }
    return tau * stepSize;
}
Exemple #8
0
static jit_word_t
_dbw(jit_state_t *_jit, jit_int32_t cc,
     jit_word_t i0, jit_int32_t r0, jit_float64_t *i1)
{
    jit_word_t		w;
    jit_int32_t		reg;
    reg = jit_get_reg(jit_class_fpr);
    movi_d(rn(reg), i1);
    FCMPD(r0, rn(reg));
    jit_unget_reg(reg);
    w = _jit->pc.w;
    FB(cc, (i0 - w) >> 2);
    NOP();
    return (w);
}
Exemple #9
0
	std::string OGL4ShaderCompiler::AdjustLog(const std::string& log, const std::vector<IncludeInfo>& inc_list)
	{
		std::regex r("\\([0-9]+\\)");
		std::sregex_iterator first(log.begin(), log.end(), r);
		std::sregex_iterator last;

		std::string s = first->str();

		std::regex rn("[0-9]+");
		std::sregex_iterator rn_first(s.begin(), s.end(), rn);
		std::sregex_iterator rn_last;

		s = rn_first->str();

		int line = strtol(s.c_str(), nullptr, 10);

		std::string result;

		int totals = 0;

		for(size_t i = 0; i < inc_list.size(); ++i)
		{
			if(line <= inc_list[i].lines)
			{
				result = inc_list[i].file.string() + "(" + boost::lexical_cast<std::string>(line) + "):";
				break;
			}
			line -= inc_list[i].lines;
		}

		return result + log.substr(s.length() + 5);
	}
int main()
{
    FILE *fin=fopen("friday.in","r");
    FILE *fout=fopen("friday.out","w");

    int n;
    fscanf(fin,"%d",&n);

    int md[13]={0,31,0,31,30,31,30,31,31,30,31,30,31};
    int y,m,wd[8],d=0,td;
    memset(wd,0,sizeof(wd));
    for (y=1900;y<=1900+n-1;y++)
    {
        if (rn(y)) md[2]=29; else md[2]=28;
        for (m=1;m<=12;m++)
        {
            td=(d+13)%7;
            wd[td]++;
            d=(d+md[m])%7;
        }
    }
    fprintf(fout,"%d %d %d %d %d %d %d\n",wd[6],wd[0],wd[1],wd[2],wd[3],wd[4],wd[5]);

    fclose(fin); fclose(fout);
    return 0;
}
Exemple #11
0
int32_t zrtp_sendSASRelayPacket(ZrtpContext* zrtpContext, uint8_t* sh, char* render) {
    if (zrtpContext && zrtpContext->zrtpEngine) {
        std::string rn(render);
        return zrtpContext->zrtpEngine->sendSASRelayPacket(sh, rn) ? 1 : 0;
    }
    return 0;
}
void createTree(const char* fn , Int_t seed) {
  TFile* f = TFile::Open(fn,"update");
  f->cd();
  Double_t aD;
  Float_t aF;
  Int_t aI;
  Double_t aVD[5];
  vector<Double_t> aSD(10);
  vector<Double_t>* pSD = &aSD;
  TTree *t = new TTree("TestTree","TestTree");
  t->Branch("aDouble",&aD,"aDouble/D");
  t->Branch("aFloat",&aF,"aFloat/F");
  t->Branch("aInt",&aI,"aInt/I");
  t->Branch("aArrayD",&(aVD[0]),"aArrayD[5]/D");
  t->Branch("aStdVecD","vector<Double_t>",&pSD);

  TRandom rn(seed);
  for ( Int_t evt = 0 ; evt < 1000 ; ++ evt ) {
    aD = rn.Gaus();
    aF = rn.Uniform();
    aI = rn.Integer(100);
    for ( Int_t i = 0 ; i<10 ; ++i ){
      if ( i < 5 ) aVD[i] = rn.Gaus( i , 0.1 );
      aSD[i] = rn.Gaus( -i , 0.1 );
    }
    t->Fill();
  }
  t->Print();
  t->Write();
  f->Close();
}
Exemple #13
0
MyPluralFormsNode*MyPluralFormsParser::logicalOrExpression()
{
    MyPluralFormsNode* p = logicalAndExpression();
    if (p == NULL)
        return NULL;
    MyPluralFormsNodePtr ln(p);
    if (token().type() == MyPluralFormsToken::T_LOGICAL_OR)
    {
        MyPluralFormsNodePtr un(new MyPluralFormsNode(token()));
        if (!nextToken())
        {
            return 0;
        }
        p = logicalOrExpression();
        if (p == 0)
        {
            return 0;
        }
        MyPluralFormsNodePtr rn(p);    // right
        if (rn->token().type() == MyPluralFormsToken::T_LOGICAL_OR)
        {
            // see logicalAndExpression comment
            un->setNode(0, ln.release());
            un->setNode(1, rn->releaseNode(0));
            rn->setNode(0, un.release());
            return rn.release();
        }


        un->setNode(0, ln.release());
        un->setNode(1, rn.release());
        return un.release();
    }
    return ln.release();
}
Exemple #14
0
// нарисовать линию до
void Drawer::LineTo(int to_x, int to_y)
{
    ASSERT( (curX == to_x) || (curY == to_y) );

    RangeNormalizer rn(*this, to_x, to_y);

    LineToImpl(to_x, to_y);
}
Exemple #15
0
// caller has to free() the result
static WCHAR* FavCompactReadableName(DisplayState* fav, Favorite* fn, bool isCurrent = false) {
    ScopedMem<WCHAR> rn(FavReadableName(fn));
    if (isCurrent) {
        return str::Format(L"%s : %s", _TR("Current file"), rn.Get());
    }
    const WCHAR* fp = path::GetBaseName(fav->filePath);
    return str::Format(L"%s : %s", fp, rn.Get());
}
 Zufallszahlen(int _n, int range) : zahlen(new int[_n]),n(_n){
     std::random_device rn;
     std::mt19937 engine(rn());
     std::uniform_int_distribution<int> dice(1, range);
     for(int i=0; i < _n; ++i) {
       zahlen[i] = dice(engine);
     }
 }
R_Ring_Vector FHE_Cipher_Text::Scale(R_Ring_Vector &x, ZZ q, ZZ p, ZZ r) {
  assert(p < q);
  R_Ring_Vector rn(p, x.Get_d(), x.Get_Dimension());
  for (int i = 0; i < x.Get_Dimension(); i++) {
    rn[i] = x[i].Scale(q, p, r);
  }
  return rn;
}
Exemple #18
0
const char* ARMv7DOpcodeCompareRegisterT2::format()
{
    appendInstructionName("compare");
    appendRegisterName(rn());
    appendSeparator();
    appendRegisterName(rm());

    return m_formatBuffer;
}
Exemple #19
0
const char* ARMv7DOpcodeCompareImmediateT1::format()
{
    appendInstructionName("cmp");
    appendRegisterName(rn());
    appendSeparator();
    appendUnsignedImmediate(immediate8());

    return m_formatBuffer;
}
// test only for posix
void tst_QSocketNotifier::posixSockets()
{
    QTcpServer server;
    QVERIFY(server.listen(QHostAddress::LocalHost, 0));

    int posixSocket = qt_safe_socket(AF_INET, SOCK_STREAM, 0);
    sockaddr_in addr;
    addr.sin_addr.s_addr = htonl(0x7f000001);
    addr.sin_family = AF_INET;
    addr.sin_port = htons(server.serverPort());
    qt_safe_connect(posixSocket, (const struct sockaddr*)&addr, sizeof(sockaddr_in));
    QVERIFY(server.waitForNewConnection(5000));
    QScopedPointer<QTcpSocket> passive(server.nextPendingConnection());

    ::fcntl(posixSocket, F_SETFL, ::fcntl(posixSocket, F_GETFL) | O_NONBLOCK);

    {
        QSocketNotifier rn(posixSocket, QSocketNotifier::Read);
        connect(&rn, SIGNAL(activated(int)), &QTestEventLoop::instance(), SLOT(exitLoop()));
        QSignalSpy readSpy(&rn, SIGNAL(activated(int)));
        QVERIFY(readSpy.isValid());
        // No write notifier, some systems trigger write notification on socket creation, but not all
        QSocketNotifier en(posixSocket, QSocketNotifier::Exception);
        connect(&en, SIGNAL(activated(int)), &QTestEventLoop::instance(), SLOT(exitLoop()));
        QSignalSpy errorSpy(&en, SIGNAL(activated(int)));
        QVERIFY(errorSpy.isValid());

        passive->write("hello",6);
        passive->waitForBytesWritten(5000);

        QTestEventLoop::instance().enterLoop(3);
        QCOMPARE(readSpy.count(), 1);
        QCOMPARE(errorSpy.count(), 0);

        char buffer[100];
        int r = qt_safe_read(posixSocket, buffer, 100);
        QCOMPARE(r, 6);
        QCOMPARE(buffer, "hello");

        QSocketNotifier wn(posixSocket, QSocketNotifier::Write);
        connect(&wn, SIGNAL(activated(int)), &QTestEventLoop::instance(), SLOT(exitLoop()));
        QSignalSpy writeSpy(&wn, SIGNAL(activated(int)));
        QVERIFY(writeSpy.isValid());
        qt_safe_write(posixSocket, "goodbye", 8);

        QTestEventLoop::instance().enterLoop(3);
        QCOMPARE(readSpy.count(), 1);
        QCOMPARE(writeSpy.count(), 1);
        QCOMPARE(errorSpy.count(), 0);

        // Write notifier may have fired before the read notifier inside
        // QTcpSocket, give QTcpSocket a chance to see the incoming data
        passive->waitForReadyRead(100);
        QCOMPARE(passive->readAll(), QByteArray("goodbye",8));
    }
    qt_safe_close(posixSocket);
}
Exemple #21
0
void createNetwork::rewireWeights ( double prop ,boost::function<double () > r,nodeKind theNodeKind )
{
	network::edgeList toChange;
	network::edgeIterator it;
	//		unsigned int i;

	network::edgesBetween ( toChange, theNodeKind, theNodeKind );

	nodeList vl;
	network::verticesMatching(vl, theNodeKind);
	getRandomNode rn (vl);

	for ( it = toChange.begin(); it != toChange.end(); it++ )
	{
		if ( network::noise.getUniform() > prop )
			continue;

		nodeDescriptor  newSource;
		nodeDescriptor  newTarget;

		nodeDescriptor oldSource = it->first ;
		nodeDescriptor oldTarget = getTarget(*it);

		do
		{
			newSource = rn();
			newTarget = rn();
		}
		while ( newSource == newTarget || nodeBlueprint::theNodes[newSource]->isLinked ( newTarget ) );   // keine Selbst- und Doppelverbindungen

			//			if ((network::theNodes[newSource] == (*it)->source) && (network::theNodes[newTarget] == (*it)->target))
			//				continue;

		((edgeVirtual*)  getEdge(*it))->setWeight( r() );

		network::link ( newSource,newTarget, (edgeBlueprint *) node::theNodes[it->first]-> getEdge(it->second));

		network::unlink( oldSource, oldTarget);
	}


	network::clean();
}
Exemple #22
0
int main( int argc, char *argv[] ) {
    int sq_side = 1000, radius = sq_side/2;
    int n = 1000, success = 0;
    double pi = 0;
    srand(time(NULL));
    printf("Sequential MonteCarlo for Pi\n");
    for (int cnt = 0; cnt < n; cnt ++)
    {
        double x = rn();
        double y = rn();
        if ((x*x + y*y) <= 1.0)
        {
            success += 1;
        }
    }
    pi = ((double)success)/((double)n) * 4;
    printf("PI = %1.5f\n", pi);
    printf("PI/4 = %1.5f\n", ((double)success/n));
}
Exemple #23
0
const char* ARMv7DOpcodeAddSubtractImmediate3::format()
{
    appendInstructionName(opName(), !inITBlock());
    appendRegisterName(rd());
    appendSeparator();
    appendRegisterName(rn());
    appendSeparator();
    appendUnsignedImmediate(immediate3());

    return m_formatBuffer;
}
void tst_QSocketNotifier::posixSockets()
{
#ifndef Q_OS_UNIX
    QSKIP("test only for posix", SkipAll);
#else

    QTcpServer server;
    QVERIFY(server.listen(QHostAddress::LocalHost, 0));

    int posixSocket = qt_safe_socket(AF_INET, SOCK_STREAM, 0);
    sockaddr_in addr;
    addr.sin_addr.s_addr = htonl(0x7f000001);
    addr.sin_family = AF_INET;
    addr.sin_port = htons(server.serverPort());
    qt_safe_connect(posixSocket, (const struct sockaddr*)&addr, sizeof(sockaddr_in));
    QVERIFY(server.waitForNewConnection(5000));
    QScopedPointer<QTcpSocket> passive(server.nextPendingConnection());

    ::fcntl(posixSocket, F_SETFL, ::fcntl(posixSocket, F_GETFL) | O_NONBLOCK);

    {
        QSocketNotifier rn(posixSocket, QSocketNotifier::Read);
        connect(&rn, SIGNAL(activated(int)), &QTestEventLoop::instance(), SLOT(exitLoop()));
        QSignalSpy readSpy(&rn, SIGNAL(activated(int)));
        QSocketNotifier wn(posixSocket, QSocketNotifier::Write);
        connect(&wn, SIGNAL(activated(int)), &QTestEventLoop::instance(), SLOT(exitLoop()));
        QSignalSpy writeSpy(&wn, SIGNAL(activated(int)));
        QSocketNotifier en(posixSocket, QSocketNotifier::Exception);
        connect(&en, SIGNAL(activated(int)), &QTestEventLoop::instance(), SLOT(exitLoop()));
        QSignalSpy errorSpy(&en, SIGNAL(activated(int)));

        passive->write("hello",6);
        passive->waitForBytesWritten(5000);

        QTestEventLoop::instance().enterLoop(3);
        QCOMPARE(readSpy.count(), 1);
        writeSpy.clear(); //depending on OS, write notifier triggers on creation or not.
        QCOMPARE(errorSpy.count(), 0);

        char buffer[100];
        qt_safe_read(posixSocket, buffer, 100);
        QCOMPARE(buffer, "hello");

        qt_safe_write(posixSocket, "goodbye", 8);

        QTestEventLoop::instance().enterLoop(3);
        QCOMPARE(readSpy.count(), 1);
        QCOMPARE(writeSpy.count(), 1);
        QCOMPARE(errorSpy.count(), 0);
        QCOMPARE(passive->readAll(), QByteArray("goodbye",8));
    }
    qt_safe_close(posixSocket);
#endif
}
Exemple #25
0
const char* ARMv7DOpcodeAddSubtractT1::format()
{
    appendInstructionName(opName(), !inITBlock());
    appendRegisterName(rd());
    appendSeparator();
    appendRegisterName(rn());
    appendSeparator();
    appendRegisterName(rm());

    return m_formatBuffer;
}
//==============================================================================
void 
patch_model::
train(const vector<Mat> &images,
      const Size psize,
      const float var,
      const float lambda,
      const float mu_init,
      const int nsamples,
      const bool visi)
{
  int N = images.size(),n = psize.width*psize.height;

  //compute desired response map
  Size wsize = images[0].size();
  if((wsize.width < psize.width) || (wsize.height < psize.height)){
    cerr << "Invalid image size < patch size!" << endl; throw std::exception();
  }
  int dx = wsize.width-psize.width,dy = wsize.height-psize.height;
  Mat F(dy,dx,CV_32F);
  for(int y = 0; y < dy; y++){   float vy = (dy-1)/2 - y;
    for(int x = 0; x < dx; x++){ float vx = (dx-1)/2 - x;
      F.fl(y,x) = exp(-0.5*(vx*vx+vy*vy)/var);
    }
  }
  normalize(F,F,0,1,NORM_MINMAX);

  //allocate memory
  Mat I(wsize.height,wsize.width,CV_32F);
  Mat dP(psize.height,psize.width,CV_32F);
  Mat O = Mat::ones(psize.height,psize.width,CV_32F)/n;
  P = Mat::zeros(psize.height,psize.width,CV_32F);

  //optimise using stochastic gradient descent
  RNG rn(getTickCount()); double mu=mu_init,step=pow(1e-8/mu_init,1.0/nsamples);
  for(int sample = 0; sample < nsamples; sample++){ int i = rn.uniform(0,N);
    I = this->convert_image(images[i]); dP = 0.0;
    for(int y = 0; y < dy; y++){
      for(int x = 0; x < dx; x++){
    Mat Wi = I(Rect(x,y,psize.width,psize.height)).clone();
    Wi -= Wi.dot(O); normalize(Wi,Wi);
    dP += (F.fl(y,x) - P.dot(Wi))*Wi;
      }
    }    
    P += mu*(dP - lambda*P); mu *= step;
    if(visi){
      Mat R; matchTemplate(I,P,R,CV_TM_CCOEFF_NORMED);
      Mat PP; normalize(P,PP,0,1,NORM_MINMAX);
      normalize(dP,dP,0,1,NORM_MINMAX);
      normalize(R,R,0,1,NORM_MINMAX);
      imshow("P",PP); imshow("dP",dP); imshow("R",R); 
      if(waitKey(10) == 27)break;
    }
  }return;
}
Exemple #27
0
static void
_movi_f(jit_state_t *_jit, jit_int32_t r0, jit_float32_t *i0)
{
    union {
	jit_int32_t	 i;
	jit_float32_t	 f;
    } data;
    jit_int32_t		 reg;

    if (_jitc->no_data) {
	data.f = *i0;
	reg = jit_get_reg(jit_class_gpr);
	movi(rn(reg), data.i & 0xffffffff);
	stxi_i(-8, _FP_REGNO, rn(reg));
	jit_unget_reg(reg);
	ldxi_f(r0, _FP_REGNO, -8);
    }
    else
	ldi_f(r0, (jit_word_t)i0);
}
/**--------------------------------------------------------------------------<BR>
C2DPolyBase::RandomPerturb <BR>
\brief Perturbs the shape by a very small random amount so as to avoid degeneracies
with another polygon caused by coincident lines or points.
<P>---------------------------------------------------------------------------*/
void C2DPolyBase::RandomPerturb(void)
{
	C2DPoint pt = m_BoundingRect.GetPointFurthestFromOrigin();
	double dMinEq = max(pt.x, pt.y) * conEqualityTolerance;
	CRandomNumber rn(dMinEq * 10, dMinEq * 100);

	C2DVector cVector( rn.Get(), rn.Get() );
	if (CRandomNumber::GetBool())
		cVector.i = - cVector.i ;
	if (CRandomNumber::GetBool())
		cVector.j = - cVector.j ;
	Move(cVector);
}
Exemple #29
0
static void
_movi_d(jit_state_t *_jit, jit_int32_t r0, jit_float64_t *i0)
{
    union {
	jit_int32_t	 i[2];
	jit_float64_t	 d;
    } data;
    jit_int32_t		 reg;

    if (_jitc->no_data) {
	data.d = *i0;
	reg = jit_get_reg(jit_class_gpr);
	movi(rn(reg), data.i[0]);
	stxi_i(-8, _FP_REGNO, rn(reg));
	movi(rn(reg), data.i[1]);
	stxi_i(-4, _FP_REGNO, rn(reg));
	jit_unget_reg(reg);
	ldxi_d(r0, _FP_REGNO, -8);
    }
    else
	ldi_d(r0, (jit_word_t)i0);
}
Exemple #30
0
const char* ARMv7DOpcodeLoadStoreRegisterOffsetT1::format()
{
    appendInstructionName(opName());
    appendRegisterName(rt());
    appendSeparator();
    appendCharacter('[');
    appendRegisterName(rn());
    appendSeparator();
    appendRegisterName(rm());
    appendCharacter(']');

    return m_formatBuffer;
}