blosc2.register_filter#

blosc2.register_filter(id, forward, backward)#

Register an user defined filter.

Parameters:
  • id (int) – Filter id, must be between 160 and 255 (both included).

  • forward (Python function) – This will receive an input to apply the filter as a ndarray of dtype uint8, an output to fill as a ndarray of dtype uint8, the filter meta and the corresponding SChunk instance.

  • backward (Python function) – This will receive an input as a ndarray of dtype uint8, an output to fill as a ndarray of dtype uint8, the filter meta and the SChunk instance.

Returns:

out

Return type:

None

Notes

  • Cannot use multi-threading when using an user defined filter.

  • User defined filters can only be used inside a SChunk instance.

See also

register_codec()

Examples

# Define forward and backward functions
def forward(input, output, meta, schunk):
    nd_input = input.view(dtype)
    nd_output = output.view(dtype)

    nd_output[:] = nd_input + 1

def backward(input, output, meta, schunk):
    nd_input = input.view(dtype)
    nd_output = output.view(dtype)

    nd_output[:] = nd_input - 1

# Register filter
id = 160
blosc2.register_filter(id, forward, backward)