unsigned int DataBuffer::latticeReadUintArray( iobFile *infile ) { unsigned int sz, inand, inor; infile->readUI( sz ); inand = newUintArray( sz ); infile->readUIArray( uintArrays[inand]->u, sz ); infile->readUI( sz ); inor = newUintArray( sz ); infile->readUIArray( uintArrays[inor]->u, sz ); unsigned int returnid = newUintArray( sz ); unsigned int prev = 0; for (unsigned int i=0; i<sz; i++) { unsigned int iand = getUint( inand, i ); unsigned int ior = getUint( inor, i ); unsigned int b = (prev & iand) | (~prev & ior); addUint( returnid, b ); prev = b; } deleteUintArray( inand ); deleteUintArray( inor ); return returnid; }
float DataBuffer::quantizeFloatArray( unsigned int id, unsigned int precisionBits ) { assert( id < ((unsigned int) floatArrays.size()) ); assert( floatArrays[id] != NULL ); assert( precisionBits < 32 ); assert( precisionBits > 1 ); floatArrays[id]->bits = precisionBits; double error = 0.0; double shift = (double) (1 << precisionBits); double interval = double(floatArrays[id]->maxf - floatArrays[id]->minf); double invShift = 1.0 / shift; double invInterval = 1.0 / interval; for (unsigned int i=0; i<floatArrays[id]->sz; i++) { double normf = double(floatArrays[id]->f[i] - floatArrays[id]->minf) * invInterval; unsigned int quantized = unsigned(normf * shift); //floatArrays[id]->q[i] = unsigned(normf * shift); addUint( floatArrays[id]->qid, quantized ); error += fabs( floatArrays[id]->f[i] - (quantized*invShift*interval + floatArrays[id]->minf) ); } return float(error); }
INLINE void wxeReturn::add(wxMouseState val) { addAtom("wxMouseState"); // TODO not int? addUint(val.GetX()); addUint(val.GetY()); addBool(val.LeftDown()); addBool(val.MiddleDown()); addBool(val.RightDown()); addBool(val.ControlDown()); addBool(val.ShiftDown()); addBool(val.AltDown()); addBool(val.MetaDown()); addBool(val.CmdDown()); addTupleCount(11); }
INLINE void wxeReturn::addRef(const unsigned int ref, const char* className) { addAtom("wx_ref"); addUint(ref); addAtom(className); rt.Add(ERL_DRV_NIL); addTupleCount(4); }
void DataBuffer::latticeWriteUintArray( unsigned int id, iobFile *outfile ) { assert( id < ((unsigned int) uintArrays.size()) ); unsigned int outand = newUintArray( uintArrays[id]->sz ); unsigned int outor = newUintArray( uintArrays[id]->sz ); unsigned int prev = 0; for (unsigned int i=0; i<uintArrays[id]->sz; i++) { addUint( outand, uintArrays[id]->u[i] & prev ); addUint( outor, uintArrays[id]->u[i] | prev ); prev = uintArrays[id]->u[i]; } outfile->writeUIArray( uintArrays[outand]->u, uintArrays[outand]->sz ); outfile->writeUIArray( uintArrays[outor]->u, uintArrays[outor]->sz ); deleteUintArray( outand ); deleteUintArray( outor ); }