blosc2.unpack_tensor#

blosc2.unpack_tensor(cframe: bytes) tensorflow.Tensor | torch.Tensor | np.ndarray#

Unpack (decompress) a packed TensorFlow or PyTorch tensor or a NumPy array from a cframe.

Parameters:

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

Returns:

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

Return type:

tensorflow.Tensor, torch.Tensor, or np.ndarray

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

  • RunTimeError – If an error occurs during decompression.

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