blosc2.save_tensor#
- blosc2.save_tensor(tensor: tensorflow.Tensor | torch.Tensor | np.ndarray, urlpath: str, chunksize: int = None, **kwargs: dict) int #
Save a serialized PyTorch or TensorFlow tensor or NumPy array to a specified file path.
- Parameters:
tensor¶ (tensorflow.Tensor, torch.Tensor, or np.ndarray) – The tensor or array to be saved.
urlpath¶ (str) – The file path where the tensor or array will be 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 or 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 ...
See also