def decode(self, buf, out=None): arr = ndarray_from_buffer(buf, dtype='u1') expect = arr[:4].view('<u4')[0] checksum = self.checksum(arr[4:]) & 0xffffffff if expect != checksum: raise RuntimeError('checksum failed') return buffer_copy(arr[4:], out)
def decode(self, buf, out=None): # do decompression dec = _lzma.decompress(buf, format=self.format, filters=self.filters) # handle destination return buffer_copy(dec, out)
def decode(self, buf, out=None): # do decompression dec = _zlib.decompress(buf) # handle destination - Python standard library zlib module does not # support direct decompression into buffer, so we have to copy into # out if given return buffer_copy(dec, out)
def decode(self, buf, out=None): # view encoded data as 1D array enc = ndarray_from_buffer(buf, self.encode_dtype) # convert and copy dec = enc.astype(self.decode_dtype) # handle output out = buffer_copy(dec, out) return out
def decode(self, buf, out=None): # interpret buffer as 1D array enc = ndarray_from_buffer(buf, self.astype) # decode scale offset dec = (enc / self.scale) + self.offset # convert dtype dec = dec.astype(self.dtype, copy=False) # handle output return buffer_copy(dec, out)
def decode(self, buf, out=None): # BZ2 cannot handle ndarray directly at all, coerce everything to # memoryview if not isinstance(buf, array.array): buf = memoryview(buf) # do decompression dec = _bz2.decompress(buf) # handle destination - Python standard library bz2 module does not # support direct decompression into buffer, so we have to copy into # out if given return buffer_copy(dec, out)
def decode(self, buf, out=None): # view encoded data as ndarray enc = ndarray_from_buffer(buf, 'u1') # find out how many bits were padded n_bits_padded = int(enc[0]) # apply decoding dec = np.unpackbits(enc[1:]) # remove padded bits if n_bits_padded: dec = dec[:-n_bits_padded] # view as boolean array dec = dec.view(bool) # handle destination return buffer_copy(dec, out)
def decode(self, buf, out=None): # view encoded data as 1D array enc = ndarray_from_buffer(buf, self.astype) # setup decoded output if isinstance(out, np.ndarray): # optimization, can decode directly to out dec = out.reshape(-1, order='A') copy_needed = False else: dec = np.empty_like(enc, dtype=self.dtype) copy_needed = True # decode differences np.cumsum(enc, out=dec) # handle output if copy_needed: out = buffer_copy(dec, out) return out
def decode(self, buf, out=None): # view encoded data as ndarray enc = ndarray_from_buffer(buf, self.astype) # setup output if isinstance(out, np.ndarray): # optimization, decode directly to output dec = out.reshape(-1, order='A') copy_needed = False else: dec = np.zeros_like(enc, dtype=self.dtype) copy_needed = True # apply decoding for i, l in enumerate(self.labels): dec[enc == (i + 1)] = l # handle output if copy_needed: dec = buffer_copy(dec, out) return dec
def decode(self, buf, out=None): # filter is lossy, decoding is no-op dec = ndarray_from_buffer(buf, self.astype) dec = dec.astype(self.dtype, copy=False) return buffer_copy(dec, out)