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

Incorrect Reading of 8-bit Signed Char Attributes #5

Closed
a-shahba opened this issue Oct 4, 2024 · 4 comments
Closed

Incorrect Reading of 8-bit Signed Char Attributes #5

a-shahba opened this issue Oct 4, 2024 · 4 comments

Comments

@a-shahba
Copy link

a-shahba commented Oct 4, 2024

I was trying to read an array-valued attribute from an HDF file using PDL::IO::HDF5 package and noticed that the return value is incorrect. The attribute datatype is 8-bit signed char (H5T_STD_I8LE) and I expected the package to return [-127, 127], but instead it returned [129, 127]. Examining the source code, I found out why this is happening.

The code maps H5T_STD_I8LE to $PDL::Types::PDL_B here. However, $PDL::Types::PDL_B represents an unsigned char datatype. Therefore, the bits representing -127 in the buffer are interpreted as 129 by PDL.

To correct this behavior, I suggest that H5T_STD_I8LE and H5T_STD_I8BE are mapped to $PDL::Types::PDL_SB which represents signed char datatype.

@mohawk2
Copy link
Member

mohawk2 commented Oct 4, 2024

I agree! Feel like making a pull request implementing that? You'll need to add a test case similar to what triggered this.

@a-shahba
Copy link
Author

a-shahba commented Oct 4, 2024

Thanks, @mohawk2. Sure, I will work on it and submit a PR.

@mohawk2 mohawk2 closed this as completed in 8f5f19c Oct 9, 2024
@mohawk2
Copy link
Member

mohawk2 commented Oct 9, 2024

This is fixed and released as 0.76.

@a-shahba
Copy link
Author

Thanks. You are very fast. I was going to work on it this weekend.

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

No branches or pull requests

2 participants