From 6801969055af9fa0a582d13c684b13f41c0f0288 Mon Sep 17 00:00:00 2001 From: Axel Bocciarelli Date: Mon, 5 Aug 2024 09:08:32 +0200 Subject: [PATCH] Parse VLEN metadata --- src/hdf5_util.cc | 6 ++++ src/hdf5_util_helpers.d.ts | 1 + test/make_test_files.py | 9 ++++++ test/test.mjs | 2 ++ test/vlen.h5 | Bin 0 -> 6208 bytes test/vlen_test.mjs | 55 +++++++++++++++++++++++++++++++++++++ 6 files changed, 73 insertions(+) create mode 100644 test/vlen.h5 create mode 100644 test/vlen_test.mjs diff --git a/src/hdf5_util.cc b/src/hdf5_util.cc index 0a5191d..b2aadff 100644 --- a/src/hdf5_util.cc +++ b/src/hdf5_util.cc @@ -303,6 +303,12 @@ val get_dtype_metadata(hid_t dtype) array_type.set("total_size", total_size); attr.set("array_type", array_type); } + else if (dtype_class == H5T_VLEN) { + hid_t base_dtype = H5Tget_super(dtype); + val vlen_type = get_dtype_metadata(base_dtype); + H5Tclose(base_dtype); + attr.set("vlen_type", vlen_type); + } else if (dtype_class == H5T_ENUM) { val enum_type = val::object(); val members = val::object(); diff --git a/src/hdf5_util_helpers.d.ts b/src/hdf5_util_helpers.d.ts index ea05200..5857432 100644 --- a/src/hdf5_util_helpers.d.ts +++ b/src/hdf5_util_helpers.d.ts @@ -23,6 +23,7 @@ export interface Metadata { compound_type?: CompoundTypeMetadata, cset?: number, enum_type?: EnumTypeMetadata, + vlen_type?: Metadata, littleEndian: boolean, maxshape: number[] | null, ref_type?: 'object' | 'region', diff --git a/test/make_test_files.py b/test/make_test_files.py index 68fccb2..b50a45a 100644 --- a/test/make_test_files.py +++ b/test/make_test_files.py @@ -33,3 +33,12 @@ with h5py.File("empty.h5", "w") as f: f.create_dataset("empty_dataset", data=h5py.Empty("f")) f.attrs["empty_attr"] = h5py.Empty("f") + +with h5py.File("vlen.h5", "w") as f: + vlen_scalar = f.create_dataset("int8_scalar", shape=(), dtype=h5py.vlen_dtype(np.int8)) + vlen_scalar[()] = [0, 1] + + vlen_array = f.create_dataset("float32_oneD", shape=(3,), dtype=h5py.vlen_dtype(np.float32)) + vlen_array[0] = [0] + vlen_array[1] = [0, 1] + vlen_array[2] = [0, 1, 2] diff --git a/test/test.mjs b/test/test.mjs index 7af6c09..9e69bf7 100644 --- a/test/test.mjs +++ b/test/test.mjs @@ -18,6 +18,7 @@ import dimension_scales from './dimension_scales.mjs'; import references from './create_read_references.mjs'; import test_throwing_error_handler from './test_throwing_error_handler.mjs'; import test_empty from './empty_dataset_and_attrs.mjs'; +import vlen_test from './vlen_test.mjs'; let tests = []; const add_tests = (tests_in) => { /*global*/ tests = tests.concat(tests_in)} @@ -39,6 +40,7 @@ add_tests(dimension_scales); add_tests(references); add_tests(test_throwing_error_handler); add_tests(test_empty); +add_tests(vlen_test); let passed = true; async function run_test(test) { diff --git a/test/vlen.h5 b/test/vlen.h5 new file mode 100644 index 0000000000000000000000000000000000000000..4fabfdbbab6780b45563fc8b40ba8ecf39670347 GIT binary patch literal 6208 zcmeHL%}T>S5S~q22t_eHRlS&_$D$W+t(e#z#EN?GR)Z)Ar3LN5n>p4u@DY3z-%58f z^F@eQPlAw{vYFpqnvZX$Y+pvn@p^l^O)OzZO^ON=j}Mi>rbOT)f31d7y;S`ch~bDo zM7o_idVaO;@;pt+SK@qVJ&t-!u|fn)*9w7AdU(b!e5G%_tNLAerY_yj76+5Zn{1jr z6rsE6JX`GVP3E)PgahDd4;y~bj#{!uH#!mq;+%$OHrrc%apy!nEjg)c`Fi$)K*FJR zLIVd?`i