Пример #1
0
int CExpression::Value(double& valoare)
{
	error_code=0;
	if (m_Arbore == NULL) return -1;
	valoare=vexp(m_Arbore);
	return (error_code);
}
Пример #2
0
VN * IR_GVN::comp_sc_by_anon_domdef(IR const* exp, IR const* domdef,
									bool & change)
{
	IS_TRUE0((IR_type(exp) == IR_LD || IR_type(exp) == IR_PR) &&
			 m_du->is_may_def(domdef, exp, false));
	SCVNE2VN * vnexp_map = m_def2sctab.get(domdef);
	UINT dtsz = exp->get_dt_size(m_dm);
	MD const* md = exp->get_exact_ref();
	IS_TRUE0(md);
	VNE_SC vexp(MD_id(md), exp->get_ofst(), dtsz);
	/*
	NOTE:
		foo();
		v1; //s1
		goo();
		v1; //s2
		vn of s1 should not same with s2.
	*/
	if (vnexp_map == NULL) {
		vnexp_map = new SCVNE2VN(m_pool, 16); //bsize to be evaluate.
		m_def2sctab.set(domdef, vnexp_map);
	}
	VN * vn = vnexp_map->get(&vexp);
	if (vn == NULL) {
		vn = new_vn();
		VN_type(vn) = VN_VAR;
		vnexp_map->setv((OBJTY)&vexp, vn);
	}
	m_ir2vn.set(IR_id(exp), vn);
	change = true;
	return vn;
}
Пример #3
0
//Compute VN for array according to anonymous domdef.
VN * IR_GVN::comp_array_by_anon_domdef(IR const* arr, VN const* basevn,
									   VN const* ofstvn, IR const* domdef,
									   bool & change)
{
	IS_TRUE0(IR_type(arr) == IR_ARRAY && m_du->is_may_def(domdef, arr, false));
	ARR_VNE2VN * vnexp_map = m_def2arrtab.get(domdef);
	UINT dtsz = arr->get_dt_size(m_dm);
	VNE_ARR vexp(VN_id(basevn), VN_id(ofstvn), ARR_ofst(arr), dtsz);
	/* NOTE:
		foo();
		array(v1); //s1
		goo();
		array(v1); //s2
		vn of s1 should not same with s2. */
	if (vnexp_map == NULL) {
		vnexp_map = new ARR_VNE2VN(m_pool, 16); //bsize to be evaluate.
		m_def2arrtab.set(domdef, vnexp_map);
	}
	VN * vn = vnexp_map->get(&vexp);
	if (vn == NULL) {
		vn = new_vn();
		VN_type(vn) = VN_OP;
		VN_op(vn) = IR_ARRAY;
		vnexp_map->setv((OBJTY)&vexp, vn);
	}
	m_ir2vn.set(IR_id(arr), vn);
	change = true;
	return vn;
}
Пример #4
0
//Compute VN for ild according to anonymous domdef.
VN * IR_GVN::comp_ild_by_anon_domdef(IR const* ild, VN const* mlvn,
									 IR const* domdef, bool & change)
{
	IS_TRUE0(IR_type(ild) == IR_ILD && m_du->is_may_def(domdef, ild, false));
	ILD_VNE2VN * vnexp_map = m_def2ildtab.get(domdef);
	UINT dtsz = ild->get_dt_size(m_dm);
	VNE_ILD vexp(VN_id(mlvn), ILD_ofst(ild), dtsz);
	/*
	NOTE:
		foo();
		ild(v1); //s1
		goo();
		ild(v1); //s2
		vn of s1 should not same with s2.
	*/
	if (vnexp_map == NULL) {
		vnexp_map = new ILD_VNE2VN(m_pool, 16); //bsize to be evaluate.
		m_def2ildtab.set(domdef, vnexp_map);
	}
	VN * ildvn = vnexp_map->get(&vexp);
	if (ildvn == NULL) {
		ildvn = new_vn();
		VN_type(ildvn) = VN_OP;
		VN_op(ildvn) = IR_ILD;
		vnexp_map->setv((OBJTY)&vexp, ildvn);
	}
	m_ir2vn.set(IR_id(ild), ildvn);
	change = true;
	return ildvn;
}
double binlogtail(int n, int t, double p, char c) 
{

    double *bindis ;
    double val, base ;

    ZALLOC(bindis, n+1, double) ;
    genlogbin(bindis, n, p) ;
    base = bindis[t] ;
    vsp(bindis, bindis, -base, n+1) ;
    if (c=='+') {
     vexp(bindis+t, bindis+t, n-t+1) ;
     val = asum(bindis+t, n-t+1) ; 
    }
    else  {
     vexp(bindis, bindis, t) ;
     val = asum(bindis, t) ;
    }
    free(bindis) ;
    return (log(val) + base) ;

}
double binomtail(int n, int t, double p, char c) 
{
/** 
 c = '+':   P(S>=t) 
 c = '-':   P(S<t) 
 WARNING <= t use binomtail(n, t+1, ... 
*/
    double *bindis ;
    double val ;

    ZALLOC(bindis, n+1, double) ;
    genlogbin(bindis, n, p) ;
    vexp(bindis, bindis, n+1) ;
    if (c=='+') 
     val = asum(bindis+t, n-t+1) ; 
    else  
     val = asum(bindis, t) ;
    free(bindis) ;
    return val ;
}
Пример #7
0
int main() 
{
  double p, val ;
  int n, t, c, i ;
  char str[MAXS] ;
  char line[MAXS] ;
  char *spt[MAXFIELD] ;
  int nsplit ;
  double *a ;

  while (fgets(line,MAXS,stdin) != NULL)   {
   nsplit = splitup(line, spt, MAXFIELD) ;
   n = atoi(spt[0]) ;
   p = atof(spt[1]) ;
   freeup(spt, nsplit) ;
   if ((p<=0.0) || (p>=1.0)) fatalx("bad line %s\n",line) ;
   ZALLOC(a, n+1, double) ;
   genlogbin(a, n, p) ;
   vexp(a, a, n+1) ;
   for (i=0; i<=n; i++) {  
    printf("%3d %15.9f\n",i, a[i]) ;
   }
  }
}
Пример #8
0
bool MeshKD::loadObjFromFile ( std::string filename )
{
	std::vector<Vector3> vectorVector; // SCNR
	std::vector<Vector3> normalVector;
	std::cout << "reading " << filename << std::endl;
	std::ifstream file ( filename.c_str() );
	if ( !file.is_open() )
	{
		std::cerr << "Couldn't load mesh " << filename << std::endl;
		return false;
	}
	//build regexes
	boost::regex vexp ( "^v\\s+(.*?)\\s+(.*?)\\s+(.*?)$" );
	boost::regex fexp ( "^f\\s+(.*?)\\s+(.*?)\\s+(.*?)$" );

	boost::cmatch match;
	char line[1024];
	while ( !file.eof() )
	{
		file.getline ( line,1024 );
//		std::cout << line << std::endl;
		if ( boost::regex_match ( line, match, vexp ) )
		{
			Vector3 v = Vector3 ( boost::lexical_cast<double> ( match[1] ),
			                      boost::lexical_cast<double> ( match[2] ),
			                      boost::lexical_cast<double> ( match[3] ) );
			vectorVector.push_back ( v );

		}
		else if ( boost::regex_match ( line, match, fexp ) )
		{
			Vector3 a, b, c;
			int vectorSize = vectorVector.size();
			if ( boost::lexical_cast<int> ( match[1] ) < 0 )
				a = vectorVector[vectorSize + boost::lexical_cast<int> ( match[1] ) ];
			if ( boost::lexical_cast<int> ( match[1] ) > 0 )
				a = vectorVector[boost::lexical_cast<int> ( match[1] )-1];
			if ( boost::lexical_cast<int> ( match[2] ) < 0 )
				b = vectorVector[vectorSize + boost::lexical_cast<int> ( match[2] ) ];
			if ( boost::lexical_cast<int> ( match[2] ) > 0 )
				b = vectorVector[boost::lexical_cast<int> ( match[2] )-1];
			if ( boost::lexical_cast<int> ( match[3] ) < 0 )
				c = vectorVector[vectorSize + boost::lexical_cast<int> ( match[3] ) ];
			if ( boost::lexical_cast<int> ( match[3] ) > 0 )
				c = vectorVector[boost::lexical_cast<int> ( match[3] )-1];
			tree.addMeshKDTriangle ( new MeshKDTriangle ( a,b,c ) );
		}
	}
	/*
	std::cout << "Finished reading" << std::endl;
	std::cout << "Loaded " << ( unsigned int ) tris.size() << " faces" << std::endl;
	std::cout << "Building tree" << std::endl;
	std::cout << "Finished building tree" << std::endl;
	tris.dump();
	oa <<const_cast<const OctreeNode&> ( tris );*/
	this->boundingBoxComputed = true;
	std::cout << "Building tree" << std::endl;
	tree.build ( AXIS_X );
	std::cout << "Finished building tree" << std::endl;
	std::cout << "Tree countains " << tree.getMeshKDTriangleCount() << " tris" << std::endl;
	return true;

}
Пример #9
0
double CExpression::vexp ( arbore a )
{
	double v;
	SYSTEMTIME tm;
	
	GetSystemTime(&tm);

	if (a->operatie==NULL) {error_code=10;return 0;}
	switch(a->operatie){
	case '+' : return( vexp(a->left)+vexp(a->right) );
	case '-' : return( vexp(a->left)-vexp(a->right) );
	case '*' : return( vexp(a->left)*vexp(a->right) );
	case '%':
		{
			v = vexp(a->right);
			if(v == 0){
				error_code = DIVISION_BY_0;
				return 0;
			}
			return (int)vexp(a->left) % (int)v;
		}
	case '/' : v=vexp(a->right) ;
		if (v==0){
			error_code=DIVISION_BY_0;
			return -vexp(a->left)/0.001;
		}else{
			return(vexp(a->left)/v);
		}
	case 150 : return(sin(vexp(a->left)));
	case 151 : return(cos(vexp(a->left)));
	case 152 : return(exp(vexp(a->left)));
	case 153 : v=vexp(a->left) ;
		if (v<0) {error_code=INVALID_DOMAIN;return 0;}
		else return(sqrt(v));
	case 154 : v=vexp(a->left) ;
		if (v<=0) {error_code=INVALID_DOMAIN;return 0;}
		else return(log(v));
	case 155 : return (tan (vexp(a->left)));
	case 156 : return (1 / tan (vexp(a->left)));
	case 157 : return (asin (vexp(a->left)));
	case 158 : return (acos (vexp(a->left)));
	case 159 : return (atan (vexp(a->left)));
	case 173 : return (fabs (vexp(a->left)));
	case 160 : return tm.wYear;
	case 161 : return tm.wMonth;
	case 162 : return tm.wDay;
	case 163 : return tm.wHour;
	case 164 : return tm.wMinute;
	case 165 : return tm.wSecond;
	case 166 : return max(vexp(a->left),vexp(a->right));
	case 167 : return min(vexp(a->left),vexp(a->right));
	case 168 : return rng_rand(0,RAND_MAX)*vexp(a->left)/RAND_MAX;
	//case '|' : return(fabs(vexp(a->left)));
	case '^' : return(pow(vexp(a->left),vexp(a->right)));
	case '@' : return (a->valoare);
		//logical operations evaluation
	case '<' : return( vexp(a->left) < vexp(a->right) );
	case '>' : return( vexp(a->left) > vexp(a->right) );
	case '!' : return(!vexp(a->right)) ;
	// added by chenj, @2008-5-22
	case '=' : return( vexp(a->left) == vexp(a->right) );
	case '&' : return (int)(vexp(a->left)) & (int)(vexp(a->right));
	case '|' : return (int)(vexp(a->left)) | (int)(vexp(a->right));
		
	case 169:
		{
			RTK_TIME t;
			rtk_time_mark(&t);
			return (double)(__int64)t.Data / 1e7;
		}
		
	case 170:
		{
			/* last update time */
			PRTK_TAG tte;
			__r8 retval = 0;
			
			tte  = (PRTK_TAG)a->left->pvObj;
			if(!tte){
				error_code=UNDEFINED_VARIABLE;
				retval = 0;
			}else{ 
				if(!(tte->d.Value.Flags & TF_Valid)){
					error_code=UNDEFINED_VARIABLE;
					retval = 0;
				}else{
					PRTK_TIME pTime = (PRTK_TIME)&tte->d.BinaryAddress[8];
					retval = (double)(__int64)pTime->Data / 1e7;
					rtk_time_mark(pTime);
				}
			}

			return retval;
		}

	case 171  : 
		{
			// a database tag
			PRTK_TAG tte;
			__r8 retval = 0;
			tte = (PRTK_TAG)a->pvObj;
			if(!tte){
				error_code=UNDEFINED_VARIABLE;
				retval = 0;
			}else{ 
				if(!(tte->d.Value.Flags & TF_Valid)){
					error_code=UNDEFINED_VARIABLE;
					retval = 0;
				}else{
					pmc_value_t dblVal;
					set_value_type(dblVal.Flags, dt_real8);
					pmc_type_cast(&tte->d.Value, &dblVal);
					retval = dblVal.Value.dbl;
				}
			}
			return retval;
		}
	
	case 172:
		{
			/* span time */
			PRTK_TAG tte;
			RTK_TIME now;
			__r8 retval = 0;
			
			tte  = (PRTK_TAG)a->left->pvObj;
			if(!tte){
				error_code=UNDEFINED_VARIABLE;
				retval = 0;
			}else{ 
				if(!(tte->d.Value.Flags & TF_Valid)){
					error_code=UNDEFINED_VARIABLE;
					retval = 0;
				}else{
					PRTK_TIME pTime = (PRTK_TIME)&(tte->d.BinaryAddress[8]);
					rtk_time_mark(&now);
					if(pTime->Data != 0){
						/* yes, the field is previouly stored with a resonable value,
						thus valid for a sub-operation to get a duration time */
						retval = rtk_time_diff(&now, pTime);
					}else{
						/* this might be the first time that a time-span was requested
						for this tag
						*/
						retval = 0;
					}
					
					*pTime = now;
				}
			}

			return retval;
		}

	}

	return 0;
}
Пример #10
0
void shr_vmath_fwrap_vexp_(double *X, double *Y, int *n)
{
   vexp(X, Y, *n, 1, 1);
}
static
void
adjust_icalls_eprob(const blt_options& opt,
                    dependent_prob_cache& dpc,
                    icalls_t& ic,
                    const snp_pos_info& pi,
                    std::vector<float>& dependent_eprob) {

    const unsigned ic_size(ic.size());

#ifdef DEBUG_ADJUST
    for (unsigned i(0); i<ic_size; ++i) {
        base_call& bi(pi.calls[ic[i]]);
        std::cerr << "BEFORE: " << i << " " << bi.is_neighbor_mismatch << " " << dependent_eprob[ic[i]] << "\n";
    }
#endif

    static const bool is_use_vexp_frac(true);

    // produce weighted fraction of reads with a neighboring mismatch:
    blt_float_t vexp_frac(opt.bsnp_ssd_no_mismatch);
    if (is_use_vexp_frac) {
        static const blt_float_t lnran(std::log(0.75));
        blt_float_t num(0);
        blt_float_t den(0);
        for (unsigned i(0); i<ic_size; ++i) {
            const base_call& bi(pi.calls[ic[i]]);
//            const blt_float_t eprob(dependent_eprob[ic[i]]);
            const blt_float_t weight(lnran-bi.ln_error_prob());
            den += weight;
            if (bi.is_neighbor_mismatch) { num += weight; }
        }
        blt_float_t mismatch_frac(0);
        if (ic_size && (den>0.)) mismatch_frac=(num/den);
        vexp_frac=(1.-mismatch_frac)*opt.bsnp_ssd_no_mismatch+mismatch_frac*opt.bsnp_ssd_one_mismatch;
    }

    const bool is_limit_vexp_iterations(opt.max_vexp_iterations>0);
    const int max_vexp_iterations(opt.max_vexp_iterations);

    const bool is_limit_vexp(opt.is_min_vexp);
    const blt_float_t min_vexp(opt.min_vexp);

    // used cached dependent probs once we reach the min_vexp level:
    bool is_min_vexp(false);

    std::sort(ic.begin(),ic.end(),sort_icall_by_eprob(pi));
    blt_float_t vexp(1.);
    for (unsigned i(0); i<ic_size; ++i) {
        const base_call& bi(pi.calls[ic[i]]);
        if (! is_min_vexp) {
            dependent_eprob[ic[i]] = static_cast<float>(get_dependent_eprob(bi.get_qscore(),vexp));

            if (is_limit_vexp_iterations && (static_cast<int>(i)>=max_vexp_iterations)) continue;

            blt_float_t next_vexp(vexp);
            if (is_use_vexp_frac) {
                next_vexp *= (1.-vexp_frac);
            } else {
                if (bi.is_neighbor_mismatch) {
                    next_vexp *= (1.-opt.bsnp_ssd_one_mismatch);
                } else {
                    next_vexp *= (1.-opt.bsnp_ssd_no_mismatch);
                }
            }
            if (is_limit_vexp) {
                is_min_vexp=(next_vexp<=min_vexp);
                vexp = std::max(min_vexp,next_vexp);
            } else {
                vexp = next_vexp;
            }
        } else {
            // cached version:
            dependent_eprob[ic[i]] = static_cast<float>(dpc.get_dependent_val(bi.get_qscore(),vexp));
        }
    }

#ifdef DEBUG_ADJUST
    for (unsigned i(0); i<ic_size; ++i) {
        base_call& bi(pi.calls[ic[i]]);
        std::cerr << "AFTER: " << i << " " << bi.is_neighbor_mismatch << " " << dependent_eprob[ic[i]] << "\n";
    }
#endif
}
Пример #12
0
namespace test {

template <class T>
struct b {
   b(){} ~b(){}
   inline string& p() { return static_cast<T*>(this)->v; }
};

#define perm(x,y,z) template <> struct n <x,y,z> : b< n<x,y,x> >
#define vexp(x,y,z) string v; n():v("n " #x #y #z){}

template <op T0, op T1, op T2> struct n : b< n<T0 , T1 , T2 > > {string v; n():v("n ___"){}};

template <       op T1, op T2> struct n <X, T1, T2> : b< n<X, T1, T2> > {string v; n():v("n X__"){}};
template <       op T1, op T2> struct n <A, T1, T2> : b< n<A, T1, T2> > {string v; n():v("n A__"){}};
template <       op T1, op T2> struct n <O, T1, T2> : b< n<O, T1, T2> > {string v; n():v("n O__"){}};

// two operator boperator cases  here

perm(X,O,D) { vexp(X,O,D) };
perm(X,A,D) { vexp(X,A,D) };
perm(X,X,D) { vexp(X,X,D) };
perm(X,N,D) { vexp(X,N,D) };
perm(A,O,D) { vexp(A,O,D) };
perm(A,A,D) { vexp(A,A,D) };
perm(A,X,D) { vexp(A,X,D) };
perm(A,N,D) { vexp(A,N,D) };
perm(O,O,D) { vexp(O,O,D) };
perm(O,A,D) { vexp(O,A,D) };
perm(O,X,D) { vexp(O,X,D) };
perm(O,N,D) { vexp(O,N,D) };

perm(O,D,D) { vexp(O,D,D) };
perm(A,D,D) { vexp(A,D,D) };
perm(X,D,D) { vexp(X,D,D) };

perm(N,O,E) { vexp(N,O,E) };
perm(N,A,E) { vexp(N,A,E) };
perm(N,X,E) { vexp(N,X,E) };
perm(N,N,E) { vexp(N,N,E) };
perm(N,D,E) { vexp(N,D,E) };


}