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

Read complex values from .mat files via HDF5 C++ API #343

Merged
merged 5 commits into from
Jun 12, 2023

Conversation

willGraham01
Copy link
Collaborator

@willGraham01 willGraham01 commented Jun 6, 2023

Allows us to read complex MATLAB arrays via the HDF5 API.

To do this, we have to define (at runtime) a H5::CompType instance that describes the data-structure that needs to be read in - in this case, that describes the format in which MATLAB saves complex data. Note that there is no HDF5 standard for complex datatypes, so trying to read complex data from something like h5py- created files will require separate, but similar, treatment.

Implementation

The hdf5_compound_types.{h,cpp} file has been created to contain compound types.

Currently there is only one compound type, MATLAB_complex. But the following convention has been set given the remark above about compound datatypes and the lack of standard format for complex-values in particular:

  • Each compound type has it's own namespace within this file
  • Each namespace contains:
    • The struct that is compatible with the compound data-type to be read
    • A to_hdf5_CompType() method that returns a H5::CompType instance, that can be passed to the API to read data into the aforementioned struct via the read method.
    • Any number of helpful converter functions to std:: datatypes (or std::vectors thereof) so that we don't have to reimplement algebra.

Testing

Additional tests in test_hdf5_compound_types.cpp that check that:

  • The new overload of the HDF5Reader::read() method performs as expected for MATLAB_complex types
  • The other supporting functions in the namespace perform correctly.

@codecov
Copy link

codecov bot commented Jun 6, 2023

Codecov Report

Patch coverage: 63% and project coverage change: -1 ⚠️

Comparison is base (e8e9809) 27% compared to head (221a033) 26%.

Additional details and impacted files
@@         Coverage Diff         @@
##           main   #343   +/-   ##
===================================
- Coverage    27%    26%   -1%     
===================================
  Files        77     83    +6     
  Lines      3687   3687           
===================================
- Hits        978    949   -29     
- Misses     2709   2738   +29     
Impacted Files Coverage Δ
tdms/include/hdf5_io/hdf5_compound_types.h 0% <0%> (ø)
tdms/include/hdf5_io/hdf5_reader.h 0% <0%> (ø)
tdms/src/hdf5_io/hdf5_compound_types.cpp 86% <86%> (ø)

... and 20 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@willGraham01 willGraham01 added this pull request to the merge queue Jun 12, 2023
@samcunliffe
Copy link
Member

Nice!

Merged via the queue into main with commit b2396aa Jun 12, 2023
@willGraham01 willGraham01 deleted the compound_datatype branch June 12, 2023 11:25
@samcunliffe samcunliffe linked an issue Jun 13, 2023 that may be closed by this pull request
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.

Reading complex-valued arrays from HDF5 files.
2 participants