SChunk.filler#

SChunk.filler(inputs_tuple, schunk_dtype, nelem=None)#

Decorator to set a filler function.

This function will fill self according to nelem. It will receive three parameters: a tuple with the inputs as ndarrays from which to read, the ndarray to fill self and the offset inside the SChunk instance where the corresponding block begins (see example below).

Parameters:
  • inputs_tuple (tuple of tuples) – Tuple which will contain a tuple for each argument that the function will receive with their corresponding np.dtype. The supported operand types are SChunk, ndarray and Python scalars.

  • schunk_dtype (np.dtype) – The data type to use to fill self.

  • nelem (int) – Number of elements to append to self. If None (default) it will be the number of elements from the operands.

Returns:

out

Return type:

None

Notes

  • Compression nthreads must be 1 when using this.

  • This does not need to be removed from the created SChunk instance.

See also

prefilter()

Examples

# Set the compression and decompression parameters
schunk_dtype = np.dtype(np.float64)
cparams = {"typesize": schunk_dtype.itemsize, "nthreads": 1}
storage = {"cparams": cparams}
# Create empty SChunk
schunk = blosc2.SChunk(chunksize=20_000 * schunk_dtype.itemsize, **storage)

# Create operands
op_dtype = np.dtype(np.int32)
data = np.full(20_000 * 3, 12, dtype=op_dtype)
schunk_op = blosc2.SChunk(chunksize=20_000 * op_dtype.itemsize, data=data)

# Create filler
@schunk.filler(((schunk_op, op_dtype), (np.e, np.float32)), schunk_dtype)
def filler(inputs_tuple, output, offset):
    output[:] = inputs_tuple[0] - inputs_tuple[1]