Skip to content

Commit

Permalink
Parse VLEN metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
axelboc committed Aug 5, 2024
1 parent d96956a commit 6801969
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/hdf5_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/hdf5_util_helpers.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
9 changes: 9 additions & 0 deletions test/make_test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
2 changes: 2 additions & 0 deletions test/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand All @@ -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) {
Expand Down
Binary file added test/vlen.h5
Binary file not shown.
55 changes: 55 additions & 0 deletions test/vlen_test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env node

import { strict as assert } from 'assert';
import h5wasm from 'h5wasm/node';

async function vlen_test() {
await h5wasm.ready;
var f = new h5wasm.File('./test/vlen.h5', 'r');

assert.deepEqual(f.get('int8_scalar').metadata, {
type: 9,
shape: [],
maxshape: [],
chunks: null,
size: 8,
total_size: 1,
signed: true,
littleEndian: true,
vlen: false,
vlen_type: {
type: 0,
size: 1,
signed: true,
littleEndian: true,
vlen: false,
},
});

assert.deepEqual(f.get('float32_oneD').metadata, {
type: 9,
shape: [3],
maxshape: [3],
chunks: null,
size: 8,
total_size: 3,
signed: false,
littleEndian: true,
vlen: false,
vlen_type: {
type: 1,
size: 4,
signed: false,
littleEndian: true,
vlen: false,
},
});
}

export const tests = [
{
description: 'Read variable-length datasets',
test: vlen_test,
},
];
export default tests;

0 comments on commit 6801969

Please sign in to comment.