Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalise H5T enums and use them to initialise types #1658

Merged
merged 1 commit into from
Jun 4, 2024
Merged

Conversation

axelboc
Copy link
Contributor

@axelboc axelboc commented Jun 4, 2024

[email protected] has just been released with the new strpad metadata property to address #1621.

Since this is another case where we need to map an H5T enum number to a more readable string, and since both h5grove and h5wasm expose a few of those raw enum values now (dtype class, charset, sign, order), I thought I'd first normalise things a bit...

  1. I create a h5t.ts file in the shared package to hold the H5T enums and their mappings to readable strings.
    The enums and their keys are named as closely to the HDF5 spec as possible (though I don't specify keys for errors (-1) and reserved values — I'll explain why in a comment.)
  2. I refactor the dtype factories (stringType(), intType(), etc.) to accept H5T enum values; it is now there responsibility to convert those values to readable strings ('little-endian', etc.) using the mappings in h5t.ts instead of the providers.

Hopefully this makes sense. I'll add some more comments.

@axelboc axelboc force-pushed the h5t-enums branch 2 times, most recently from 007e484 to 63b513e Compare June 4, 2024 12:28
return intOrUintType(
signed ? H5T_SIGN.SIGN_2 : H5T_SIGN.NONE,
size * 8,
littleEndian ? H5T_ORDER.LE : H5T_ORDER.BE,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

h5wasm exposes two booleans: signed and littleEndian. It might be better to expose the raw H5T enum values instead/as well, like in h5grove, since the enums have more than two values: https://docs.hdfgroup.org/hdf5/v1_14/_h5_tpublic_8h.html#title3 (H5T_NSGN, H5T_ORDER_MIXED, etc.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it planned than h5wasm eventually exposes the enum values ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet, but I'll make a note of it.

export enum H5T_SIGN {
NONE = 0, // unsigned
SIGN_2 = 1, // signed
NSGN = 2,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what this enum member represents, TBH.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even the HDF people don't know apparently: https://docs.hdfgroup.org/hdf5/v1_14/_h5_tpublic_8h.html#af7bfee2db210a12b9290eba85d730a71

Perhaps @t20100 has an idea ?

packages/shared/src/h5t.ts Show resolved Hide resolved
@axelboc axelboc requested a review from loichuder June 4, 2024 12:41
Copy link
Member

@loichuder loichuder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done 👍

return intOrUintType(
signed ? H5T_SIGN.SIGN_2 : H5T_SIGN.NONE,
size * 8,
littleEndian ? H5T_ORDER.LE : H5T_ORDER.BE,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it planned than h5wasm eventually exposes the enum values ?

export enum H5T_SIGN {
NONE = 0, // unsigned
SIGN_2 = 1, // signed
NSGN = 2,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even the HDF people don't know apparently: https://docs.hdfgroup.org/hdf5/v1_14/_h5_tpublic_8h.html#af7bfee2db210a12b9290eba85d730a71

Perhaps @t20100 has an idea ?

@axelboc axelboc merged commit 6c1678e into main Jun 4, 2024
8 checks passed
@axelboc axelboc deleted the h5t-enums branch June 4, 2024 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants