Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# normalise inputs
buf = ensure_contiguous_ndarray(buf)
if out is not None:
out = ensure_contiguous_ndarray(out)
# N.B., bz2 cannot handle ndarray directly because of truth testing issues
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 ndarray_copy(dec, out)
# 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 ndarray_copy(dec, out)
def decode(self, buf, out=None):
# filter is lossy, decoding is no-op
dec = ensure_ndarray(buf).view(self.astype)
dec = dec.astype(self.dtype, copy=False)
return ndarray_copy(dec, out)
def decode(self, buf, out=None):
# normalise input
enc = ensure_ndarray(buf).view(self.astype)
# flatten to simplify implementation
enc = enc.reshape(-1, order='A')
# setup decoded output
dec = np.empty_like(enc, dtype=self.dtype)
# decode differences
np.cumsum(enc, out=dec)
# handle output
out = ndarray_copy(dec, out)
return out
def decode(self, buf, out=None):
# normalise inputs
buf = ensure_contiguous_ndarray(buf)
if out is not None:
out = ensure_contiguous_ndarray(out)
# do decompression
dec = _lzma.decompress(buf, format=self.format, filters=self.filters)
# handle destination
return ndarray_copy(dec, out)
def decode(self, buf, out=None):
# normalise inputs
buf = ensure_contiguous_ndarray(buf)
if out is not None:
out = ensure_contiguous_ndarray(out)
# 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 ndarray_copy(dec, out)
def encode(self, buf):
arr = ensure_contiguous_ndarray(buf).view('u1')
checksum = self.checksum(arr) & 0xffffffff
enc = np.empty(arr.nbytes + 4, dtype='u1')
enc[:4].view('
# normalise input
enc = ensure_ndarray(buf).view(self.astype)
# flatten to simplify implementation
enc = enc.reshape(-1, order='A')
# setup output
dec = np.full_like(enc, fill_value='', dtype=self.dtype)
# apply decoding
for i, l in enumerate(self.labels):
dec[enc == (i + 1)] = l
# handle output
dec = ndarray_copy(dec, out)
return dec
def decode(self, buf, out=None):
# normalise input
enc = ensure_ndarray(buf).view(self.encode_dtype)
# convert and copy
dec = enc.astype(self.decode_dtype)
# handle output
out = ndarray_copy(dec, out)
return out
def decode(self, buf, out=None):
arr = ensure_contiguous_ndarray(buf).view('u1')
expect = arr[:4].view('