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

Add support for complex dataset values in h5wasm #1111

Merged
merged 1 commit into from
May 11, 2022
Merged

Conversation

loichuder
Copy link
Member

@loichuder loichuder commented May 11, 2022

Thanks to v0.4.2 of h5wasm

I still have some issues with boolean which is why it is not included in this PR

export function convertMetadataToDType(metadata: NumericMetadata): NumericType;
export function convertMetadataToDType(metadata: Metadata): DType;
export function convertMetadataToDType(metadata: Metadata): DType {
if (isIntegerMetadata(metadata)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I reworked the switch to use dedicated guards to allow TS to infer the typing of metadata.

It allows more specific destructurings for Integer, Float and String but the important part is that compound metadata is correctly inferred.

if (nmembers === 2 && members[0].name === 'r' && members[1].name === 'i') {
const [realTypeMetadata, imagTypeMetadata] = members;
assertNumericMetadata(realTypeMetadata);
assertNumericMetadata(imagTypeMetadata);
Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks to this assertion and the overload of convertMetadataToDType above, TS knows that converting this will yield a NumericType removing the need to assert after conversion.

class: DTypeClass.Compound,
fields: Object.fromEntries(
members.map((member) => [member.name, convertMetadataToDType(member)])
),
Copy link
Member Author

Choose a reason for hiding this comment

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

Following our line of work in HSDS, we try to be as specific as possible even if it is not complex and that we don't provide visualizations for such types.

Copy link
Contributor

@axelboc axelboc 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 👍

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