Skip to content

Fix SZ and SZ3 from_filter_options for chunks with 3 or more dimensions - #412

Open
aaronkanzer wants to merge 1 commit into
silx-kit:mainfrom
aaronkanzer:fix/sz-from-filter-options-ndim
Open

aaronkanzer wants to merge 1 commit into
silx-kit:mainfrom
aaronkanzer:fix/sz-from-filter-options-ndim

Conversation

@aaronkanzer

Copy link
Copy Markdown

The SZ and SZ3 filters put the chunk shape at the start of the stored cd_values: (ndim, dtype, dims...), which is 4 values for 1D and 2D chunks and ndim + 2 values otherwise (see SZ_cdArrayToMetaDataErr in H5Z_SZ.c and H5Z_SZ3.cpp). SZ._from_filter_options and SZ3._from_filter_options always read the error bound mode at index 4, so for 3D or larger chunks they read a chunk dimension instead. Depending on the shape this raises or quietly returns the wrong filter.

import h5py, numpy, hdf5plugin
with h5py.File("sz.h5", "w") as f:
    f.create_dataset("d", data=numpy.random.random((8, 64, 64)).astype("f4"),
                     chunks=(4, 32, 32), compression=hdf5plugin.SZ3(absolute=1e-3))
with h5py.File("sz.h5") as f:
    fid, _, opts, _ = f["d"].id.get_create_plist().get_filter(0)
    print(hdf5plugin.from_filter_options(fid, opts))

Observed on 7.1.0 and main: ValueError: Unsupported sz_mode: 4. Chunks of (1, 2, 16, 16) give SZ3(norm2=0.0) instead of SZ3(absolute=0.001). Expected: SZ3(absolute=0.001) in both cases. 1D and 2D chunks work today, which is why the existing tests pass.

The fix drops the extra shape values before parsing, so the existing index layout still applies. New test cases cover 2D, 3D and 4D chunks for both filters.

The SZ filters prepend (ndim, dtype, dims...) to the cd_values: 4 values
for 1D and 2D chunks, ndim + 2 values otherwise. _from_filter_options
always read the error bound mode at index 4, so it raised
"Unsupported sz_mode" or returned the wrong config for 3D+ chunks.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant