blosc2.pack_tensor#
- blosc2.pack_tensor(tensor, chunksize=None, **kwargs)#
Pack (compress) a TensorFlow / PyTorch tensor or a NumPy array.
- Parameters:
tensor¶ (tensor, ndarray.) – The tensor / array to be packed.
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 serialized version (cframe) of the array. If urlpath is provided, the number of bytes in file is returned instead.
- Return type:
bytes | int
Examples
>>> import numpy as np >>> th = np.arange(1e6, dtype=np.float32) >>> cframe = blosc2.pack_tensor(th) >>> if not os.getenv("BTUNE_TRADEOFF"): ... assert len(cframe) < th.size * th.itemsize ...
See also