def uniform(self, N, offset=0):
        '''
        Provide an array of random decimals following uniform distribution
        in the half-open range [0, 1).

        Parameters:
            N:  int
                Amount of provided decimals.
            offset: int
                Amount of bits at the beginning of the file to be skipped over.

        Returns:
            result: 1d numpy array
        '''
        sign = '0' # sign bit denoting positive
        exponent = '0' + '1' * 10 # exponent bits denoting 0
        prefix = "0b" + sign + exponent # the bit order entails big endian
        blob = Bits(filename=self.source, length=52*N, offset=offset)
        buf = Bits().join([prefix+mantissa for mantissa in blob.cut(52)])
        result = np.frombuffer(buf.bytes, dtype=">f8") - 1 # 64-bit double precision in big endian
        return result
 def testCut(self):
     s = Bits(30)
     for t in s.cut(3):
         self.assertEqual(t, [0] * 3)
Exemple #3
0
 def testCut(self):
     s = Bits(30)
     for t in s.cut(3):
         self.assertEqual(t, [0] * 3)
def _lzw_unpack_compressed(packed_ints):
	ints_count = len(packed_ints) * 8 // _LZW_NUM_SIZE;
	bits = Bits(bytes=packed_ints, length=ints_count * _LZW_NUM_SIZE)
	return [chunk.uint for chunk in bits.cut(_LZW_NUM_SIZE)]