blosc2.unpack_tensor#

blosc2.unpack_tensor(cframe)#

Unpack (decompress) a packed TensorFlow / PyTorch via a cframe.

Parameters:

cframe (bytes) – The packed tensor to be restored.

Returns:

out – The unpacked TensorFlow / PyTorch tensor or NumPy array.

Return type:

tensor, ndarray

Raises:
  • TypeError – If cframe is not of type bytes, or not a cframe.

  • RunTimeError – If some other problem is detected.

Examples

>>> import os
>>> import numpy as np
>>> th = np.arange(1e3, dtype=np.float32)
>>> cframe = blosc2.pack_tensor(th)
>>> if not os.getenv("BTUNE_TRADEOFF"):
...     assert len(cframe) < th.size * th.itemsize
...
>>> th2 = blosc2.unpack_tensor(cframe)
>>> a = np.asarray(th)
>>> a2 = np.asarray(th2)
>>> np.array_equal(a, a2)
True