Skip to content

Commit

Permalink
Add int_trunc filter
Browse files Browse the repository at this point in the history
  • Loading branch information
martaiborra committed Jan 24, 2024
1 parent a1412ca commit d54951a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions blosc2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Filter(Enum):
NDCELL = 32
NDMEAN = 33
BYTEDELTA = 35
INT_TRUNC = 36


class SplitMode(Enum):
Expand Down
2 changes: 2 additions & 0 deletions doc/reference/autofiles/top_level/blosc2.Filter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@
~Filter.TRUNC_PREC
~Filter.NDCELL
~Filter.NDMEAN
~Filter.BYTEDELTA
~Filter.INT_TRUNC

31 changes: 31 additions & 0 deletions tests/test_compress2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit d54951a

Please sign in to comment.