Esempio n. 1
0
void fn ()
{
  X x1(3.5);        // WARNING - double to int
  X x2(3.5f);       // WARNING - float to int
  X x3(1, 3.5);     // WARNING - double to int
  X x4(1, 3.5f);    // WARNING - float to int
  X x5(3.5, 1);     // WARNING - double to int
  X x6(3.5f, 1);    // WARNING - float to int

  X y1 = 3.5;       // WARNING - double to int
  X y2 = 3.5f;      // WARNING - float to int

  int j1 (3.5);     // WARNING - double to int
  int j2 (3.5f);    // WARNING - float to int

  int k1 = 3.5;     // WARNING - double to int
  int k2 = 3.5f;    // WARNING - float to int
  
  j1 = 3.5;         // WARNING - double to int
  j2 = 3.5f;        // WARNING - float to int
  
  foo (3.5);        // WARNING - double to int
  foo (3.5f);       // WARNING - float to int
  
  wibble (3.5);     // WARNING - double to int
  wibble (3.5f);    // WARNING - float to int
  wibble (1, 3.5);  // WARNING - double to int
  wibble (1, 3.5f); // WARNING - float to int
  wibble (3.5, 1);  // WARNING - double to int
  wibble (3.5f, 1); // WARNING - float to int
  
  punk ();          // WARNING - double to int
  rock (1);         // WARNING - double to int
}
Esempio n. 2
0
int Vezba4::execute() {
    Parking* parkingRow = new Parking[5];

    for(int i = 0; i < 5; i++) {
        parkingRow[i].showParking();
    }

    Car opel, meckica("Mercedes", 1.8, 2.3), x5("BMW", 3.0, 5.0);

    parkingRow[0].park(&opel);
    parkingRow[1].park(&meckica);
    parkingRow[2].park(&x5);

    for(int i = 0; i < 5; i++) {
        parkingRow[i].showParking();
    }

    parkingRow[0].removeCar();

    for(int i = 0; i < 5; i++) {
        parkingRow[i].showParking();
    }

    return 0;
}
Esempio n. 3
0
void foobar()
   {
      X x1 = 1;
      X x2 = X(1);
      X x3 = (X)X(1);
      X x4(1);
      X x5(X(1));

   // Y y0 = 1;  // illegal C++ code: no autopromotion via X type
      Y y1 = X(1);

   // This fails to compile with g++ which expressed (unparsed) as "class Y y2(X(X(1)));"
   // Y y2 = X(X(1));
   }
Esempio n. 4
0
//pentagonal number
GeneralInteger f5(int d5)
{
  int i5 = 0, multiplier = 0;
  if( d5 %2 == 0) {
    i5 = 3* d5 -1;
    multiplier = d5/2;
  }else{
    i5 = (3 * d5 -1)/2;
    multiplier = d5;
  }
    GeneralInteger x5(i5);
    x5 = x5.multiply(multiplier);
    return x5;
}    
Esempio n. 5
0
TEST(XmlEquality, SimpleValues) {
	AmfXml x1;
	AmfXml x2("");
	EXPECT_EQ(x1, x2);

	AmfXml x3("foo");
	AmfXml x4("foo");
	EXPECT_EQ(x3, x4);

	EXPECT_NE(x1, x3);

	AmfXml x5("foobar");
	EXPECT_NE(x3, x5);
}
Esempio n. 6
0
void RSA_TestInstantiations()
{
	RSASS<PKCS1v15, SHA>::Verifier x1(1, 1);
	RSASS<PKCS1v15, SHA>::Signer x2(NullRNG(), 1);
	RSASS<PKCS1v15, SHA>::Verifier x3(x2);
	RSASS<PKCS1v15, SHA>::Verifier x4(x2.GetKey());
	RSASS<PSS, SHA>::Verifier x5(x3);
#ifndef __MWERKS__
	RSASS<PSSR, SHA>::Signer x6 = x2;
	x3 = x2;
	x6 = x2;
#endif
	RSAES<PKCS1v15>::Encryptor x7(x2);
#ifndef __GNUC__
	RSAES<PKCS1v15>::Encryptor x8(x3);
#endif
	RSAES<OAEP<SHA> >::Encryptor x9(x2);

	x4 = x2.GetKey();
}
boost::shared_ptr<Mesh<Simplex<2> > >
createMeshLaplacianLM()
{
    typedef Mesh<Simplex<2> > mesh_type;
    double meshSize = option("gmsh.hsize").as<double>();
    GeoTool::Node x1(-2,-1);
    GeoTool::Node x2(2,1);
    GeoTool::Rectangle R( meshSize ,"OMEGA",x1,x2);
    //R.setMarker(_type="line",_name="Paroi",_marker3=true);
    R.setMarker(_type="line",_name="gamma",_markerAll=true);
    R.setMarker(_type="surface",_name="Omega",_markerAll=true);
    GeoTool::Node x3(0,0); //center
    GeoTool::Node x4(1);//majorRadiusParam
    GeoTool::Node x5(0.7);//minorRadiusParam
    GeoTool::Node x6(0.1);//penautRadiusParam
    GeoTool::Peanut P( meshSize ,"OMEGA2",x3,x4,x5,x6);
    P.setMarker(_type="line",_name="peanut",_markerAll=true);
    P.setMarker(_type="surface",_name="Omega2",_markerAll=true);
    auto mesh = (R-P).createMesh(_mesh=new mesh_type,_name="mymesh.msh");

    return mesh;
}
Esempio n. 8
0
// This function creates the following model:
//   Minimize
//    obj: x1 + x2 + x3 + x4 + x5 + x6
//   Subject To
//    c1: x1 + x2      + x5      = 8
//    c2:           x3 + x5 + x6 = 10
//    q1: [ -x1^2 + x2^2 + x3^2 ] <= 0
//    q2: [ -x4^2 + x5^2 ] <= 0
//   Bounds
//    x2 Free
//    x3 Free
//    x5 Free
//   End
// which is a second order cone program in standard form.
// The function returns objective, variables and constraints in the
// values obj, vars and rngs.
// The function also sets up cone so that for a column j we have
// cone[j] >= 0               Column j is in a cone constraint and is the
//                            cone's head variable.
// cone[j] == NOT_CONE_HEAD   Column j is in a cone constraint but is
//                            not the cone's head variable..
// cone[j] == NOT_IN_CONE     Column j is not contained in any cone constraint.
static void
createmodel (IloModel& model, IloObjective &obj, IloNumVarArray &vars,
             IloRangeArray &rngs, IloIntArray& cone)
{
   // The indices we assign as user objects to the modeling objects.
   // We define them as static data so that we don't have to worry about
   // dynamic memory allocation/leakage.
   static int indices[] = { 0, 1, 2, 3, 4, 5, 6 };

   IloEnv env = model.getEnv();

   // Create variables.
   IloNumVar x1(env,            0, IloInfinity, "x1");
   IloNumVar x2(env, -IloInfinity, IloInfinity, "x2");
   IloNumVar x3(env, -IloInfinity, IloInfinity, "x3");
   IloNumVar x4(env,            0, IloInfinity, "x4");
   IloNumVar x5(env, -IloInfinity, IloInfinity, "x5");
   IloNumVar x6(env,            0, IloInfinity, "x6");

   // Create objective function and immediately store it in return value.
   obj = IloMinimize(env, x1 + x2 + x3 + x4 + x5 + x6);

   // Create constraints.
   IloRange c1(env, 8,  x1 + x2      + x5,       8, "c1");
   IloRange c2(env, 10,           x3 + x5 + x6, 10, "c2");
   IloRange q1(env, -IloInfinity, -x1*x1 + x2*x2 + x3*x3, 0, "q1");
   cone.add(2);             // x1, cone head of constraint at index 2
   cone.add(NOT_CONE_HEAD); // x2
   cone.add(NOT_CONE_HEAD); // x3
   IloRange q2(env, -IloInfinity, -x4*x4 + x5*x5, 0, "q2");
   cone.add(3);             // x4, cone head of constraint at index 3
   cone.add(NOT_CONE_HEAD); // x5

   cone.add(NOT_IN_CONE);   // x6

   // Setup model.
   model.add(obj);
   model.add(obj);
   model.add(c1);
   model.add(c2);
   model.add(q1);
   model.add(q2);

   // Setup return values.
   vars.add(x1);
   vars.add(x2);
   vars.add(x3);
   vars.add(x4);
   vars.add(x5);
   vars.add(x6);

   rngs.add(c1);
   rngs.add(c2);
   rngs.add(q1);
   rngs.add(q2);

   // We set the user object for each modeling object to its index in the
   // respective array. This makes the code in checkkkt a little simpler.
   for (IloInt i = 0; i < vars.getSize(); ++i)
      vars[i].setObject(&indices[i]);
   for (IloInt i = 0; i < rngs.getSize(); ++i)
      rngs[i].setObject(&indices[i]);
}
Esempio n. 9
0
void bi::DOPRI5IntegratorHost<B,S,T1>::update(const T1 t1, const T1 t2,
    State<B,ON_HOST>& s) {
  /* pre-condition */
  BI_ASSERT(t1 < t2);

  typedef host_vector_reference<real> vector_reference_type;
  typedef Pa<ON_HOST,B,host,host,host,host> PX;
  typedef DOPRI5VisitorHost<B,S,S,real,PX,real> Visitor;

  static const int N = block_size<S>::value;
  const int P = s.size();

  #pragma omp parallel
  {
    real buf[10*N]; // use of dynamic array faster than heap allocation
    vector_reference_type x0(buf, N);
    vector_reference_type x1(buf + N, N);
    vector_reference_type x2(buf + 2*N, N);
    vector_reference_type x3(buf + 3*N, N);
    vector_reference_type x4(buf + 4*N, N);
    vector_reference_type x5(buf + 5*N, N);
    vector_reference_type x6(buf + 6*N, N);
    vector_reference_type err(buf + 7*N, N);
    vector_reference_type k1(buf + 8*N, N);
    vector_reference_type k7(buf + 9*N, N);

    real t, h, e, e2, logfacold, logfac11, fac;
    int n, id, p;
    bool k1in;
    PX pax;

    #pragma omp for
    for (p = 0; p < P; ++p) {
      t = t1;
      h = h_h0;
      logfacold = bi::log(BI_REAL(1.0e-4));
      k1in = false;
      n = 0;
      host_load<B,S>(s, p, x0);

      /* integrate */
      while (t < t2 && n < h_nsteps) {
        if (BI_REAL(0.1)*bi::abs(h) <= bi::abs(t)*h_uround) {
          // step size too small
        }
        if (t + BI_REAL(1.01)*h - t2 > BI_REAL(0.0)) {
          h = t2 - t;
          if (h <= BI_REAL(0.0)) {
            t = t2;
            break;
          }
        }

        /* stages */
        Visitor::stage1(t, h, s, p, pax, x0.buf(), x1.buf(), x2.buf(), x3.buf(), x4.buf(), x5.buf(), x6.buf(), k1.buf(), err.buf(), k1in);
        k1in = true; // can reuse from previous iteration in future
        host_store<B,S>(s, p, x1);

        Visitor::stage2(t, h, s, p, pax, x0.buf(), x2.buf(), x3.buf(), x4.buf(), x5.buf(), x6.buf(), err.buf());
        host_store<B,S>(s, p, x2);

        Visitor::stage3(t, h, s, p, pax, x0.buf(), x3.buf(), x4.buf(), x5.buf(), x6.buf(), err.buf());
        host_store<B,S>(s, p, x3);

        Visitor::stage4(t, h, s, p, pax, x0.buf(), x4.buf(), x5.buf(), x6.buf(), err.buf());
        host_store<B,S>(s, p, x4);

        Visitor::stage5(t, h, s, p, pax, x0.buf(), x5.buf(), x6.buf(), err.buf());
        host_store<B,S>(s, p, x5);

        Visitor::stage6(t, h, s, p, pax, x0.buf(), x6.buf(), err.buf());

        /* compute error */
        Visitor::stageErr(t, h, s, p, pax, x0.buf(), x6.buf(), k7.buf(), err.buf());
        e2 = 0.0;
        for (id = 0; id < N; ++id) {
          e = err(id)*h/(h_atoler + h_rtoler*bi::max(bi::abs(x0(id)), bi::abs(x6(id))));
          e2 += e*e;
        }
        e2 /= N;

        /* accept/reject */
        if (e2 <= BI_REAL(1.0)) {
          /* accept */
          t += h;
          x0.swap(x6);
          k1.swap(k7);
        }
        host_store<B,S>(s, p, x0);

        /* compute next step size */
        if (t < t2) {
          logfac11 = h_expo*bi::log(e2);
          if (e2 > BI_REAL(1.0)) {
            /* step was rejected */
            h *= bi::max(h_facl, bi::exp(h_logsafe - logfac11));
          } else {
            /* step was accepted */
            fac = bi::exp(h_beta*logfacold + h_logsafe - logfac11); // Lund-stabilization
            fac = bi::min(h_facr, bi::max(h_facl, fac));  // bound
            h *= fac;
            logfacold = BI_REAL(0.5)*bi::log(bi::max(e2, BI_REAL(1.0e-8)));
          }
        }

        ++n;
      }
    }
  }
}
Esempio n. 10
0
Vector Runge45(
	Fun           &F ,
	size_t         M ,
	const Scalar &ti ,
	const Scalar &tf ,
	const Vector &xi ,
	Vector       &e )
{
	CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL;

	// check numeric type specifications
	CheckNumericType<Scalar>();

	// check simple vector class specifications
	CheckSimpleVector<Scalar, Vector>();

	// Cash-Karp parameters for embedded Runge-Kutta method
	// are static to avoid recalculation on each call and
	// do not use Vector to avoid possible memory leak
	static Scalar a[6] = {
		Scalar(0),
		Scalar(1) / Scalar(5),
		Scalar(3) / Scalar(10),
		Scalar(3) / Scalar(5),
		Scalar(1),
		Scalar(7) / Scalar(8)
	};
	static Scalar b[5 * 5] = {
		Scalar(1) / Scalar(5),
		Scalar(0),
		Scalar(0),
		Scalar(0),
		Scalar(0),

		Scalar(3) / Scalar(40),
		Scalar(9) / Scalar(40),
		Scalar(0),
		Scalar(0),
		Scalar(0),

		Scalar(3) / Scalar(10),
		-Scalar(9) / Scalar(10),
		Scalar(6) / Scalar(5),
		Scalar(0),
		Scalar(0),

		-Scalar(11) / Scalar(54),
		Scalar(5) / Scalar(2),
		-Scalar(70) / Scalar(27),
		Scalar(35) / Scalar(27),
		Scalar(0),

		Scalar(1631) / Scalar(55296),
		Scalar(175) / Scalar(512),
		Scalar(575) / Scalar(13824),
		Scalar(44275) / Scalar(110592),
		Scalar(253) / Scalar(4096)
	};
	static Scalar c4[6] = {
		Scalar(2825) / Scalar(27648),
		Scalar(0),
		Scalar(18575) / Scalar(48384),
		Scalar(13525) / Scalar(55296),
		Scalar(277) / Scalar(14336),
		Scalar(1) / Scalar(4),
	};
	static Scalar c5[6] = {
		Scalar(37) / Scalar(378),
		Scalar(0),
		Scalar(250) / Scalar(621),
		Scalar(125) / Scalar(594),
		Scalar(0),
		Scalar(512) / Scalar(1771)
	};

	CPPAD_ASSERT_KNOWN(
		M >= 1,
		"Error in Runge45: the number of steps is less than one"
	);
	CPPAD_ASSERT_KNOWN(
		e.size() == xi.size(),
		"Error in Runge45: size of e not equal to size of xi"
	);
	size_t i, j, k, m;              // indices

	size_t  n = xi.size();           // number of components in X(t)
	Scalar  ns = Scalar(int(M));     // number of steps as Scalar object
	Scalar  h = (tf - ti) / ns;      // step size
	Scalar  zero_or_nan = Scalar(0); // zero (nan if Ode returns has a nan)
	for(i = 0; i < n; i++)           // initialize e = 0
		e[i] = zero_or_nan;

	// vectors used to store values returned by F
	Vector fh(6 * n), xtmp(n), ftmp(n), x4(n), x5(n), xf(n);

	xf = xi;           // initialize solution
	for(m = 0; m < M; m++)
	{	// time at beginning of this interval
		// (convert to int to avoid MS compiler warning)
		Scalar t = ti * (Scalar(int(M - m)) / ns)
		         + tf * (Scalar(int(m)) / ns);

		// loop over integration steps
		x4 = x5 = xf;   // start x4 and x5 at same point for each step
		for(j = 0; j < 6; j++)
		{	// loop over function evaluations for this step
			xtmp = xf;  // location for next function evaluation
			for(k = 0; k < j; k++)
			{	// loop over previous function evaluations
				Scalar bjk = b[ (j-1) * 5 + k ];
				for(i = 0; i < n; i++)
				{	// loop over elements of x
					xtmp[i] += bjk * fh[i * 6 + k];
				}
			}
			// ftmp = F(t + a[j] * h, xtmp)
			F.Ode(t + a[j] * h, xtmp, ftmp);

			// if ftmp has a nan, set zero_or_nan to nan
			for(i = 0; i < n; i++)
				zero_or_nan *= ftmp[i];

			for(i = 0; i < n; i++)
			{	// loop over elements of x
				Scalar fhi    = ftmp[i] * h;
				fh[i * 6 + j] = fhi;
				x4[i]        += c4[j] * fhi;
				x5[i]        += c5[j] * fhi;
				x5[i]        += zero_or_nan;
			}
		}
		// accumulate error bound
		for(i = 0; i < n; i++)
		{	// cant use abs because cppad.hpp may not be included
			Scalar diff = x5[i] - x4[i];
			e[i] += fabs(diff);
			e[i] += zero_or_nan;
		}

		// advance xf for this step using x5
		xf = x5;
	}
	return xf;
}