Exemplo n.º 1
0
void assign_test()
{
  std::cout << "With U = [" << nt2::type_id<U>() << "]\n";
  static const std::size_t N = 11;
  nt2::table<T> a0(nt2::of_size(N));
  nt2::table< std::complex<T> > a1(nt2::of_size(N));
  for(std::size_t i=0; i!=N; ++i)
  {
    a0(i+1) = T(roll<U>());
    a1(i+1) = a0(i+1);
  }

  boost::proto::display_expr( nt2::cast<std::complex<U> >(a0) );
  nt2::table<std::complex<U> > ra0 = nt2::cast< std::complex<U> >(a0);
  for(std::size_t i=0; i!= N; ++i)
  {
    std::cout << a0(i+1) << "\n";
    NT2_TEST_EQUAL( ra0(i+1), nt2::cast(a0(i+1), nt2::meta::as_< std::complex<U> >()) );
  }

  boost::proto::display_expr( nt2::cast<std::complex<U> >(a1) );
  nt2::table<std::complex<U> > ra1 = nt2::cast< std::complex<U> >(a1);
  for(std::size_t i=0; i!= N; ++i)
  {
    std::cout << a1(i+1) << "\n";
    NT2_TEST_EQUAL( ra1(i+1), nt2::cast(a1(i+1), nt2::meta::as_< std::complex<U> >()) );
  }
};
Exemplo n.º 2
0
NT2_TEST_CASE_TPL ( vandermonde_2, NT2_REAL_TYPES)
{
  typedef std::complex<T> cT;
  nt2::table<cT> a0(nt2::of_size(1, 3));
  for(int i=1; i <= 3; i++)
  {
    a0(i) = cT(i);
  }
  NT2_DISPLAY(a0);
  nt2::table<cT> v  =  nt2::vandermonde(a0);
  nt2::display("vandermonde(a0)", v);
  nt2::display("vandermonde(a0)", nt2::vandermonde(a0));
  T bc[9] =  {
    1, 1, 1,
    4, 2, 1,
    9, 3, 1
  };
  int k = 0;
  nt2::table<cT> a(nt2::of_size(3, 3));
  for(int i=1; i <= 3; i++)
  {
    for(int j=1; j <= 3; j++)
    {
      a(i, j) = cT(bc[k++]);
    }

  }
  NT2_DISPLAY(a);
 NT2_TEST(nt2::isulpequal(a, v, 2.0));
}
Exemplo n.º 3
0
void giperbolic(double *x, double ts, double te){
     /* процедура для параболического уравнения*/
      for ( int i = 0; i < n; i++ ) {
          x[i]=1.0/n * i ; // количество шагов на оси x
      }
      double xi=1.0/n;
     double tau=xi*sqrt(r); // шаг по времени (из условия Куранта)
     double t=ts; // t-текущее время, ts -- время начала эксперимента
     
     /*пересчёт значений в середине по разносной схеме*/
     while(t < te){ //te -- время конца эксперимента
     for ( int i = 1; i < n-1; i++ ) {
     w[i] = 2 * (1 - r) * v[i] +
            r * (v[i-1] + v[i+1]) -
            u[i] + tau * tau * source(i * xi, t);
         }

     /* пересчёт значений на краях*/


      v[0] = (c0(t) - v[1] * a0(t) / xi) / (b0(t) - a0(t) / xi);
      v[n-1] = (c1(t) + v[n-2] * a1(t) / xi) / (b1(t) + a1(t) / xi);

    for ( int i = 0; i < n; i++ ) {
        q[i]=u[i]; 
        u[i]=v[i];
        v[i]=w[i];
        w[i]=q[i];
    }
        t += tau; //обновление времени
    for ( int i = 0; i < n; i++ ) {
       double   d = (v[i] - u[i]) / tau; //список производных по времени
      }
}
}
Exemplo n.º 4
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void TestErrorMessage()
{
  PipelineMessage e0;

  QString a0("Some Class Name");
  QString a1("Description");
  int eCode = -10;
  PipelineMessage e1;


  PipelineMessage e2(a0, a1, eCode);

  AbstractFilter::Pointer f = AbstractFilter::New();
  f->notifyErrorMessage("Some Test", a1, eCode);
  f->notifyErrorMessage("Another Test", "A description", -10);

  PipelineMessage pm("Joey's Test", "Testing Warning Message...", -23, PipelineMessage::Warning);
  PipelineMessage pm1("Joey's Test", "Testing Error Message...", -23, PipelineMessage::Error);
  PipelineMessage pm2("Joey's Test", "Testing Status Message...", -23, PipelineMessage::StatusMessage);
  PipelineMessage pm3("Joey's Test", "Testing Status Message...", -23, PipelineMessage::ProgressValue, 23);
  f->broadcastPipelineMessage(pm);
  f->broadcastPipelineMessage(pm1);
  f->broadcastPipelineMessage(pm2);

  if (true)
  { return; }

}
Exemplo n.º 5
0
void Foam::sixDoFSolvers::CrankNicolson::solve
(
    bool firstIter,
    const vector& fGlobal,
    const vector& tauGlobal,
    scalar deltaT,
    scalar deltaT0
)
{
    // Update the linear acceleration and torque
    updateAcceleration(fGlobal, tauGlobal);

    // Correct linear velocity
    v() = tConstraints()
      & (v0() + aDamp()*deltaT*(aoc_*a() + (1 - aoc_)*a0()));

    // Correct angular momentum
    pi() = rConstraints()
      & (pi0() + aDamp()*deltaT*(aoc_*tau() + (1 - aoc_)*tau0()));

    // Correct position
    centreOfRotation() =
        centreOfRotation0() + deltaT*(voc_*v() + (1 - voc_)*v0());

    // Correct orientation
    Tuple2<tensor, vector> Qpi =
        rotate(Q0(), (voc_*pi() + (1 - voc_)*pi0()), deltaT);
    Q() = Qpi.first();
}
Exemplo n.º 6
0
real_t pi_make()
{
	// Gauss-Legrende algorithm

	real_t a0(1);
	real_t b0(real_t(1) / sqrt(real_t(2)));
	real_t t0(0.25);
	real_t p0(1);

	real_t a1, b1, t1, p1;

	// index is halved each time because the precision doubles per iteration.
	for (int index = option_precision + 2; index > 0; index /= 2)
	{
		a1 = (a0 + b0) / real_t(2);
		b1 = sqrt(real_t(a0 * b0));
		t1 = t0 - (p0 * (a0-a1) * (a0-a1));
		p1 = p0 * real_t(2);

		a0 = a1;
		b0 = b1;
		t0 = t1;
		p0 = p1;
	}

	return ((a0 + b0) * (a0 + b0)) / (t0 * real_t(4));
}
Exemplo n.º 7
0
void 
driver_pert()
{
    PertCpm<Actividade*, std::string> p;

    Lista<Actividade*> l1;
    Actividade a1( "chave1","trabalho 1", 134, MES, l1);

    Lista<Actividade*> l0;
    ActividadeCustoFixo a0("chave fixa0", "trab fixo 0", 100, HORA, l0, 1929.98);

    Lista<Actividade*> la2;
    ActividadeCustoFixo a2("chave 2", "trab 2", 222.00, HORA, la2, 22.00);

    p.juntar_actividade(&a1);
    p.juntar_actividade(&a0);
    p.juntar_actividade(&a2);
    p.juntar_ramo("jose", &a0, &a1);
    p.juntar_ramo("pinheiro", &a1, &a2);
    p.juntar_ramo("neta", &a2, &a0);
    p.juntar_ramo("repetido a1->a2", &a1, &a2);

    Projecto esinf("my second project", "input.txt");

    esinf.load_pert();
    esinf.to_string();
    
}
Exemplo n.º 8
0
 table_test(std::size_t n, std::size_t m, T const& min, T const& max )
     : a0(nt2::of_size(n,m)), a1(nt2::of_size(n,m))
     , N(n), M(m)
 {
   for(std::size_t j=1; j<=M; ++j)
     for(std::size_t i=1; i<=N; ++i)
       a1(i, j) = a0(i, j) = roll<T>(min,max);
 }
Exemplo n.º 9
0
 table_test(int n, int m, T const& min, T const& max )
     : a0(nt2::of_size(n,m)), a1(nt2::of_size(n,m)), a2(nt2::of_size(n,m))
     , N(n), M(m)
 {
   for(int j=1; j<=M; ++j)
     for(int i=1; i<=N; ++i)
       a1(i, j) = a2(i, j) = a0(i, j) = roll<T>(min,max);
 }
Exemplo n.º 10
0
/* Public functions */
void VGCRectangleTest::run(){
	VGCRectangle r0;
	VGCAssert(VGCVector(0, 0) == r0.getPosition());
	VGCAssert(0 == r0.getWidth());
	VGCAssert(0 == r0.getHeight());

	r0.setPosition(VGCVector(1, 2));
	VGCAssert(VGCVector(1, 2) == r0.getPosition());
	r0.setWidth(1);
	VGCAssert(1 == r0.getWidth());
	r0.setHeight(2);
	VGCAssert(2 == r0.getHeight());

	VGCRectangle r1(VGCVector(1, 2), 1, 2);
	VGCAssert(VGCVector(1, 2) == r1.getPosition());
	VGCAssert(1 == r1.getWidth());
	VGCAssert(2 == r1.getHeight());

	VGCRectangle r2(r1);
	VGCAssert(VGCVector(1, 2) == r2.getPosition());
	VGCAssert(1 == r2.getWidth());
	VGCAssert(2 == r2.getHeight());

	VGCRectangle r3;
	r3 = r2;
	VGCAssert(VGCVector(1, 2) == r3.getPosition());
	VGCAssert(1 == r3.getWidth());
	VGCAssert(2 == r3.getHeight());

	VGCRectangle r4(VGCVector(1, 2), 2, 3);
	VGCAssert(r4.isInside(VGCVector(1, 2)));
	VGCAssert(r4.isInside(VGCVector(2, 2)));
	VGCAssert(r4.isInside(VGCVector(1, 3)));
	VGCAssert(r4.isInside(VGCVector(2, 3)));
	VGCAssert(r4.isInside(VGCVector(1, 4)));
	VGCAssert(r4.isInside(VGCVector(2, 4)));
	VGCAssert(!r4.isInside(VGCVector(0, 3)));
	VGCAssert(!r4.isInside(VGCVector(2, 5)));


	VGCRectangle a0(VGCVector(0, 0), 0, 0);
	VGCRectangle a1(VGCVector(0, 0), 0, 1);
	VGCRectangle a2(VGCVector(0, 0), 1, 0);
	VGCRectangle a3(VGCVector(0, 1), 0, 0);
	VGCRectangle b0(VGCVector(0, 0), 0, 0);
	VGCRectangle b1(VGCVector(0, 0), 0, 1);
	VGCRectangle b2(VGCVector(0, 0), 1, 0);
	VGCRectangle b3(VGCVector(0, 1), 0, 0);
	VGCAssert(a0 == b0);
	VGCAssert(a1 == b1);
	VGCAssert(a2 == b2);
	VGCAssert(a3 == b3);
	VGCAssert(a0 != a1);
	VGCAssert(a0 != a2);
	VGCAssert(a0 != a3);
}
Exemplo n.º 11
0
void dtkMatrixTestCase::testSubAssign(void)
{
    dtkUnderscore _;
    dtkDenseMatrix<double> a0(4,4),b0(4,4);

    a0.fill(82);
    b0.fill(40);

    a0-=b0;

    for(qlonglong j=1; j<5; j++)
    {
        for(qlonglong i=1; i<5; i++)
        {
            QVERIFY(a0(i,j)==42);
            QVERIFY(b0(i,j)==40);
        }
    }
}
Exemplo n.º 12
0
void Foam::sixDoFSolvers::Newmark::solve
(
    bool firstIter,
    const vector& fGlobal,
    const vector& tauGlobal,
    scalar deltaT,
    scalar deltaT0
)
{
    // Update the linear acceleration and torque
    updateAcceleration(fGlobal, tauGlobal);

    // Correct linear velocity
    v() =
        tConstraints()
      & (v0() + aDamp()*deltaT*(gamma_*a() + (1 - gamma_)*a0()));

    // Correct angular momentum
    pi() =
        rConstraints()
      & (pi0() + aDamp()*deltaT*(gamma_*tau() + (1 - gamma_)*tau0()));

    // Correct position
    centreOfRotation() =
        centreOfRotation0()
      + (
            tConstraints()
          & (
                deltaT*v0()
              + aDamp()*sqr(deltaT)*(beta_*a() + (0.5 - beta_)*a0())
            )
        );

    // Correct orientation
    vector piDeltaT =
        rConstraints()
      & (
            deltaT*pi0()
          + aDamp()*sqr(deltaT)*(beta_*tau() + (0.5 - beta_)*tau0())
        );
    Tuple2<tensor, vector> Qpi = rotate(Q0(), piDeltaT, 1);
    Q() = Qpi.first();
}
Exemplo n.º 13
0
/**
 * test method for the base CoordXY* classes.
 */
void coord() {
    // test comparision
    TESTEQUALS(TestCoordsAbsolute(3, 4) == TestCoordsAbsolute(3, 4), true);
    TESTEQUALS(TestCoordsAbsolute(3, 4) != TestCoordsAbsolute(3, 4), false);
    TESTEQUALS(TestCoordsAbsolute(3, 4) == TestCoordsAbsolute(3, 5), false);
    TESTEQUALS(TestCoordsAbsolute(3, 4) == TestCoordsAbsolute(4, 4), false);
    TESTEQUALS(TestCoordsAbsolute(3, 4) != TestCoordsAbsolute(3, 5), true);

    TESTEQUALS(TestCoordsRelative(3, 4) == TestCoordsRelative(3, 4), true);
    TESTEQUALS(TestCoordsRelative(3, 4) != TestCoordsRelative(3, 4), false);
    TESTEQUALS(TestCoordsRelative(3, 4) == TestCoordsRelative(3, 5), false);
    TESTEQUALS(TestCoordsRelative(3, 4) == TestCoordsRelative(4, 4), false);
    TESTEQUALS(TestCoordsRelative(3, 4) != TestCoordsRelative(3, 5), true);

    // test copy constructor / assignment operator
    TestCoordsAbsolute a0(1, 2);
    TestCoordsRelative r0(3, 4);

    TESTEQUALS(a0, TestCoordsAbsolute(1, 2));
    TESTEQUALS(r0, TestCoordsRelative(3, 4));

    TestCoordsAbsolute a1{a0};
    TestCoordsRelative r1{r0};

    TESTEQUALS(a0, a1);
    TESTEQUALS(r0, r1);

    a1 = a0;
    r1 = r0;

    TESTEQUALS(a0, a1);
    TESTEQUALS(r0, r1);

    // test unary +/-
    TESTEQUALS(-r0, TestCoordsRelative(-3, -4));
    TESTEQUALS(+r0, TestCoordsRelative(3, 4));

    // test addition
    TESTEQUALS(r0 + r0, TestCoordsRelative(6, 8));
    TESTEQUALS(a0 + r0, TestCoordsAbsolute(4, 6));
    TESTEQUALS(r0 + a0, TestCoordsAbsolute(4, 6));

    // test scalar multiplication and division
    TESTEQUALS(r0 * 3, TestCoordsRelative(9, 12));
    TESTEQUALS(r0 / 3, TestCoordsRelative(1, 1));

    // test string representation
    util::FString s;
    s << TestCoordsAbsolute(1, 2);
    TESTEQUALS(std::string(s), "[x: 1, y: 2]");

    s.reset();
    s << TestCoordsRelative(3, 4);
    TESTEQUALS(std::string(s), "(x: 3, y: 4)");
}
Exemplo n.º 14
0
int main()
{
	
	int fdes=_open("x.idx",O_RDONLY | O_BINARY);
//	int fdes=_open("x_test3.cmx",O_RDONLY | O_BINARY);
	int ofdes=_open("x_test3.cmx",O_WRONLY|O_BINARY|O_CREAT|O_TRUNC,_S_IREAD|_S_IWRITE);
//	int ofdes0=_open("x_test2.cmx",O_WRONLY|O_BINARY|O_CREAT|O_TRUNC,_S_IREAD|_S_IWRITE);
	uint32_t* offset=NULL;
	char head[8];

	//read header
	_read(fdes,head,8);
	uint32_t len[2];
	
	//read length
	_read(fdes,len,8);
	offset=(uint32_t*)malloc(sizeof(uint32_t)*(len[1]+1));
	
	//read offset
	_read(fdes,offset,sizeof(uint32_t)*(len[1]+1));

	_write(ofdes,head,8);
	_write(ofdes,len,8);
	_write(ofdes,offset,(len[1]+1)*4);
//	_write(ofdes0,head,8);
//	_write(ofdes0,len,8);
//	_write(ofdes0,offset,(len[1]+1)*4);

	
	//read bitmap
	int i=0;
	for(i=0;i<1;i++){

	ibis::array_t<ibis::bitvector::word_t>
                        a0(fdes, offset[i], offset[i+1]);
	ibis::bitvector* bv=new ibis::bitvector(a0);  //we only read one bitvector as test
	bv->sloppySize(len[0]);
	

//	(*bv).decompress_compax();
	//do some querry

	//bv->WAH2COMPAX();
	//bv->compress_icx();
	//bv->decompress_icx(offset[i], offset[i+1]);
	bv->write(ofdes); //need to be replaced by a for loop
	//bv->decompress_compax();
	//bv->write(ofdes0);
	}

	_close(fdes);
	_close(ofdes);
	return 0;
}
Exemplo n.º 15
0
void dtkMatrixTestCase::testMultAssign(void)
{
    dtkUnderscore _;
    dtkDenseMatrix<double> a0(4,4),b0(4,4),c0(4,4);

    a0.fill(3);
    b0.fill(2);
    c0=a0*b0;

    a0*=5;

    for(qlonglong j=1; j<5; j++)
    {
        for(qlonglong i=1; i<5; i++)
        {
            QVERIFY(a0(i,j)==15);
            QVERIFY(b0(i,j)==2);
            QVERIFY(c0(i,j)==24);
        }
    }
}
Exemplo n.º 16
0
    /**
     * @brief Return parameters used for all bands
     *
     * Method creates keyword vectors of band specific parameters
     * used in the photometric correction.
     *
     * @author Kris Becker - 2/22/2010
     *
     * @param pvl Output PVL container write keywords
     */
    void Hillier::Report ( PvlContainer &pvl ) {
        pvl.addComment("I/F = mu0/(mu0+mu) * F(phase)");
                pvl.addComment(" where:");
                pvl.addComment("  mu0 = cos(incidence)");
                pvl.addComment("  mu = cos(incidence)");
                pvl.addComment("  F(phase) = B0*exp(-B1*phase) + A0 + A1*phase + A2*phase^2 + A3*phase^3 + A4*phase^4");

                pvl += PvlKeyword("Algorithm", "Hillier");
                pvl += PvlKeyword("IncRef", toString(_iRef), "degrees");
                pvl += PvlKeyword("EmaRef", toString(_eRef), "degrees");
                pvl += PvlKeyword("PhaRef", toString(_gRef), "degrees");
                PvlKeyword units("HillierUnits");
                PvlKeyword phostd("PhotometricStandard");
                PvlKeyword bbc("BandBinCenter");
                PvlKeyword bbct("BandBinCenterTolerance");
                PvlKeyword bbn("BandNumber");
                PvlKeyword b0("B0");
                PvlKeyword b1("B1");
                PvlKeyword a0("A0");
                PvlKeyword a1("A1");
                PvlKeyword a2("A2");
                PvlKeyword a3("A3");
                PvlKeyword a4("A4");
                for (unsigned int i = 0; i < _bandpho.size(); i++) {
                    Parameters &p = _bandpho[i];
                    units.addValue(p.units);
                    phostd.addValue(toString(p.phoStd));
                    bbc.addValue(toString(p.wavelength));
                    bbct.addValue(toString(p.tolerance));
                    bbn.addValue(toString(p.band));
                    b0.addValue(toString(p.b0));
                    b1.addValue(toString(p.b1));
                    a0.addValue(toString(p.a0));
                    a1.addValue(toString(p.a1));
                    a2.addValue(toString(p.a2));
                    a3.addValue(toString(p.a3));
                    a4.addValue(toString(p.a4));
                }
                pvl += units;
                pvl += phostd;
                pvl += bbc;
                pvl += bbct;
                pvl += bbn;
                pvl += b0;
                pvl += b1;
                pvl += a0;
                pvl += a1;
                pvl += a2;
                pvl += a3;
                pvl += a4;
                return;
            }
Exemplo n.º 17
0
void Lauchli( AbstractDistMatrix<T>& A, Int n, T mu )
{
    DEBUG_ONLY(CallStackEntry cse("Lauchli"))
    Zeros( A, n+1, n );

    // Set the first row to all ones
    unique_ptr<AbstractDistMatrix<T>> a0( A.Construct(A.Grid(),A.Root()) );
    View( *a0, A, IR(0,1), IR(0,n) );
    Fill( *a0, T(1) );

    // Set the subdiagonal to mu
    FillDiagonal( A, mu, -1 );
}
Exemplo n.º 18
0
double SBVAR::LogLikelihood(void)
{
  double log_likelihood=log_likelihood_constant + lambda_T*LogAbsDeterminant(A0);
  TDenseVector a0(n_vars), aplus(n_predetermined);

  for (int i=n_vars-1; i >= 0; i--)
    {
      a0.RowVector(A0,i);
      aplus.RowVector(Aplus,i);
      log_likelihood+=-0.5*(InnerProduct(a0,a0,YY) - 2.0*InnerProduct(aplus,a0,XY) + InnerProduct(aplus,aplus,XX));
    }

  return log_likelihood;
}
Exemplo n.º 19
0
void level_three()
{
	vector<DPipe> DirectPipes(13);
		vector<DoublePipe> DoublePipes(13);
		vector<CrossPipe> CrossPipes(2);
				DPipe a0(50,SCREEN_HEIGHT-50,100,40);
				DoublePipe b0(150,SCREEN_HEIGHT-50,70,40);
				DPipe a1(150,SCREEN_HEIGHT-150,100,40);
				DoublePipe b1(150,SCREEN_HEIGHT-250,70,40);
				DPipe a2(250,SCREEN_HEIGHT-350,100,40);
				DoublePipe b2(350,SCREEN_HEIGHT-250,70,40);
				DPipe a3(350,SCREEN_HEIGHT-350,100,40);
				DPipe a4(350,SCREEN_HEIGHT-150,100,40);
				DoublePipe b3(250,SCREEN_HEIGHT-450,70,40);
				DoublePipe b4(350,SCREEN_HEIGHT-450,70,40);
				CrossPipe c0(250,SCREEN_HEIGHT-250,100,40);
				DPipe a5(550,SCREEN_HEIGHT-50,100,40);
				DoublePipe b5(250,SCREEN_HEIGHT-150,70,40);
				DoublePipe b6(450,SCREEN_HEIGHT-50,70,40);
				DoublePipe b7(650,SCREEN_HEIGHT-150,70,40);
				DPipe a6(550,SCREEN_HEIGHT-50,100,40);
				DPipe a7(550,SCREEN_HEIGHT-150,100,40);
				DoublePipe b8(750,SCREEN_HEIGHT-50,70,40);
				DPipe a8(550,SCREEN_HEIGHT-250,100,40);
				DoublePipe b9(750,SCREEN_HEIGHT-350,70,40);
				CrossPipe c1(450,SCREEN_HEIGHT-150,100,40);
				DoublePipe b10(350,SCREEN_HEIGHT-450,70,40);
				DPipe a9(750,SCREEN_HEIGHT-150,100,40);
				DPipe a10(750,SCREEN_HEIGHT-250,100,40);
				DoublePipe b11(450,SCREEN_HEIGHT-250,70,40);
				DoublePipe b12(650,SCREEN_HEIGHT-250,70,40);
				DPipe a11(650,SCREEN_HEIGHT-50,100,40);
				DPipe a12(850,SCREEN_HEIGHT-350,100,40);

				DirectPipes[0] = a0; DoublePipes[0] = b0;
				DirectPipes[1] = a1; DoublePipes[1] = b1;
				DirectPipes[2] = a2; DoublePipes[2] = b2;
				DirectPipes[3] = a3; DoublePipes[3] = b3;
				DirectPipes[4] = a4; DoublePipes[4] = b4;
				DirectPipes[5] = a5; DoublePipes[5] = b5;
				DirectPipes[6] = a6; DoublePipes[6] = b6;
				DirectPipes[7] = a7; DoublePipes[7] = b7;
				DirectPipes[8] = a8; DoublePipes[8] = b8;
				DirectPipes[9] = a9; DoublePipes[9] = b9;
				DirectPipes[10] = a10; DoublePipes[10] = b10;
				DirectPipes[11] = a11; DoublePipes[11] = b11;
				DirectPipes[12] = a12; DoublePipes[12] = b12;
				CrossPipes[0] = c0; CrossPipes[1] = c1;
				Water a(20,SCREEN_HEIGHT-50,40,40);
}
Exemplo n.º 20
0
NT2_TEST_CASE_TPL( complexify2, BOOST_SIMD_REAL_TYPES )
{
  typedef typename nt2::meta::as_complex<T>::type cT;
  nt2::table<T>   a00 = nt2::ones(3, 3, nt2::meta::as_<T>());
  NT2_DISPLAY(a00);
  nt2::table<cT> a0 = cT(0, 1)*a00;

  for(int i=1; i < 9; i++)
  {
    std::cout << a0(i) << std::endl;
  }
  NT2_DISPLAY(complexify(a0));
  NT2_DISPLAY(complexify(complexify(a0)));
  NT2_TEST_EQUAL(complexify(a0), nt2::complexify(complexify(a0)));
}
Exemplo n.º 21
0
void DemoQNanoItemPainter::drawGraphCircles(float x, float y, float w, float h, int items, float t)
{
    qreal barWidth = 0.3 * w/items;
    qreal lineMargin = 0.2 * barWidth;
    qreal showAnimationProgress = 0.1 + 0.4*sinf(t*0.8)+0.5;
    qreal lineWidth = barWidth*showAnimationProgress;

    qreal cx = x+w/2;
    qreal cy = y+h/2;
    qreal radius1 = w/2 - lineWidth;
    qreal pi = 3.1415926;
    qreal pi2 = pi*2;
    int i;

    // Setup values
    qreal a1 = -pi/2;
    QVarLengthArray<qreal, 1024> a0(items);
    for (i=0; i<items; i++) {
        a0[i] = -pi/2 + pi2*(((float)items-i)/items)*showAnimationProgress;
    }

    m_painter->setLineWidth(lineWidth);
    m_painter->setLineJoin(QNanoPainter::JOIN_ROUND);
    m_painter->setLineCap(QNanoPainter::CAP_ROUND);

    // Draw cicle backgrounds
    qreal r = radius1;
    QNanoColor c_background(215,215,215,50);
    m_painter->setStrokeStyle(c_background);
    for (int i=0 ; i<items ; i++) {
        m_painter->beginPath();
        m_painter->circle(cx, cy, r);
        m_painter->stroke();
        r -= (lineWidth + lineMargin);
    }

    // Draw circle bars
    r = radius1;
    for (int i=0 ; i<items ; i++) {
        m_painter->beginPath();
        m_painter->arc(cx, cy, r, a0[i], a1, QNanoPainter::WINDING_CCW);
        float s = (float)i/items;
        QNanoColor c(200-150*s, 200-50*s, 100+50*s, 255*showAnimationProgress);
        m_painter->setStrokeStyle(c);
        m_painter->stroke();
        r -= (lineWidth + lineMargin);
    }
}
Exemplo n.º 22
0
double SBVAR_symmetric::LogPrior(void)
{
  if (flat_prior) return 0.0;

  double log_prior=log_prior_constant;
  TDenseVector a0(n_vars), aplus(n_predetermined);

  for (int i=n_vars-1; i >= 0; i--)
    {
      a0.RowVector(A0,i);
      aplus.RowVector(Aplus,i);
      log_prior+=-0.5*(InnerProduct(a0,a0,prior_YY) - 2.0*InnerProduct(aplus,a0,prior_XY) + InnerProduct(aplus,aplus,prior_XX));
    }

  return log_prior;
}
Exemplo n.º 23
0
void dtkMatrixTestCase::testResize(void)
{
    dtkDenseMatrix<double> a0(4,4);
    const double* place=a0.data();
    a0.fill(5);
    a0.resize(4,4);
    QVERIFY(a0.data()==place);

    a0.resize(5,5);
    QCOMPARE(a0.numRows(), 5LL);
    QCOMPARE(a0.numCols(), 5LL);

    a0.resize(3,3);
    QCOMPARE(a0.numRows(), 3LL);
    QCOMPARE(a0.numCols(), 3LL);
}
boost::filesystem::path Waifu2x::GetModeDirPath(const boost::filesystem::path &model_dir)
{
	boost::filesystem::path mode_dir_path(model_dir);
	if (!mode_dir_path.is_absolute()) // model_dirが相対パスなら絶対パスに直す
	{
		// まずはカレントディレクトリ下にあるか探す
		mode_dir_path = boost::filesystem::absolute(model_dir);
		if (!boost::filesystem::exists(mode_dir_path) && !ExeDir.empty()) // 無かったらargv[0]から実行ファイルのあるフォルダを推定し、そのフォルダ下にあるか探す
		{
			boost::filesystem::path a0(ExeDir);
			if (a0.is_absolute())
				mode_dir_path = a0.branch_path() / model_dir;
		}
	}

	return mode_dir_path;
}
Exemplo n.º 25
0
void DemoQPItem::drawGraphCircles(float x, float y, float w, float h, int items, float t)
{
    qreal barWidth = 0.3 * w/items;
    qreal lineMargin = 0.2 * barWidth;
    qreal showAnimationProgress = 0.1 + 0.4*sinf(t*0.8)+0.5;
    qreal lineWidth = barWidth*showAnimationProgress;

    qreal cx = x+w/2;
    qreal cy = y+h/2;
    qreal radius1 = w/2 - lineWidth;
    int i;

    // Setup values
    qreal a1 = 90*16;
    QVarLengthArray<qreal, 1024> a0(items);
    for (i=0; i<items; i++) {
        a0[i] = -360*16*(((float)items-i)/items)*showAnimationProgress;
    }

    // Draw cicle backgrounds
    qreal r = radius1;
    QColor c_background = QColor(215,215,215,50);
    m_painter->setPen(QPen(c_background, lineWidth));
    m_painter->setBrush(Qt::NoBrush);
    for (int i=0 ; i<items ; i++) {
        m_painter->drawEllipse(QPointF(cx, cy), r, r);
        r -= (lineWidth + lineMargin);
    }

    // Draw circle bars
    r = radius1;
    qreal r2 = radius1;
    QPen pen(c_background, lineWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
    qreal margin = 0;
    for (int i=0 ; i<items ; i++) {
        float s = (float)i/items;
        QColor c(200-150*s,200-50*s,100+50*s,255*showAnimationProgress);
        pen.setColor(c);
        m_painter->setPen(pen);
        QRectF area(cx-r, cy-r, cx-x+r2-lineWidth, cy-y+r2-lineWidth);
        m_painter->drawArc(area, a1, a0[i]);
        margin -= (lineWidth + lineMargin);
        r -= (lineWidth + lineMargin);
        r2 -= 2*(lineWidth + lineMargin);
    }
}
Exemplo n.º 26
0
/* Apply the restraint by computing the d-norm
 */
double AmbiguousRestraint::unprotected_evaluate(
                               DerivativeAccumulator *accum)
    const {
  Vector<double> enes;
  double ene = 0;
  for (unsigned int i = 0; i < rs_.size(); ++i) {
    enes.push_back(rs_[i]->unprotected_evaluate(nullptr));
    ene += pow(enes[i], d_);
  }
  ene = pow(ene, 1.0 / d_);
  if (accum) {
    for (unsigned int i = 0; i < rs_.size(); ++i) {
      DerivativeAccumulator a0(*accum,
                                       pow(enes[i], d_ - 1) * pow(ene, 1 - d_));
      rs_[i]->unprotected_evaluate(&a0);
    }
  }
  return ene;
}
Exemplo n.º 27
0
int main()
{
	int n = 4;			//order+1
	double h = 0;
	int maxiter = 100000;
	double eps = pow(10,-10);
	VEC A(n);
	VEC R1(n-1);
/*VEC R2(n-1);
	VEC R3(n-1);
	VEC R4(n-1);*/
	
	Complex a0(-6,0);
	Complex a1(11,0);
	Complex a2(-6,0);
	Complex a3(1,0);
//	Complex a4(0,0);
//Complex a5(0,0);
//	Complex a6(1,0);
//	Complex a7(1,0);
	A[0] = a0;		//x0
	A[1] = a1;		//x1
	A[2] = a2;		//x2
	A[3] = a3;
//	A[4] = a4;
//	A[5] = a5;
//	A[6] = a6;
//	A[7] = a7;
	

	for(int i=0;i<n;i++){
		h = max(h,fabs(A[i]/A[n-1]));
	}
	Complex x1(1+h,1+h);
	
	R1 = polyRoots(x1,A,maxiter,eps);
	
	for(int i=0;i<n-1;i++){
		printf("%lf + %lfj\n",R1[i].r(),R1[i].i());
	}
	return 0;
}
Exemplo n.º 28
0
osg::Node* makePTendcaps()
{
    osg::Geometry* geom = new osg::Geometry;

    osg::Vec3Array* vAry = new osg::Vec3Array;
    geom->setVertexArray( vAry );

    osg::Vec4Array* cAry = new osg::Vec4Array;
    geom->setColorArray( cAry );
    geom->setColorBinding( osg::Geometry::BIND_OVERALL );
    cAry->push_back( osg::Vec4(1,1,1,1) );

    osg::Vec3 a0(  0.1,  0.2,  1.2 );
    osg::Vec3 a1(  0.1,  0.2,  0.8 );
    osg::Vec3 a2( -0.1, -0.2,  0.8 );
    osg::Vec3 a3( -0.1, -0.2,  1.2 );

    vAry->push_back( a0 ); vAry->push_back( a1 ); vAry->push_back( a2 );
    vAry->push_back( a2 ); vAry->push_back( a3 ); vAry->push_back( a0 );

    geom->addPrimitiveSet( new osg::DrawArrays( GL_TRIANGLES, 0, vAry->getNumElements() ) );

    osg::Geode* geode = new osg::Geode();
    geode->addDrawable( geom );

    osg::Group* group = new osg::Group;
    group->addChild( geode );

    osg::PositionAttitudeTransform* xform;
    xform = new osg::PositionAttitudeTransform;
    xform->setAttitude( osg::Quat( osg::DegreesToRadians(120.0), osg::Vec3(0,1,0) ) );
    xform->addChild( geode );
    group->addChild( xform );

    xform = new osg::PositionAttitudeTransform;
    xform->setAttitude( osg::Quat( osg::DegreesToRadians(240.0), osg::Vec3(0,1,0) ) );
    xform->addChild( geode );
    group->addChild( xform );

    return group;
}
Exemplo n.º 29
0
// ----------------------------------------------------------------
f2npoly_t f2npoly_random(f2poly_t m, int deg)
{
	if (deg < 0) {
		std::cerr << "f2npoly_random:  degree " << deg
			<< " should be non-negative.\n";
		exit(1);
	}

	f2poly_t a0(0);
	f2poly_t a1(1);
	f2polymod_t am0(a0, m);
	f2polymod_t am1(a1, m);
	f2npoly_t rv(am0);
	for (int i = deg; i >= 0; i--) {
		f2polymod_t am = f2polymod_random(m);
		if ((i == deg) && (am == am0))
			am = am1;
		rv.set_coeff(i, am);
	}
	return rv;
}
Exemplo n.º 30
0
void Pbc::fullSearch(Vector&d)const{
   if(type==unset) return;
   Vector s=matmul(invReduced.transpose(),d);
   for(int i=0;i<3;i++) s[i]=Tools::pbc(s[i]);
   d=matmul(reduced.transpose(),s);
   const int smax=4;
   Vector a0(reduced.getRow(0));
   Vector a1(reduced.getRow(1));
   Vector a2(reduced.getRow(2));
   Vector best(d);
   double lbest=d.modulo2();
   for(int i=-smax;i<=smax;i++) for(int j=-smax;j<=smax;j++) for(int k=-smax;k<=smax;k++){
     Vector trial=d+i*a0+j*a1+k*a2;
     double ltrial=trial.modulo2();
     if(ltrial<lbest){
       best=trial;
       lbest=ltrial;
     }
   }
   d=best;
}