Esempio n. 1
0
template<class X> void splay_forest<X>::join (Pos* d, Pos u, Pos l, Pos r)
{//fast-and-sloppy version, biased to the left

    while (true) {

        POMAGMA_ASSERT5(get_root(l) == get_root(r), "L,R keys disagree");
        POMAGMA_ASSERT5((!u) or get_root(r) == get_root(u), "R,U keys disagree");
        POMAGMA_ASSERT5(rank(l) < rank(r), "L,R in wrong order");

        //look for space below l
        Pos x = R(l);
        if (not x) {                //                l
            *d = l; U(l) = u;       //  l  +  r  ->  w  r
            set_R(l,r);             // w     y z       y z
            return;
        }

        //look for space below r
        Pos y = L(r);
        if (not y) {                //                  r
            *d = r; U(r) = u;       //  l  +  r  ->   l  z
            set_L(r,l);             // w x     z     w x
            return;
        }

        //otherwise push down
        *d = l; U(l) = u;           //                l
        set_R(l,r);                 //  l  +  r  ->  w    r
        d = &(L(r));                // w x   y z       x+y z
        u = r; l = x; r = y;
    }
}
Esempio n. 2
0
File: GL.cpp Progetto: Pilatuz/omni
//////////////////////////////////////////////////////////////////////////
// GL Color construction
Color::Color(CCH_type r, CCH_type g, CCH_type b, CCH_type a)
{
	set_R(r);
	set_G(g);
	set_B(b);
	set_A(a);
}
Esempio n. 3
0
File: GL.cpp Progetto: Pilatuz/omni
//////////////////////////////////////////////////////////////////////////
// GL Color construction
Color::Color(CCH_type r, CCH_type g, CCH_type b)
{
	set_R(r);
	set_G(g);
	set_B(b);
	set_A(1.0f);
}
Esempio n. 4
0
File: GL.cpp Progetto: Pilatuz/omni
//////////////////////////////////////////////////////////////////////////
// GL Color default construction
Color::Color()
{
	set_R(0.0f);
	set_G(0.0f);
	set_B(0.0f);
	set_A(1.0f);
}
Esempio n. 5
0
 explicit RVector( size_t n ) :
 RObject(),
 Rvec( allocVector(RGetData<T>::Conv,n) ),
 data( RGetData<T>::Cast(Rvec) ),
 size( length(Rvec) )
 {
     PROTECT(Rvec);
     set_R();
 }
Esempio n. 6
0
 explicit RMatrix( size_t r, size_t c ) :
 Rmat( allocMatrix( RGetData<T>::Conv, r, c) ),
 data( RGetData<T>::Cast(Rmat) ),
 mcol(0)
 {
     PROTECT(Rmat);
     set_R();
     get_dims();
 }
Esempio n. 7
0
 //----------------------------------------------------------------------
 // log posterior if R(i_,j_) is replaced by r.  performs work needed
 // for slice sampling in draw_R(i,j)
 double SepStratSampler::logp_slice_R(double r){
   set_R(r);
   fill_siginv(false);  // false means we need to compute Rinv
   const Spd & Siginv(cand_);
   double ans =  .5 * n_ * logdet(Siginv);  // positive .5
   ans +=  -.5 * traceAB(Siginv, sumsq_);
   ans += Rpri_->logp(R_);
   // skip the jacobian because it only has products of sigma^2's in it
   return ans;
 }
Esempio n. 8
0
  //----------------------------------------------------------------------
  // driver function to draw a single element of the correlation
  // matrix conditional on the variances.
  void SepStratSampler::draw_R(int i, int j){
    i_ = i;
    j_ = j;

    double oldr = R_(i,j);
    double slice = logp_slice_R(oldr) - rexp();
    find_limits();
    double rcand = runif(lo_, hi_);
    while(logp_slice_R(rcand) < slice && hi_ > lo_){
      if(rcand > oldr) hi_ = rcand;
      else lo_ = rcand;
      rcand = runif(lo_,hi_);
    }
    set_R(rcand);
  }
Esempio n. 9
0
 //! create a list for R
 RList(const char *names[], const size_t count) :
 size( count ),
 L( allocVector(VECSXP,size) )
 {
     PROTECT(L);
     
     //-- set list items name
     SEXP list_names = 0;
     PROTECT(list_names = allocVector(STRSXP,size));
     for(size_t i = 0; i < size; i++)
         SET_STRING_ELT(list_names,i,mkChar(names[i]));
     setAttrib(L, R_NamesSymbol, list_names);
     UNPROTECT(1); //-- list_name
     
     set_R();
 }
Esempio n. 10
0
//tree manipulation
template<class X> void splay_forest<X>::splay (Pos x)
{
    POMAGMA_ASSERT5(is_inserted(x), "node is not inserted before splaying");

    Pos y = U(x);
    if (!y) { //quit if x is root
        POMAGMA_ASSERT5(root(x) == x, "parentless x is not root after splaying");
        return;
    }
    bool x_y = is_left_of(x,y); //get initial direction

    while (true) {
        Pos z = U(y);

        //swap x and y if y is root
        if (!z) {
            if (x_y) {              //      zig
                set_L(y,R(x));      //    y      x
                set_R(x,y);         //   x . -> . y
            }                       //  . .      . .

            else {                  //      zag
                set_R(y,L(x));      //   y        x
                set_L(x,y);         //  . x  ->  y .
            }                       //   . .    . .
            set_root(x);
            return;
        }

        //remember z's parent
        Pos new_y = U(z);

        //splay x above y,z
        if (is_left_of(y,z)) {      //zig-
            if (x_y) {              //      zig-zig
                set_L(z,R(y));      //     z        x
                set_L(y,R(x));      //    y .  ->  . y
                set_R(y,z);         //   x .        . z
                set_R(x,y);         //  . .          . .
            }
            else {                  //      zig-zag
                set_L(z,R(x));      //    z         x
                set_R(y,L(x));      //   y .  ->  y   z
                set_L(x,y);         //  . x      . . . .
                set_R(x,z);         //   . .
            }
        } else { //zag-
            if (x_y) {              //      zag-zig
                set_L(y,R(x));      //   z          x
                set_R(z,L(x));      //  . y   ->  z   y
                set_L(x,z);         //   x .     . . . .
                set_R(x,y);         //  . .
            }
            else {                  //     zag-zag
                set_R(z,L(y));      //   z          x
                set_R(y,L(x));      //  . y   ->   y .
                set_L(y,z);         //   . x      z .
                set_L(x,y);         //    . .    . .
            }
        }

        //update direction
        if ((y = new_y)) {
            x_y = is_left_of(z,y);
        } else {
            set_root(x);
            return;
        }
    }
}