SChunk.fill_special#
- SChunk.fill_special(nitems: int, special_value: SpecialValue, value: bytes | int | float | bool = None) int #
Fill the SChunk with a special value. SChunk must be empty.
- Parameters:
nitems¶ (int) – The number of items to fill with the special value.
special_value¶ (SpecialValue) – The special value to be used for filling the SChunk.
value¶ (bytes, int, float, bool (optional)) – The value to fill the SChunk. This parameter is only supported if
special_value
isblosc2.SpecialValue.VALUE
.
- Returns:
out – The number of chunks in the SChunk.
- Return type:
int
- Raises:
RunTimeError – If the SChunk could not be filled with the special value.
Examples
>>> import blosc2 >>> import numpy as np >>> import time >>> nitems = 100_000_000 >>> dtype = np.dtype(np.float64) >>> # Measure the time to create SChunk from a NumPy array >>> t0 = time.time() >>> data = np.full(nitems, np.pi, dtype) >>> schunk = blosc2.SChunk(data=data, cparams={"typesize": dtype.itemsize}) >>> t = (time.time() - t0) * 1000. >>> f"Time creating a schunk with a numpy array: {t:10.3f} ms" Time creating a schunk with a numpy array: 710.273 ms >>> # Measure the time to create SChunk using fill_special >>> t0 = time.time() >>> schunk = blosc2.SChunk(cparams={"typesize": dtype.itemsize}) >>> schunk.fill_special(nitems, blosc2.SpecialValue.VALUE, np.pi) >>> t = (time.time() - t0) * 1000. >>> f"Time passing directly the value to `fill_special`: {t:10.3f} ms" Time passing directly the value to `fill_special`: 2.109 ms