Ejemplo n.º 1
0
static void fornum (LexState *ls, TString *varname, int line)
{
    /* fornum -> NAME = exp1,exp1[,exp1] forbody */
    FuncState *fs = GetCurrentFuncState( ls );
    int base = fs->freereg;

    new_localvarliteral(ls, "(for index)", 0);
    new_localvarliteral(ls, "(for limit)", 1);
    new_localvarliteral(ls, "(for step)", 2);
    new_localvar(ls, varname, 3);

    checknext(ls, '=');
    exp1(ls);  /* initial value */

    checknext(ls, ',');
    exp1(ls);  /* limit */

    if (testnext(ls, ','))
    {
        exp1(ls);  /* optional step */
    }
    else
    {  /* default step = 1 */
        luaK_codeABx(fs, OP_LOADK, fs->freereg, luaK_numberK(fs, 1));
        luaK_reserveregs(fs, 1);
    }

    forbody(ls, base, line, 1, 1);
}
Ejemplo n.º 2
0
//Same as integrate() but assumes dofs are 2.0 and n.c. values are 0.0
void integrate_twospect(qfvars *vars, INT4 nterm, REAL8 interv, REAL8 tausq, INT4 mainx)
{

   REAL8 inpi, u, sum1, sum2, sum3, x, z;

   inpi = interv*LAL_1_PI;
   REAL8 neg2timesc = -2.0*vars->c, neghalftimessigsq = -0.5*vars->sigsq, neghalftimestausq = -0.5*tausq;

   for (INT4 ii=nterm; ii>=0; ii--) {
      u = (ii + 0.5)*interv;
      sum1 = neg2timesc*u;
      sum2 = fabs(sum1);
      sum3 = neghalftimessigsq * u*u;

      REAL8 twotimesu = 2.0*u;
      for (INT4 jj=vars->weights->length-1; jj>=0; jj--) {
         x = twotimesu * vars->weights->data[jj];
         sum3 -= 0.5 * log1p((x*x));
         z = 2.0 * atan(x);
         sum1 += z;
         sum2 += fabs(z);
      } /* for jj=vars->weights->length-1 --> 0 */

      x = inpi * exp1(sum3) / u;
      if ( !mainx ) x *= (1.0 - exp1(neghalftimestausq * u*u));
      sum1 = sin(0.5*sum1) * x;
      sum2 *= 0.5*x;
      vars->integrationValue += sum1;
      vars->integrationError += sum2;
   } /* for ii=nterm --> 0 */

} /* integrate_twospect() */
Ejemplo n.º 3
0
Archivo: libQF.c Proyecto: cran/MixSim
   static void integrate(int nterm, double interv, double tausq, BOOL mainx)
   /*  carry out integration with nterm terms, at stepsize
      interv.  if (! mainx) multiply integrand by
         1.0-exp(-0.5*tausq*u^2) */
   {
      double inpi, u, sum1, sum2, sum3, x, y, z;
      int k, j, nj;
      inpi = interv / pi;
      for ( k = nterm; k>=0; k--)
      {
         u = (k + 0.5) * interv;
         sum1 = - 2.0 * u * c;  sum2 = fabs(sum1);
         sum3 = - 0.5 * sigsq * square(u);
         for ( j = r-1; j>=0; j--)
         {
            nj = n[j];  x = 2.0 * lb[j] * u;  y = square(x);
            sum3 = sum3 - 0.25 * nj * log1(y, TRUE );
            y = nc[j] * x / (1.0 + y);
            z = nj * atan(x) + y;
            sum1 = sum1 + z;   sum2 = sum2 + fabs(z);
            sum3 = sum3 - 0.5 * x * y;
         }
         x = inpi * exp1(sum3) / u;
	 if ( !  mainx )
         x = x * (1.0 - exp1(-0.5 * tausq * square(u)));
         sum1 = sin(0.5 * sum1) * x;  sum2 = 0.5 * sum2 * x;
         intl = intl + sum1; ersm = ersm + sum2;
      }
   }
Ejemplo n.º 4
0
//Rewrite of integrate_eg() to make it fast
void integrate_twospect2(qfvars *vars, INT4 nterm, REAL8 interv, REAL8 tausq, INT4 mainx)
{

   for (INT4 ii=nterm; ii>=0; ii--) {
      REAL8 u = (ii + 0.5)*interv;
      REAL8 oneoverPiTimesiiPlusHalf = 1.0/(LAL_PI*(ii+0.5));

      REAL8 exptermarguementsum = 0.0, logofproductterm = 0.0, sinetermargumentsum = 0.0, sumofabssinesumargs = 0.0;

      for (INT4 jj=vars->weights->length-1; jj>=0; jj--) {
         REAL8 twoUtimesWeight = 2.0*u*vars->weights->data[jj];
         REAL8 atanTwoUtimesWeight = atan(twoUtimesWeight);

         logofproductterm += -0.5*log1p(twoUtimesWeight*twoUtimesWeight);
         sinetermargumentsum += atanTwoUtimesWeight;
         sumofabssinesumargs += fabs(atanTwoUtimesWeight);
      }
      REAL8 firstterm = exp1(-2.0*(u*u)*exptermarguementsum);
      REAL8 secondterm = exp1(logofproductterm);
      REAL8 thirdterm = sin(sinetermargumentsum - u*vars->c);
      REAL8 together = firstterm * secondterm * thirdterm * oneoverPiTimesiiPlusHalf;
      REAL8 together2 = firstterm * secondterm * (sumofabssinesumargs + fabs(u*vars->c)) * oneoverPiTimesiiPlusHalf;
      if ( !mainx ) {
         REAL8 scalingfactor = (1.0 - exp1(-0.5 * tausq * u*u));
         together *= scalingfactor;
         together2 *= scalingfactor;
      }

      vars->integrationValue += together;
      vars->integrationError += together2;
   }

}
Ejemplo n.º 5
0
//carry out integration with nterm terms, at stepsize interv.  if (! mainx) multiply integrand by 1.0-exp(-0.5*tausq*u^2)
void integrate(qfvars *vars, INT4 nterm, REAL8 interv, REAL8 tausq, INT4 mainx)
{

   REAL8 inpi, u, sum1, sum2, sum3, x, y, z;

   inpi = interv*LAL_1_PI;    //inpi = pi*(k + 1/2)

   for (INT4 ii=nterm; ii>=0; ii--) {
      u = (ii + 0.5)*interv;     //First part of eq 3 in Davies 1980, eq 9 in Davies 1973
      sum1 = -2.0*u*vars->c;     //Third sum, eq 13 of Davies 1980, the u*c term, will divide by 2 at the end
      sum2 = fabs(sum1);         //Davies 1980 says that the sine term can be replaced by the sum of abs vals of the arguement
      sum3 = -0.5*vars->sigsq * u*u;   //First part of eq 13 Davies 1980 in the exponential

      for (INT4 jj=vars->weights->length-1; jj>=0; jj--) {
         x = 2.0 * vars->weights->data[jj] * u;    //2 * lambda_j * u
         y = x*x;    //4 * lambda_j**2 * u**2
         sum3 -= 0.25 * vars->dofs->data[jj] * gsl_sf_log_1plusx(y);    //product in eq 13 of Davies 1980
         y = vars->noncentrality->data[jj] * x / (1.0 + y);    //First sum argument in eq 13 of Davies 1980
         z = vars->dofs->data[jj] * atan(x) + y;      //Third sum argument in eq 13 of Davies 1980
         sum1 += z;        //Third sum in eq 13
         sum2 += fabs(z);
         sum3 -= 0.5 * x * y;    //Product
      } /* for jj=vars->weights->length-1 --> 0 */

      x = inpi * exp1(sum3) / u;
      if ( !mainx ) x *= (1.0 - exp1(-0.5 * tausq * u*u));  //For auxillary integration, we multiply by this factor)
      sum1 = sin(0.5 * sum1) * x;   //Now compute the sine
      sum2 *= 0.5*x;
      vars->integrationValue += sum1;     //integration value
      vars->integrationError += sum2;     //error on integration
   } /* for ii=nterm --> 0 */

} /* integrate() */
Ejemplo n.º 6
0
Archivo: libQF.c Proyecto: cran/MixSim
   static double truncation(double u, double tausq)
   /* bound integration error due to truncation at u */
   {
      double sum1, sum2, prod1, prod2, prod3, lj, ncj,
         x, y, err1, err2;
      int j, nj, s;

      counter();
      sum1  = 0.0; prod2 = 0.0;  prod3 = 0.0;  s = 0;
      sum2 = (sigsq + tausq) * square(u); prod1 = 2.0 * sum2;
      u = 2.0 * u;
      for (j=0; j<r; j++ )
      {
         lj = lb[j];  ncj = nc[j]; nj = n[j];
         x = square(u * lj);
         sum1 = sum1 + ncj * x / (1.0 + x);
         if (x > 1.0)
         {
            prod2 = prod2 + nj * log(x);
            prod3 = prod3 + nj * log1(x, TRUE );
            s = s + nj;
         }
         else  prod1 = prod1 + nj * log1(x, TRUE );
      }
      sum1 = 0.5 * sum1;
      prod2 = prod1 + prod2;  prod3 = prod1 + prod3;
      x = exp1(-sum1 - 0.25 * prod2) / pi;
      y = exp1(-sum1 - 0.25 * prod3) / pi;
      err1 =  ( s  ==  0 )  ? 1.0 : x * 2.0 / s;
      err2 =  ( prod3 > 1.0 )  ? 2.5 * y : 1.0;
      if (err2 < err1) err1 = err2;
      x = 0.5 * sum2;
      err2 =  ( x  <=  y )  ? 1.0  : y / x;
      return  ( err1 < err2 )  ? err1  :  err2;
   }
Ejemplo n.º 7
0
//This is from eq 13 of Davies 1980 and makes more sense than the integrate() function while giving nearly identical results (last digits of double precision are only slightly different)
void integrate_eg(qfvars *vars, INT4 nterm, REAL8 interv, REAL8 tausq, INT4 mainx)
{

   for (INT4 ii=nterm; ii>=0; ii--) {
      REAL8 u = (ii + 0.5)*interv;

      REAL8 exptermarguementsum = 0.0, logofproductterm = 0.0, sinetermargumentsum = 0.0, sumofabssinesumargs = 0.0;
      for (INT4 jj=vars->weights->length-1; jj>=0; jj--) {
         exptermarguementsum += (vars->weights->data[jj]*vars->weights->data[jj])*(vars->noncentrality->data[jj]*vars->noncentrality->data[jj])/(1.0 + 4.0*(u*u)*(vars->weights->data[jj]*vars->weights->data[jj]));

         logofproductterm += -0.25*vars->dofs->data[jj]*log1p(4.0*(u*u)*(vars->weights->data[jj]*vars->weights->data[jj]));

         sinetermargumentsum += 0.5*vars->dofs->data[jj]*atan(2.0*u*vars->weights->data[jj]) + (vars->noncentrality->data[jj]*vars->noncentrality->data[jj])*u*vars->weights->data[jj]/(1.0 + 4.0*(u*u)*(vars->weights->data[jj]*vars->weights->data[jj]));

         sumofabssinesumargs += fabs(0.5*(2.0)*atan(2.0*u*vars->weights->data[jj]) + (vars->noncentrality->data[jj]*vars->noncentrality->data[jj])*u*vars->weights->data[jj]/(1.0 + 4.0*(u*u)*(vars->weights->data[jj]*vars->weights->data[jj])));
      }
      REAL8 firstterm = exp1(-2.0*(u*u)*exptermarguementsum - 0.5*(u*u)*vars->sigsq);
      REAL8 secondterm = exp1(logofproductterm);
      REAL8 thirdterm = sin(sinetermargumentsum - u*vars->c);
      REAL8 together = firstterm * secondterm * thirdterm/(LAL_PI*(ii+0.5));
      REAL8 together2 = firstterm * secondterm * (sumofabssinesumargs + fabs(u*vars->c)) / (LAL_PI*(ii+0.5));
      if ( !mainx ) {
         together *= (1.0 - exp1(-0.5 * tausq * u*u));
         together2 *= (1.0 - exp1(-0.5 * tausq * u*u));
      }

      vars->integrationValue += together;
      vars->integrationError += together2;
   }

}
Ejemplo n.º 8
0
//bound integration error due to truncation at u
//Eq. 6, 7, 8 of Davies 1980
REAL8 truncation(qfvars *vars, REAL8 u, REAL8 tausq)
{
   REAL8 sum1, sum2, prod1, prod2, prod3, x, y, err1, err2;
   INT4 s;

   //counter(vars);
   (vars->count)++;           //Increase counter

   sum1  = 0.0;   //Calculating N(u) = exp(-2u**2 sum_j(lambda_j**2 delta_j**2/(1+4u**2 lambda_j**2)))
   prod2 = 0.0;   //Calculating product (i)
   prod3 = 0.0;   //Calculating product (ii)
   s = 0;   //Sum of degrees of freedom

   sum2 = (vars->sigsq + tausq) * u*u;
   prod1 = 2.0 * sum2;
   u *= 2.0;      //This produces the factor of 4 in front of the products (U*lambda_j)**2 (i and ii) in Davies 1980

   for (UINT4 ii=0; ii<vars->weights->length; ii++ ) {
      x = (u * vars->weights->data[ii])*(u * vars->weights->data[ii]);  //(2*U*lambda_j)**2
      sum1 += vars->noncentrality->data[ii] * x / (1.0 + x);   //Sum after eq 4 in Davies 1980
      if (x > 1.0) {
         prod2 += vars->dofs->data[ii] * log(x);      //Logarithim of product (ii) produces sum of logorithms
         prod3 += vars->dofs->data[ii] * gsl_sf_log_1plusx(x);    //Logarithim of product (i) produces sum of logorithms
         s += vars->dofs->data[ii];    //sum of degrees of freedom
      }
      else prod1 += vars->dofs->data[ii] * gsl_sf_log_1plusx(x);
   } /* for ii < vars->weights->length */

   sum1 *= 0.5;      //Remove the extra prefactor of 2 before taking the exponential
   prod2 += prod1;
   prod3 += prod1;
   x = exp1(-sum1 - 0.25*prod2)*LAL_1_PI;    //Now remove logarithm by computing exponential (eq 6)
   y = exp1(-sum1 - 0.25*prod3)*LAL_1_PI;    //Now remove logarithm by computing exponential (eq 8)

   if (s==0) err1 = 1.0;
   else err1 = 2.0*x/s;

   if (prod3>1.0) err2 = 2.5*y;  //eq 8
   else err2 = 1.0;

   if (err2 < err1) err1 = err2;

   x = 0.5 * sum2;

   if (x<=y) err2 = 1.0;
   else err2 = y/x;

   if (err1<err2) return err1;
   else return err2;

} /* truncation() */
bool StdMeshers_Projection_3D::IsApplicable(const TopoDS_Shape & aShape, bool toCheckAll)
{
  TopExp_Explorer exp0( aShape, TopAbs_SOLID );
  if ( !exp0.More() ) return false;

  TopTools_IndexedMapOfOrientedShape blockShapes;
  TopoDS_Vertex v;
  TopoDS_Shell shell;
  for ( ; exp0.More(); exp0.Next() )
  {
    int nbFoundShells = 0;
    TopExp_Explorer exp1( exp0.Current(), TopAbs_SHELL );
    for ( ; exp1.More(); exp1.Next(), ++nbFoundShells )
    {
      shell = TopoDS::Shell( exp1.Current() );
      if ( nbFoundShells == 2 ) break;
    }
    if ( nbFoundShells != 1 ) {
      if ( toCheckAll ) return false;
      continue;
    }   
    bool isBlock = SMESH_Block::FindBlockShapes( shell, v, v, blockShapes );
    if ( toCheckAll && !isBlock ) return false;
    if ( !toCheckAll && isBlock ) return true;
  }
  return toCheckAll;
}
Ejemplo n.º 10
0
void UCHome_Main_SiteConst::clean_my_name_lable()
{
    //<my:name uid="1673222" />
    //<my:name uid="1673222"></my:name>

    //QString unis = this->codec->toUnicode(this->feed_page_html);
    //QByteArray u8s = this->u8codec->fromUnicode(unis);
    //unis = u8s;
    QByteArray tarr = this->feed_page_html;

    QRegExp exp1 ("<my:name uid=\"[0-9]{1,12}\" />");
    QRegExp exp2 ( "<my:name uid=\"[0-9]{1,12}\"></my:name>");
    
    tarr = tarr.trimmed();
    if(tarr.startsWith("f5b")) {
        tarr = tarr.right(tarr.length()-3);
    }
    if(tarr.endsWith("0")) {
        tarr = tarr.left(tarr.length()-1);
    }
    //unis = unis.replace(exp1, QString(""));
    //unis = unis.replace(exp2, QString(""));
    
    //u8s = this->u8codec->fromUnicode(unis);
    QString unis = this->codec->toUnicode(tarr);

    this->feed_page_utf8_html = this->u8codec->fromUnicode(unis);

    this->feed_page_utf8_html = this->u8codec->fromUnicode(this->codec->toUnicode(this->feed_page_html));
}
BOOST_AUTO_TEST_CASE_TEMPLATE(special_cases, RealT, test_types)
{
    const RealT tol = make_tolerance<RealT>();

	// When the number of phases is 1, the hyperexponential distribution is an exponential distribution
    const RealT rates1[] = { static_cast<RealT>(0.5L) };
    boost::math::hyperexponential_distribution<RealT> hexp1(rates1);
    boost::math::exponential_distribution<RealT> exp1(rates1[0]);
    BOOST_CHECK_CLOSE(boost::math::pdf(hexp1, static_cast<RealT>(1L)), boost::math::pdf(exp1, static_cast<RealT>(1L)), tol);
    BOOST_CHECK_CLOSE(boost::math::cdf(hexp1, static_cast<RealT>(1L)), boost::math::cdf(exp1, static_cast<RealT>(1L)), tol);
    BOOST_CHECK_CLOSE(boost::math::mean(hexp1), boost::math::mean(exp1), tol);
    BOOST_CHECK_CLOSE(boost::math::variance(hexp1), boost::math::variance(exp1), tol);
    BOOST_CHECK_CLOSE(boost::math::quantile(hexp1, static_cast<RealT>(0.25L)), boost::math::quantile(exp1, static_cast<RealT>(0.25L)), tol);
    BOOST_CHECK_CLOSE(boost::math::median(hexp1), boost::math::median(exp1), tol);
    BOOST_CHECK_CLOSE(boost::math::quantile(hexp1, static_cast<RealT>(0.75L)), boost::math::quantile(exp1, static_cast<RealT>(0.75L)), tol);
    BOOST_CHECK_CLOSE(boost::math::mode(hexp1), boost::math::mode(exp1), tol);

	// When a k-phase hyperexponential distribution has all rates equal to r, the distribution is an exponential distribution with rate r
    const RealT rate2 = static_cast<RealT>(0.5L);
    const RealT rates2[] = { rate2, rate2, rate2 };
    boost::math::hyperexponential_distribution<RealT> hexp2(rates2);
    boost::math::exponential_distribution<RealT> exp2(rate2);
    BOOST_CHECK_CLOSE(boost::math::pdf(hexp2, static_cast<RealT>(1L)), boost::math::pdf(exp2, static_cast<RealT>(1L)), tol);
    BOOST_CHECK_CLOSE(boost::math::cdf(hexp2, static_cast<RealT>(1L)), boost::math::cdf(exp2, static_cast<RealT>(1L)), tol);
    BOOST_CHECK_CLOSE(boost::math::mean(hexp2), boost::math::mean(exp2), tol);
    BOOST_CHECK_CLOSE(boost::math::variance(hexp2), boost::math::variance(exp2), tol);
    BOOST_CHECK_CLOSE(boost::math::quantile(hexp2, static_cast<RealT>(0.25L)), boost::math::quantile(exp2, static_cast<RealT>(0.25L)), tol);
    BOOST_CHECK_CLOSE(boost::math::median(hexp2), boost::math::median(exp2), tol);
    BOOST_CHECK_CLOSE(boost::math::quantile(hexp2, static_cast<RealT>(0.75L)), boost::math::quantile(exp2, static_cast<RealT>(0.75L)), tol);
    BOOST_CHECK_CLOSE(boost::math::mode(hexp2), boost::math::mode(exp2), tol);
}
Ejemplo n.º 12
0
int exp1()
{
	/* 
	 * exp1 -> MINUS term exp1
	 * 		 | MINUS term exp2
	 *       | exp2
	 */

	if(match(MINUS))
	{
		advance();
		term();
		if(match(MINUS))
		{
			advance();
			term();
			exp1();
			printf("-\n");
		}
		expr_prime();
		printf("-\n");
	}
	else
	{
		expr_prime();
	}
}
Ejemplo n.º 13
0
int expression()
{
    /* expr -> term expr1 */

    term();
    exp1();
}
Ejemplo n.º 14
0
//Same as trunction() but assumes dofs are 2.0 and n.c. values are 0.0
REAL8 truncation_twospect(qfvars *vars, REAL8 u, REAL8 tausq)
{
   REAL8 sum2, prod1, prod2, prod3, x, y, err1, err2;
   INT4 s;

   (vars->count)++;           //Increase counter

   prod2 = 0.0;
   prod3 = 0.0;
   s = 0;

   sum2 = (vars->sigsq + tausq) * u*u;
   prod1 = 2.0 * sum2;
   u *= 2.0;

   for (UINT4 ii=0; ii<vars->weights->length; ii++) {
      x = (u * vars->weights->data[ii])*(u * vars->weights->data[ii]);
      if (x > 1.0) {
         prod2 += 2 * log(x);
         prod3 += 2 * log1p(x);
         s += 2;
      }
      else prod1 += 2 * log1p(x);
   } /* for ii < vars->weights->length */

   prod2 += prod1;
   prod3 += prod1;
   x = exp1(-0.25*prod2)*LAL_1_PI;
   y = exp1(-0.25*prod3)*LAL_1_PI;

   err1 = 2.0*x/s;

   if (prod3>1.0) err2 = 2.5*y;
   else err2 = 1.0;

   if (err2 < err1) err1 = err2;

   x = 0.5 * sum2;

   if (x<=y) err2 = 1.0;
   else err2 = y/x;

   if (err1<err2) return err1;
   else return err2;

} /* truncation_twospect() */
Ejemplo n.º 15
0
static bool longValidator(const QString str, double & val)
{
	QStringList myList;
	QRegExp exp1("^[oOwWeElL][ ]\\d\\d?\\d?[ ]?\\d\\d?[ ]?\\d?\\d?\\.?[0-9]?" );
	QRegExp exp2("^[oOwWeElL][;]\\d\\d?\\d?[;]?\\d\\d?[;]?\\d?\\d?\\.?[0-9]?" ); 
	QRegExp exp3("^[oOwWeElL][:]\\d\\d?\\d?[:]?\\d\\d?[:]?\\d?\\d?\\.?[0-9]?" ); 
	QRegExp exp4("^[+-]?\\d\\d?\\d?\\.?[0-9]*" ); 

	double grauDec;

    if ( exp1.exactMatch( str ) )
	{
		myList = str.split(" ");
	}
	else if ( exp2.exactMatch( str ) )
	{
		myList = str.split(";");
	}
	else if ( exp3.exactMatch( str ) )
	{
		myList = str.split(":");
	}
	else if ( exp4.exactMatch( str ) )
	{
		grauDec = str.toDouble();
		if ((grauDec >= -180.0 && grauDec <=180.0))
		{
			val = grauDec * TeCDR;
			return true;
		}
		else
			return false;
	}
	else
		return false;

	int nelementos = myList.count();
	short graus, minutos = 0;
	float segundos = 0.0;
	
	graus = myList[1].toShort();

	if (nelementos > 2)
		minutos = myList[2].toShort();
	
	if (nelementos > 3)
		segundos = myList[3].toFloat();

	if (TeLongDMS2DD(myList[0].at(0).toAscii(),graus, minutos, segundos, grauDec))
	{
		val = grauDec * TeCDR;
		return true;
	}
	else
		return false;
}
Ejemplo n.º 16
0
bool IfcGeom::Kernel::convert(const IfcSchema::IfcRectangleHollowProfileDef* l, TopoDS_Shape& face) {
	const double x = l->XDim() / 2.0f * getValue(GV_LENGTH_UNIT);
	const double y = l->YDim() / 2.0f  * getValue(GV_LENGTH_UNIT);
	const double d = l->WallThickness() * getValue(GV_LENGTH_UNIT);

	const bool fr1 = l->hasOuterFilletRadius();
	const bool fr2 = l->hasInnerFilletRadius();

	const double r1 = fr1 ? l->OuterFilletRadius() * getValue(GV_LENGTH_UNIT) : 0.;
	const double r2 = fr2 ? l->InnerFilletRadius() * getValue(GV_LENGTH_UNIT) : 0.;
	
	if ( x < ALMOST_ZERO || y < ALMOST_ZERO ) {
		Logger::Message(Logger::LOG_NOTICE,"Skipping zero sized profile:",l->entity);
		return false;
	}

	TopoDS_Face f1;
	TopoDS_Face f2;

	gp_Trsf2d trsf2d;
	bool has_position = true;
#ifdef USE_IFC4
	has_position = l->hasPosition();
#endif
	if (has_position) {
		IfcGeom::Kernel::convert(l->Position(), trsf2d);
	}

	double coords1[8] = {-x  ,-y,   x  ,-y,   x,  y,   -x,  y  };
	double coords2[8] = {-x+d,-y+d, x-d,-y+d, x-d,y-d, -x+d,y-d};
	double radii1[4] = {r1,r1,r1,r1};
	double radii2[4] = {r2,r2,r2,r2};
	int fillets[4] = {0,1,2,3};

	bool s1 = profile_helper(4,coords1,fr1 ? 4 : 0,fillets,radii1,trsf2d,f1);
	bool s2 = profile_helper(4,coords2,fr2 ? 4 : 0,fillets,radii2,trsf2d,f2);

	if (!s1 || !s2) return false;

	TopExp_Explorer exp1(f1, TopAbs_WIRE);
	TopExp_Explorer exp2(f2, TopAbs_WIRE);

	TopoDS_Wire w1 = TopoDS::Wire(exp1.Current());	
	TopoDS_Wire w2 = TopoDS::Wire(exp2.Current());

	BRepBuilderAPI_MakeFace mf(w1, false);
	mf.Add(w2);

	ShapeFix_Shape sfs(mf.Face());
	sfs.Perform();
	face = TopoDS::Face(sfs.Shape());	
	return true;
}
Ejemplo n.º 17
0
static void fornum (LexState *ls, TString *varname, int line) {
  /* fornum -> NAME = exp1,exp1[,exp1] DO body */
  FuncState *fs = ls->fs;
  int base = fs->freereg;
  new_localvar(ls, varname, 0);
  new_localvarstr(ls, "(for limit)", 1);
  new_localvarstr(ls, "(for step)", 2);
  check(ls, '=');
  exp1(ls);  /* initial value */
  check(ls, ',');
  exp1(ls);  /* limit */
  if (testnext(ls, ','))
    exp1(ls);  /* optional step */
  else {  /* default step = 1 */
    luaK_codeABx(fs, OP_LOADK, fs->freereg, luaK_numberK(fs, 1));
    luaK_reserveregs(fs, 1);
  }
  luaK_codeABC(fs, OP_SUB, fs->freereg - 3, fs->freereg - 3, fs->freereg - 1);
  luaK_jump(fs);
  forbody(ls, base, line, 3, 1);
}
Ejemplo n.º 18
0
const char *doubleexp(RooWorkspace *wspace, RooRealVar &x,std::string ext = ""){ 
   // Double exponential model
   RooRealVar frac(Form("f_%s",ext.c_str()),"f",0.9,0.,1.);
   RooRealVar m1(Form("m1_%s",ext.c_str()),"m1",-0.02,-0.2,0.);
   RooRealVar m2(Form("m2_%s",ext.c_str()),"m2",-0.01,-0.2,0.);

   RooExponential exp1(Form("exp1_%s",ext.c_str()),Form("exp1_%s",ext.c_str()),x,m1);
   RooExponential exp2(Form("exp2_%s",ext.c_str()),Form("exp2_%s",ext.c_str()),x,m2);

   RooAddPdf *sumexp = new RooAddPdf(Form("doubleExponential_%s",ext.c_str()), Form("doubleExponential_%s",ext.c_str()),RooArgList(exp1,exp2),RooArgList(frac));
   wspace->import(*sumexp);
   return sumexp->GetName(); 
}
Ejemplo n.º 19
0
int expr_prime()
{  
     /* exp2 -> PLUS term exp1
     * 				| epsilon
     */

    if( match( PLUS ) )
    {
		advance();
        term();
        printf("+\n");
        exp1();
    }
}
Ejemplo n.º 20
0
int main(int argc, char* argv[]){
  if(argc == 3){
    int_type a = (int_type)atoi(argv[1]);
    int_type b = (int_type)atoi(argv[2]);
    int_type lhs = exp0(a, b);
    int_type rhs = exp1(a, b);
    if(lhs == rhs){
      printf("lhs == rhs: %d\n", lhs);
    } else {
      printf("lhs = %d != rhs = %d\n", lhs, rhs);

    }
  }
  return 0;
}
Ejemplo n.º 21
0
    void eval_randf()
    {
      QgsExpression exp1( "randf(1.5,9.5)" );
      QVariant v1 = exp1.evaluate();
      QCOMPARE( v1.toDouble() <= 9.5, true );
      QCOMPARE( v1.toDouble() >= 1.5, true );

      QgsExpression exp2( "randf(-0.0005,-0.0005)" );
      QVariant v2 = exp2.evaluate();
      QCOMPARE( v2.toDouble(), -0.0005 );

      // Invalid expression since max<min
      QgsExpression exp3( "randf(9.3333,1.784)" );
      QVariant v3 = exp3.evaluate();
      QCOMPARE( v3.type(),  QVariant::Invalid );
    }
Ejemplo n.º 22
0
    void eval_rand()
    {
      QgsExpression exp1( "rand(1,10)" );
      QVariant v1 = exp1.evaluate();
      QCOMPARE( v1.toInt() <= 10, true );
      QCOMPARE( v1.toInt() >= 1, true );

      QgsExpression exp2( "rand(-5,-5)" );
      QVariant v2 = exp2.evaluate();
      QCOMPARE( v2.toInt(), -5 );

      // Invalid expression since max<min
      QgsExpression exp3( "rand(10,1)" );
      QVariant v3 = exp3.evaluate();
      QCOMPARE( v3.type(),  QVariant::Invalid );
    }
Ejemplo n.º 23
0
double dftH(int** histogram,int n,int u)
{
    std::complex<double> sum (0.0,0.0);

// std::complex<double> i (0.0,-1.0);
    for (int r=0; r<8; r++)
    {
        std::complex<double> exp1 (0,-2*PI*(double)u*r/8);
        sum=sum+(dcmplx)(histogram[n][r])*(exp(exp1));
    }
    std::complex<double> cc (conj(sum));
    sum=sum*cc;
    sum=sqrt(sum);
    return (double)(abs(sum));

}
Ejemplo n.º 24
0
    void eval_geometry_calc()
    {
      QgsPolyline polyline, polygon_ring;
      polyline << QgsPoint( 0, 0 ) << QgsPoint( 10, 0 );
      polygon_ring << QgsPoint( 2, 1 ) << QgsPoint( 10, 1 ) << QgsPoint( 10, 6 ) << QgsPoint( 2, 6 ) << QgsPoint( 2, 1 );
      QgsPolygon polygon;
      polygon << polygon_ring;
      QgsFeature fPolygon, fPolyline;
      fPolyline.setGeometry( QgsGeometry::fromPolyline( polyline ) );
      fPolygon.setGeometry( QgsGeometry::fromPolygon( polygon ) );

      QgsExpression exp1( "$area" );
      QVariant vArea = exp1.evaluate( &fPolygon );
      QCOMPARE( vArea.toDouble(), 40. );

      QgsExpression exp2( "$length" );
      QVariant vLength = exp2.evaluate( &fPolyline );
      QCOMPARE( vLength.toDouble(), 10. );

      QgsExpression exp3( "$perimeter" );
      QVariant vPerimeter = exp3.evaluate( &fPolygon );
      QCOMPARE( vPerimeter.toDouble(), 26. );

      QgsExpression exp4( "bounds_width($geometry)" );
      QVariant vBoundsWidth = exp4.evaluate( &fPolygon );
      QCOMPARE( vBoundsWidth.toDouble(), 8.0 );

      QgsExpression exp5( "bounds_height($geometry)" );
      QVariant vBoundsHeight = exp5.evaluate( &fPolygon );
      QCOMPARE( vBoundsHeight.toDouble(), 5.0 );

      QgsExpression exp6( "xmin($geometry)" );
      QVariant vXMin = exp6.evaluate( &fPolygon );
      QCOMPARE( vXMin.toDouble(), 2.0 );

      QgsExpression exp7( "xmax($geometry)" );
      QVariant vXMax = exp7.evaluate( &fPolygon );
      QCOMPARE( vXMax.toDouble(), 10.0 );

      QgsExpression exp8( "ymin($geometry)" );
      QVariant vYMin = exp8.evaluate( &fPolygon );
      QCOMPARE( vYMin.toDouble(), 1.0 );

      QgsExpression exp9( "ymax($geometry)" );
      QVariant vYMax = exp9.evaluate( &fPolygon );
      QCOMPARE( vYMax.toDouble(), 6.0 );
    }
Ejemplo n.º 25
0
double power1(double x, double y) {
  double z,a,aa,error, t,a1,a2,y1,y2;
 z = lgg2(x,&aa,&error);
 t = y*134217729.0;
  y1 = t - (t-y);
  y2 = y - y1;
  t = z*134217729.0;
  a1 = t - (t-z);
  a2 = z - a1;
  a = y*z;
 aa = ((y1*a1-a)+y1*a2+y2*a1)+y2*a2+aa*y;
  a1 = a+aa;
  a2 = (a-a1)+aa;
  error = error*ABS(y);
 t = exp1(a1,a2,1.9e16*error);
  return (t >= 0)?t:slowpow(x,y,z);
}
Ejemplo n.º 26
0
Archivo: libQF.c Proyecto: cran/MixSim
 static double   errbd(double u, double* cx)
 /*  find bound on tail probability using mgf, cutoff
    point returned to *cx */
 {
    double sum1, lj, ncj, x, y, xconst; int j, nj;
    counter();
    xconst = u * sigsq;  sum1 = u * xconst;  u = 2.0 * u;
    for (j=r-1; j>=0; j--)
    {
       nj = n[j]; lj = lb[j]; ncj = nc[j];
       x = u * lj; y = 1.0 - x;
       xconst = xconst + lj * (ncj / y + nj) / y;
       sum1 = sum1 + ncj * square(x / y)
          + nj * (square(x) / y + log1(-x, FALSE ));
    }
    *cx = xconst; return exp1(-0.5 * sum1);
 }
Ejemplo n.º 27
0
bool IfcGeom::is_convex(const TopoDS_Wire& wire) {
	for ( TopExp_Explorer exp1(wire,TopAbs_VERTEX); exp1.More(); exp1.Next() ) {
		TopoDS_Vertex V1 = TopoDS::Vertex(exp1.Current());
		gp_Pnt P1 = BRep_Tool::Pnt(V1);
		// Store the neighboring points
		std::vector<gp_Pnt> neighbors;
		for ( TopExp_Explorer exp3(wire,TopAbs_EDGE); exp3.More(); exp3.Next() ) {
			TopoDS_Edge edge = TopoDS::Edge(exp3.Current());
			std::vector<gp_Pnt> edge_points;
			for ( TopExp_Explorer exp2(edge,TopAbs_VERTEX); exp2.More(); exp2.Next() ) {
				TopoDS_Vertex V2 = TopoDS::Vertex(exp2.Current());
				gp_Pnt P2 = BRep_Tool::Pnt(V2);
				edge_points.push_back(P2);
			}
			if ( edge_points.size() != 2 ) continue;
			if ( edge_points[0].IsEqual(P1,GetValue(GV_POINT_EQUALITY_TOLERANCE))) neighbors.push_back(edge_points[1]);
			else if ( edge_points[1].IsEqual(P1, GetValue(GV_POINT_EQUALITY_TOLERANCE))) neighbors.push_back(edge_points[0]);
		}
		// There should be two of these
		if ( neighbors.size() != 2 ) return false;
		// Now find the non neighboring points
		std::vector<gp_Pnt> non_neighbors;
		for ( TopExp_Explorer exp2(wire,TopAbs_VERTEX); exp2.More(); exp2.Next() ) {
			TopoDS_Vertex V2 = TopoDS::Vertex(exp2.Current());
			gp_Pnt P2 = BRep_Tool::Pnt(V2);
			if ( P1.IsEqual(P2,GetValue(GV_POINT_EQUALITY_TOLERANCE)) ) continue;
			bool found = false;
			for( std::vector<gp_Pnt>::const_iterator it = neighbors.begin(); it != neighbors.end(); ++ it ) {
				if ( (*it).IsEqual(P2,GetValue(GV_POINT_EQUALITY_TOLERANCE)) ) { found = true; break; }
			}
			if ( ! found ) non_neighbors.push_back(P2);
		}
		// Calculate the angle between the two edges of the vertex
		gp_Dir dir1(neighbors[0].XYZ() - P1.XYZ());
		gp_Dir dir2(neighbors[1].XYZ() - P1.XYZ());
		const double angle = acos(dir1.Dot(dir2)) + 0.0001;
		// Now for the non-neighbors see whether a greater angle can be found with one of the edges
		for ( std::vector<gp_Pnt>::const_iterator it = non_neighbors.begin(); it != non_neighbors.end(); ++ it ) {
			gp_Dir dir3((*it).XYZ() - P1.XYZ());
			const double angle2 = acos(dir3.Dot(dir1));
			const double angle3 = acos(dir3.Dot(dir2));
			if ( angle2 > angle || angle3 > angle ) return false;
		}
	}
	return true;
}
Ejemplo n.º 28
0
//Very similar to errbound() but this has no non-centrality parameters and assumes all dofs are 2.0
REAL8 errbound_twospect(qfvars *vars, REAL8 u, REAL8* cx)
{

   REAL8 sum1, x, y, xconst;

   (vars->count)++;           //Increase counter

   xconst = u * vars->sigsq;
   sum1 = u * xconst;
   u *= 2.0;
   for (INT4 ii=vars->weights->length-1; ii>=0; ii--) {
      x = u * vars->weights->data[ii];
      y = 1.0 - x;
      xconst += 2.0*vars->weights->data[ii]/y;
      sum1 += 2 * (x*x / y + (log1p(-x)+x));
   }
   *cx = xconst;

   return exp1(-0.5 * sum1);

} /* errbound_twospect() */
Ejemplo n.º 29
0
//find bound on tail probability using mgf, cutoff point returned to *cx
REAL8 errbound(qfvars *vars, REAL8 u, REAL8* cx)
{

   REAL8 sum1, x, y, xconst;

   (vars->count)++;           //Increase counter

   xconst = u * vars->sigsq;  //xconst = u * sigma**2 + sum{ }
   sum1 = u * xconst;         //sum1 = u**2 * sigma**2 + sum{ } this is almost the equation after eq 9 in Davies 1973
                              //without the factor of 1/2 (applied at the end of this function)
   u *= 2.0;
   for (INT4 ii=vars->weights->length-1; ii>=0; ii--) {
      x = u * vars->weights->data[ii];       //x=2*u*lambda_j
      y = 1.0 - x;                           //y=1-2*u*lambda_j
      xconst += vars->weights->data[ii] * (vars->noncentrality->data[ii] / y + vars->dofs->data[ii]) / y;
      sum1 += vars->noncentrality->data[ii] * (x*x/(y*y)) + vars->dofs->data[ii] * (x*x / y + gsl_sf_log_1plusx_mx(-x));
   }
   *cx = xconst;

   return exp1(-0.5 * sum1);

}/* errbound() */
Ejemplo n.º 30
0
    void eval_geometry_calc()
    {
        QgsPolyline polyline, polygon_ring;
        polyline << QgsPoint( 0, 0 ) << QgsPoint( 10, 0 );
        polygon_ring << QgsPoint( 1, 1 ) << QgsPoint( 6, 1 ) << QgsPoint( 6, 6 ) << QgsPoint( 1, 6 ) << QgsPoint( 1, 1 );
        QgsPolygon polygon;
        polygon << polygon_ring;
        QgsFeature fPolygon, fPolyline;
        fPolyline.setGeometry( QgsGeometry::fromPolyline( polyline ) );
        fPolygon.setGeometry( QgsGeometry::fromPolygon( polygon ) );

        QgsExpression exp1( "$area" );
        QVariant vArea = exp1.evaluate( &fPolygon );
        QCOMPARE( vArea.toDouble(), 25. );

        QgsExpression exp2( "$length" );
        QVariant vLength = exp2.evaluate( &fPolyline );
        QCOMPARE( vLength.toDouble(), 10. );

        QgsExpression exp3( "$perimeter" );
        QVariant vPerimeter = exp3.evaluate( &fPolygon );
        QCOMPARE( vPerimeter.toDouble(), 20. );
    }