blosc2.load_tensor#

blosc2.load_tensor(urlpath, **kwargs)#

Load a serialized PyTorch / TensorFlow tensor or NumPy array in urlpath.

Parameters:
  • urlpath (str) – The file where the tensor / array is to be loaded.

  • kwargs (dict, optional) –

    Keyword arguments supported: dparams: dict

    A dictionary with the decompression parameters, which are the same that can be used in the decompress2() function.

Returns:

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

Return type:

tensor, ndarray

Raises:
  • TypeError – If urlpath is not in cframe format

  • RunTimeError – If some other problem is detected.

Examples

>>> import numpy as np
>>> th = np.arange(1e6, dtype=np.float32)
>>> size = blosc2.save_tensor(th, "test.bl2", mode="w")
>>> if not os.getenv("BTUNE_TRADEOFF"):
...     assert size < th.size * th.itemsize
...
>>> th2 = blosc2.load_tensor("test.bl2")
>>> np.array_equal(th, th2)
True