From c1d2b7b9eba7a5c8b7fa4d611bacc64e79171950 Mon Sep 17 00:00:00 2001 From: Luigi Pertoldi Date: Sat, 28 Oct 2023 22:44:27 +0200 Subject: [PATCH] [sigcompress] improve decode with pre-allocated structure --- src/lgdo/compression/radware.py | 6 ++++++ tests/compression/test_radware_sigcompress.py | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/src/lgdo/compression/radware.py b/src/lgdo/compression/radware.py index f7f9bca0..8a72bc27 100644 --- a/src/lgdo/compression/radware.py +++ b/src/lgdo/compression/radware.py @@ -251,6 +251,12 @@ def decode( dtype=int32, attrs=sig_in.getattrs(), ) + else: + if not ( + isinstance(sig_out, lgdo.ArrayOfEqualSizedArrays) + and sig_out.nda.shape == (len(sig_in), sig_in.decoded_size.value) + ): + raise ValueError("sig_out is of the wrong format") siglen = np.empty(len(sig_in), dtype=uint32) # save original encoded vector lengths diff --git a/tests/compression/test_radware_sigcompress.py b/tests/compression/test_radware_sigcompress.py index ac634c36..2cb0d4f4 100644 --- a/tests/compression/test_radware_sigcompress.py +++ b/tests/compression/test_radware_sigcompress.py @@ -167,6 +167,13 @@ def test_aoesa(wftable): for wf1, wf2 in zip(dec_aoesa, wftable.values): assert np.array_equal(wf1, wf2) + # test using pre-allocated decoded array + sig_out = ArrayOfEqualSizedArrays( + shape=wftable.values.nda.shape, dtype=wftable.values.dtype + ) + decode(enc_vov, sig_out=sig_out, shift=shift) + assert wftable.values == sig_out + def test_performance(lgnd_test_data): store = LH5Store()