public boolean getZ() { return get1()!=0; } public int get1 () { return getSp(1).get ()&0xFF; }
public String print16( AutoBuffer ab ) { for( int i=0; i<16; i++ ) { int b = ab.get1(); cs[(i<<1)+0 ] = hex(b>>4); cs[(i<<1)+1 ] = hex(b ); } return new String(cs); }
public TreeVisitor( AutoBuffer tbits, boolean regression ) { _ts = tbits; _ts.get4(); // Skip tree ID _ts.get8(); // Skip seed _ts.get1(); // Skip producer id _regression = regression; }
int getInt( ) { int x = get1(); if( x <= 253 ) return x-1; if( x==255 ) return (short)get2(); assert x==254; return get4(); }
public Value read(AutoBuffer bb) { assert _key == null; // Not set yet _persist = (byte) bb.get1(); _type = (short) bb.get2(); _mem = bb.getA1(); _max = _mem.length; _pojo = null; // On remote nodes _rwlock is initialized to 0 (signaling a remote PUT is // in progress) flips to -1 when the remote PUT is done, or +1 if a notify // needs to happen. _rwlock.set(-1); // Set as 'remote put is done' touch(); return this; }
public static int getNumLeaves(AutoBuffer ab, int leftSize, boolean regression) { int result = 0; int startPos = ab.position(); while (ab.position() < startPos + leftSize) { byte currentNodeType = (byte) ab.get1(); if (currentNodeType == 'S' || currentNodeType == 'E') { ab.get2(); ab.get4f(); // skip col and split value. int skipSize = ab.get1(); if (skipSize == 0) { ab.get3();} } else if (currentNodeType == '[') { result ++; if (regression) ab.get4f(); else ab.get1(); } else { throw new NotImplementedException(); } } ab.position(startPos); // return to the original position so the buffer seems untouched. return result; }
public static void checkForSuicide(int first_byte, AutoBuffer ab) { if( first_byte != UDP.udp.rebooted.ordinal() ) return; int type = ab.get1(); suicide( T.values()[type], ab._h2o); }
public String print16( AutoBuffer ab ) { ab.getPort(); return T.values()[ab.get1()].toString(); } }
public String print16( AutoBuffer ab ) { int flavor = ab.get1(3); int iotime = ab.get4(4); int size = ab.get4(8); return "I/O "+Value.nameOfPersist(flavor)+" "+iotime+"ms "+size+"b"; }
public static int getSkip(AutoBuffer ab, int leftSize, boolean regression) { int numLeaves = 0; int numLeftLeaves = 0; int startPos = ab.position(); boolean prevIsS = false; while (ab.position() < startPos + leftSize) { byte currentNodeType = (byte) ab.get1(); if (currentNodeType == 'S' || currentNodeType == 'E') { ab.get2(); ab.get4f(); // skip col and split value. int skipSize = ab.get1(); if (skipSize == 0) { ab.get3();} prevIsS = true; } else if (currentNodeType == '[') { numLeaves ++; if (regression) ab.get4f(); else ab.get1(); if (prevIsS) numLeftLeaves++; prevIsS = false; } else { throw new NotImplementedException(); } } ab.position(startPos); return 2*numLeaves - numLeftLeaves; // only for regression tree. }
public static double classify( AutoBuffer ts, double[] ds, double badat, boolean regression ) { ts.get4(); // Skip tree-id ts.get8(); // Skip seed ts.get1(); // Skip producer id byte b; while( (b = (byte) ts.get1()) != '[' ) { // While not a leaf indicator assert b == '(' || b == 'S' || b == 'E'; int col = ts.get2(); // Column number in model-space float fcmp = ts.get4f(); // Float to compare against float fdat = Double.isNaN(ds[col]) ? fcmp - 1 : (float)ds[col]; int skip = (ts.get1()&0xFF); if( skip == 0 ) skip = ts.get3(); if (b == 'E') { if (fdat != fcmp) ts.position(ts.position() + skip); } else { // Picking right subtree? then skip left subtree if( fdat > fcmp ) ts.position(ts.position() + skip); } } if(regression) return ts.get4f(); return ts.get1()&0xFF; // Return the leaf's class }
public long[] getA8( ) { _arys++; // Get the lengths of lead & trailing zero sections, and the non-zero // middle section. int x = getInt(); if( x == -1 ) return null; int y = getInt(); // Non-zero in the middle int z = y==0 ? 0 : getInt();// Trailing zeros long[] buf = MemoryManager.malloc8(x+y+z); switch( get1() ) { // 1,2,4 or 8 for how the middle section is passed case 1: for( int i=x; i<x+y; i++ ) buf[i] = get1(); return buf; case 2: for( int i=x; i<x+y; i++ ) buf[i] = (short)get2(); return buf; case 4: for( int i=x; i<x+y; i++ ) buf[i] = get4(); return buf; case 8: break; default: throw H2O.fail(); } int sofar = x; while( sofar < x+y ) { LongBuffer as = _bb.asLongBuffer(); int more = Math.min(as.remaining(), x+y - sofar); as.get(buf, sofar, more); sofar += more; _bb.position(_bb.position() + as.position()*8); if( sofar < x+y ) getSp(Math.min(_bb.capacity()-7, (x+y-sofar)*8)); } return buf; } public double[] getA8d( ) {
/** Classify this serialized tree - withOUT inflating it to a full tree. Use row 'row' in the dataset 'ary' (with pre-fetched bits 'databits') Returns classes from 0 to N-1*/ public static float classify( AutoBuffer ts, Chunk[] chks, int row, int modelDataMap[], short badData, boolean regression ) { ts.get4(); // Skip tree-id ts.get8(); // Skip seed ts.get1(); // Skip producer id byte b; while( (b = (byte) ts.get1()) != '[' ) { // While not a leaf indicator assert b == '(' || b == 'S' || b == 'E'; int col = modelDataMap[ts.get2()]; // Column number in model-space mapped to data-space float fcmp = ts.get4f(); // Float to compare against if( chks[col].isNA0(row) ) return badData; float fdat = (float)chks[col].at0(row); int skip = (ts.get1()&0xFF); if( skip == 0 ) skip = ts.get3(); if (b == 'E') { if (fdat != fcmp) ts.position(ts.position() + skip); } else { // Picking right subtree? then skip left subtree if( fdat > fcmp ) ts.position(ts.position() + skip); } } if (regression) { return ts.get4f(); } return (float)((short) ( ts.get1()&0xFF )); // Return the leaf's class }
ab.get1(); // Skip producer id int cap = 0; String abString = ab.toString(); ab.get1(); // Skip producer id while (ab.position() < cap) { byte currentNodeType = (byte) ab.get1(); if (currentNodeType == 'S') { int _col = ab.get2(); sb.p("C").p(_col).p(" <= ").p(splitValue).p("("); } else if (currentNodeType == '[') { int cls = ab.get1(); sb.p("["+cls+"]");
public final TreeVisitor<T> visit() throws T { byte b = (byte) _ts.get1(); if( b == '[' ) { if (_regression) return leafFloat(_ts.get4f()); return leaf(_ts.get1()&0xFF); } assert b == '(' || b == 'S' || b =='E' : b; int off0 = _ts.position()-1; // Offset to start of *this* node int col = _ts.get2(); // Column number float fcmp = _ts.get4f(); // Float to compare against int skip = (_ts.get1()&0xFF); if( skip == 0 ) skip = _ts.get3(); int offl = _ts.position(); // Offset to start of *left* node int offr = _ts.position()+skip; // Offset to start of *right* node return pre(col,fcmp,off0,offl,offr).visit().mid(col,fcmp).visit().post(col,fcmp); } }
try { if( _read ) { // Reader? int x = get1(); // Read 1 more byte assert x == 0xab : "AB.close instead of 0xab sentinel got "+x+", "+this; assert _chan != null; // chan set by incoming reader, since we KNOW it is a TCP
public final void visit() throws T { int nodeType = _ts.get1(); int col = _ts.get2(); if( col==65535 ) { leaf2(nodeType); return; } int equal = (nodeType&12) >> 2; int naSplitDirInt = _ts.get1(); int skip = 0; switch(lmask) { case 0: skip = _ts.get1(); break; case 1: skip = _ts.get2(); break; case 2: skip = _ts.get3(); break;
@Override public Enum read( AutoBuffer ab ) { assert _map == null || _map.size()==0; _map = null; if( ab.get1() == 1 ) return this; // Killed? _maxId = ab.get4(); _map = new NonBlockingHashMap<ValueString, Integer>(); int len = 0; while( (len = ab.get2()) != 65535 ) // Read until end-of-map marker _map.put(new ValueString(ab.getA1(len)),ab.get4()); return this; } }