From d54951adf607d1c20e1b71af3587c231db63143e Mon Sep 17 00:00:00 2001 From: Marta Iborra Date: Wed, 24 Jan 2024 10:01:38 +0100 Subject: [PATCH] Add int_trunc filter --- blosc2/__init__.py | 1 + .../autofiles/top_level/blosc2.Filter.rst | 2 ++ tests/test_compress2.py | 31 +++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/blosc2/__init__.py b/blosc2/__init__.py index d528b728..6b8730f7 100644 --- a/blosc2/__init__.py +++ b/blosc2/__init__.py @@ -46,6 +46,7 @@ class Filter(Enum): NDCELL = 32 NDMEAN = 33 BYTEDELTA = 35 + INT_TRUNC = 36 class SplitMode(Enum): diff --git a/doc/reference/autofiles/top_level/blosc2.Filter.rst b/doc/reference/autofiles/top_level/blosc2.Filter.rst index 90eb1b74..18f6240e 100644 --- a/doc/reference/autofiles/top_level/blosc2.Filter.rst +++ b/doc/reference/autofiles/top_level/blosc2.Filter.rst @@ -16,4 +16,6 @@ ~Filter.TRUNC_PREC ~Filter.NDCELL ~Filter.NDMEAN + ~Filter.BYTEDELTA + ~Filter.INT_TRUNC \ No newline at end of file diff --git a/tests/test_compress2.py b/tests/test_compress2.py index 1e35f8ca..bc5b597b 100644 --- a/tests/test_compress2.py +++ b/tests/test_compress2.py @@ -68,6 +68,37 @@ def test_compress2_numpy(obj, cparams, dparams, gil): assert np.array_equal(dest4, obj) +@pytest.mark.parametrize("gil", [True, False]) +@pytest.mark.parametrize( + "obj, cparams, dparams", + [ + ( + np.random.randint(0, 10, 10, dtype=np.int64), + {"codec": blosc2.Codec.LZ4, "clevel": 6, "filters_meta": [-50]}, + {} + ), + ( + np.arange(10, dtype="int32"), + {"filters_meta": [-20]}, + {"nthreads": 4}, + ), + (np.arange(45, dtype=np.int16), {"codec": blosc2.Codec.LZ4HC, "filters_meta": [-10]}, {}), + (np.arange(50, dtype=np.int8), {"filters_meta": [-5]}, blosc2.dparams_dflts), + ], +) +def test_compress2_int_trunc(obj, cparams, dparams, gil): + blosc2.set_releasegil(gil) + cparams["filters"] = [blosc2.Filter.INT_TRUNC] + cparams["typesize"] = obj.dtype.itemsize + c = blosc2.compress2(obj, **cparams) + + dest = np.empty(obj.shape, obj.dtype) + blosc2.decompress2(c, dst=dest, **dparams) + + for i in range(obj.shape[0]): + assert (obj[i] - dest[i]) <= (2**((-1)*cparams["filters_meta"][0])) + + @pytest.mark.parametrize("gil", [True, False]) @pytest.mark.parametrize( "nbytes, cparams, dparams",