byte_offset: Byte Offset compression/decompression

This module provides a class for CBF byte offset compression/decompression.

class ByteOffset(raw_size=None, dec_size=None, ctx=None, devicetype='all', platformid=None, deviceid=None, block_size=None, profile=False)[source]

Bases: OpenclProcessing

Perform the byte offset compression/decompression on the GPU

See OpenclProcessing for optional arguments description.

Parameters
  • raw_size (int) – Size of the raw stream for decompression. It can be (slightly) larger than the array.

  • dec_size (int) – Size of the decompression output array (mandatory for decompression)

decode(raw, as_float=False, out=None)[source]

This function actually performs the decompression by calling the kernels

Parameters
  • raw (numpy.ndarray) – The compressed data as a 1D numpy array of char.

  • as_float (bool) – True to decompress as float32, False (default) to decompress as int32

  • out (pyopencl.array) – pyopencl array in which to place the result.

Returns

The decompressed image as an pyopencl array.

Return type

pyopencl.array

encode(data, out=None)[source]

Compress data to CBF.

Parameters
  • data (Union[numpy.ndarray, pyopencl.array.Array]) – The data to compress as a numpy array (or a pyopencl Array) of int32.

  • out (pyopencl.array) – pyopencl array of int8 in which to store the result. The array should be large enough to store the compressed data.

Returns

The compressed data as a pyopencl array. If out is provided, this array shares the backing buffer, but has the exact size of the compressed data and the queue of the ByteOffset instance.

Return type

pyopencl.array

Raises

ValueError – if out array is not large enough

encode_to_bytes(data)[source]

Compresses data to CBF and returns compressed data as bytes.

Usage:

Provided an image (image) stored as a numpy array of int32, first, create a byte offset compression/decompression object:

>>> from silx.opencl.codec.byte_offset import ByteOffset
>>> byte_offset_codec = ByteOffset()

Then, compress an image into bytes:

>>> compressed = byte_offset_codec.encode_to_bytes(image)
Parameters

data (Union[numpy.ndarray, pyopencl.array.Array]) – The data to compress as a numpy array (or a pyopencl Array) of int32.

Returns

The compressed data as bytes.

Return type

bytes