-
Notifications
You must be signed in to change notification settings - Fork 163
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
H5Easy support for complex integral type #828
Conversation
Thank you for your PR. What makes you confident that Reading cppreference I find:
https://en.cppreference.com/w/cpp/numeric/complex |
Good point! I am using the complex type in a context where I do not have to worry (and was not thinking) about operations on the integral types. These can indeed yield unexpected behaviour, if not done right, i.e. may have to return floating point types even for an integral input type. For example, considering the documentation at
it seems as if That said, I think that it is up to a programmer to consider the consequences of working with integral types. A compiler may intervene in case of undefined functions or operators. I do not see that the scope of HighFive, i.e. storage and retrieval of data, would be affected by these constraints. |
I agree that HighFive doesn't need have an opinion on whether Next, I think we should find out how widely supported |
Could a corresponding unit test be derived from the test at https://github.com/BlueBrain/HighFive/blob/master/tests/unit/tests_high_five_easy.cpp#L79 ? I was unable to run the unit tests as currently available from the master branch using the script |
Yes, that seems like a starting point. I usually use
If you want to turn off Boost (which is On by default) you add You probably also want to add |
… double and integral (int32)
Pull request now includes tests for complex types. All tests pass:
Datatypes are verified to be correct using h5py 3.7.0 on Debian 12:
HDF compass 0.7 correctly displays the complex integral quantities as compound type with components 'r' and 'i', albeit it does not display the numbers as complex quantities. vitables 3.0.2 refuses to deal with the datatype. However, this is an issue with the implementation in the respective projects and not related to hdf5 or HighFive. |
Codecov ReportAll modified lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #828 +/- ##
==========================================
+ Coverage 84.62% 84.68% +0.06%
==========================================
Files 68 68
Lines 4792 4812 +20
==========================================
+ Hits 4055 4075 +20
Misses 737 737
☔ View full report in Codecov by Sentry. |
I see you've had your share of compiler fun.
From what I can tell HDF5 doesn't have a complex datatype (probably because C doesn't have one). Hence, projects need to make their own convention, e.g. via a compound datatype. What HighFive does seems to match what h5py does. When converting to a Numpy array, it uses the existing numpy complex types. It seems numpy only support floating-point complex numbers, at least I can spot integer-based floating point numbers: This probably explains why vitables (which probably uses h5py and numpy) doesn't know what to do with these datatypes. @unbtorsten given the limitation this faces in Python, does the above still solve your problem? |
|
Indeed. I remember the struggles of early vitables (version 2.x?) before it implemented the complex-convention of a r/i-compound..
It does, and it does so reliably. The data storage has been working without issues since I amended HighFive. h5py (v3.7.0) readily reads in the compound as complex128 floating point in case of vectors. For scalars, numbers can be casted without hurdle. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the nice PR.
My pleasure and the least I could do. This project has allowed me to integrate hdf5 very efficiently. Thank you! |
Description
Among other functionality, H5Easy allows reading and writing of vectors of standard types.
However, an assertion prevents use of vector of complex integral numbers for
H5Easy::load
andH5Easy::dump
.Example:
This pull request modifies the the assertion to allow integral types and enable H5Easy support for complex integral type.
How to test this?
I have tested the modified code in a non-public application for
complex<int16_t>
.I have not tested other cases at this time, but would be happy to extend HighFive test's where appropriate. I am not familiar with the development of this library at this time.Furthermore, this pull requests extends HighFive's unit tests.Test System