Esempio n. 1
0
        inline
        uint Matrix<M, N, Container>::getIndex(uint i, uint j) const
        {
            assert_lt(i, M);
            assert_lt(j, N);

            return i*N+j;
        }
Esempio n. 2
0
 T& operator[](uint index)
 {
     assert_ge(index, 0);
     assert_lt(index, 3);
     
     return coords[index];
 }
Esempio n. 3
0
void dTensorBase::vset(int k, double value)
{
    assert_ge(k,0); assert_lt(k,size);
    #ifdef CHECK_INIT
    if(!(value==value)) eprintf("for k=%d value=%24.16e",k,value);
    #endif
    vec[k]=value;
}
Esempio n. 4
0
double& dTensorBase::vfetch(int k)
{
    assert_ge(k,0); assert_lt(k,size);
    #ifdef CHECK_INIT
    if(!(vec[k]==vec[k])) eprintf("vec[%d]=%24.16e",k,vec[k]);
    #endif
    return vec[k];
}
Esempio n. 5
0
	DataPath DataPath::component(unsigned index) const {
		auto& mgr = path.getNodeManager();
		auto& ext = mgr.getLangExtension<lang::DatapathExtension>();
		assert_true(getTargetType().isa<TupleTypePtr>()) << "Current target must be a tuple type!";
		assert_lt(index, getTargetType().as<TupleTypePtr>().size());
		auto elementType = getTargetType().as<TupleTypePtr>()[index];
		IRBuilder builder(mgr);
		return DataPath(builder.callExpr(ext.getDataPathComponent(), path, builder.uintLit(index), builder.getTypeLiteral(elementType)));
	}
/**
 * Sanity-check various pieces of the Ebwt
 */
void Ebwt::sanityCheckAll(int reverse) const {
	const EbwtParams& eh = this->_eh;
	assert(isInMemory());
	// Check ftab
	for(uint32_t i = 1; i < eh._ftabLen; i++) {
		assert_geq(this->ftabHi(i), this->ftabLo(i-1));
		assert_geq(this->ftabLo(i), this->ftabHi(i-1));
		assert_leq(this->ftabHi(i), eh._bwtLen+1);
	}
	assert_eq(this->ftabHi(eh._ftabLen-1), eh._bwtLen);
	
	// Check offs
	int seenLen = (eh._bwtLen + 31) >> 5;
	uint32_t *seen;
	try {
		seen = new uint32_t[seenLen]; // bitvector marking seen offsets
	} catch(bad_alloc& e) {
		cerr << "Out of memory allocating seen[] at " << __FILE__ << ":" << __LINE__ << endl;
		throw e;
	}
	memset(seen, 0, 4 * seenLen);
	uint32_t offsLen = eh._offsLen;
	for(uint32_t i = 0; i < offsLen; i++) {
		assert_lt(this->offs()[i], eh._bwtLen);
		int w = this->offs()[i] >> 5;
		int r = this->offs()[i] & 31;
		assert_eq(0, (seen[w] >> r) & 1); // shouldn't have been seen before
		seen[w] |= (1 << r);
	}
	delete[] seen;
	
	// Check nPat
	assert_gt(this->_nPat, 0);
	
	// Check plen, flen
	for(uint32_t i = 0; i < this->_nPat; i++) {
		assert_geq(this->plen()[i], 0);
	}
	
	// Check rstarts
	if(this->rstarts() != NULL) {
		for(uint32_t i = 0; i < this->_nFrag-1; i++) {
			assert_gt(this->rstarts()[(i+1)*3], this->rstarts()[i*3]);
			if(reverse == REF_READ_REVERSE) {
				assert(this->rstarts()[(i*3)+1] >= this->rstarts()[((i+1)*3)+1]);
			} else {
				assert(this->rstarts()[(i*3)+1] <= this->rstarts()[((i+1)*3)+1]);
			}
		}
	}
	
	// Check ebwt
	sanityCheckUpToSide(eh._numSides);
	VMSG_NL("Ebwt::sanityCheck passed");
}
Esempio n. 7
0
const double& dTensorBase::vget(int k) const
{
    assert_ge(k,0); assert_lt(k,size);
    #ifdef CHECK_INIT
    if(!(vec[k]==vec[k])) eprintf("vec[%d]=%24.16e",k,vec[k]);
    // double ret = vec[k];
    // assert_eq(ret,ret);
    #endif

    return vec[k];
}
Esempio n. 8
0
double isolate_root_using_bisection(double& low, double& hgh, Polynomial *p)
{
  double x0, p0;

  int bisection_iterations=0;
  double p_low = p->eval(low);
  if(p_low < 0.){
    Polynomial minus_p = -*p;
    return isolate_root_using_bisection(low, hgh, &minus_p);
  }
  double p_hgh = p->eval(hgh);
  assert_ge(p_low,0.);
  assert_le(p_hgh,0.);
  // for smaller intervals average is not necessarily
  // strictly between endpoints of interval
  double x_epsilon = 4*GSL_DBL_EPSILON;
  double v_epsilon = 4*GSL_DBL_EPSILON;
 bisect:
  {
    bisection_iterations++;
    assert_lt(bisection_iterations,100);
    x0 = 0.5*(low+hgh);
    //dprint(x0);
    p0 = p->eval(x0);
    //dprint(p0);
    //const double ap0 = fabs(p0);
    //if(ap0<v_epsilon) goto done;
    if(p0<0.){
      hgh = x0;
      //dprintf("low=%24.16e, hgh=%24.16e\n",low,hgh);
      double interval_length = x0-low;
      //dprint(interval_length);
      if(interval_length<x_epsilon) goto done;
    } else {
      low = x0;
      //dprintf("low=%24.16e, hgh=%24.16e\n",low,hgh);
      double interval_length = hgh-x0;
      //dprint(interval_length);
      if(interval_length<x_epsilon) goto done;
      if(p0<v_epsilon) goto done;
    }
    goto bisect;
  }
  done:
    dprint(bisection_iterations);
    //return x0;
    return low;
}
/**
 * Transform this Ebwt into the original string in linear time by using
 * the LF mapping to walk backwards starting at the row correpsonding
 * to the end of the string.  The result is written to s.  The Ebwt
 * must be in memory.
 */
void Ebwt::restore(SString<char>& s) const {
	assert(isInMemory());
	s.resize(this->_eh._len);
	uint32_t jumps = 0;
	uint32_t i = this->_eh._len; // should point to final SA elt (starting with '$')
	SideLocus l(i, this->_eh, this->ebwt());
	while(i != _zOff) {
		assert_lt(jumps, this->_eh._len);
		//if(_verbose) cout << "restore: i: " << i << endl;
		// Not a marked row; go back a char in the original string
		uint32_t newi = mapLF(l ASSERT_ONLY(, false));
		assert_neq(newi, i);
		s[this->_eh._len - jumps - 1] = rowL(l);
		i = newi;
		l.initFromRow(i, this->_eh, this->ebwt());
		jumps++;
	}
	assert_eq(jumps, this->_eh._len);
}
Esempio n. 10
0
 // evaluate at a point in the interval
 bool eval(double x, Polynomial* p)
 {
   _pv.eval(x,p);
   _num_evals++;
   dprintf3("iter %d: value at x=%24.16e is %24.16e",_num_evals,x,_pv.v());
   if(_num_evals > 30)
   {
     var_epsilon *= 2;
     assert_lt(_num_evals,100); // pure bisection does better than this
   }
   if(_pv.a() < var_epsilon) _done=true;
   //
   // confirm that the point is in the interval
   //assert_gt(x,low().x()); assert_lt(x,hgh().x());
   if(x<=low().x())
   {
     dprintf("x=%24.16e falls below lower bound %24.16e",x,low().x());
     return _done;
   }
   if(x>=hgh().x())
   {
     dprintf("x=%24.16e lands above upper bound %24.16e",x,hgh().x());
     return _done;
   }
   if(_pv.v() > 0.)
   {
     low(_pv);
     _using_hgh = false;
   }
   else
   {
     hgh(_pv);
     _using_hgh = true;
   }
   return _done;
 }
Esempio n. 11
0
void iTensorBase::vset(int k, int value)
{
  assert_ge(k,0); assert_lt(k,size);
  vec[k]=value;
}
Esempio n. 12
0
int& iTensorBase::vfetch(int k)
{
    assert_ge(k,0); assert_lt(k,size);
    return vec[k];
}
Esempio n. 13
0
const int& iTensorBase::vget(int k) const
{
    assert_ge(k,0); assert_lt(k,size);
    return vec[k];
}