blosc2.save_tensor#

blosc2.save_tensor(tensor, urlpath, chunksize=None, **kwargs)#

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

Parameters:
  • tensor (tensor, ndarray) – The tensor / array to be saved.

  • urlpath (str) – The path for the file where the array is saved.

  • chunksize (int) – The size (in bytes) for the chunks during compression. If not provided, it is computed automatically.

  • kwargs (dict, optional) – These are the same as the kwargs in SChunk.__init__.

Returns:

out – The number of bytes of the saved tensor / array.

Return type:

int

Examples

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