-
Notifications
You must be signed in to change notification settings - Fork 137
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 numbers from HDF5 #180
Comments
It doesn't so much fail as need some help:
My suspicion is that the best way to handle this would be with a separate module dedicated to reading particular formatting conventions. There's nothing in your h5 file that says "this structure with fields r and i is to be interpreted as a complex number." But an |
When I filed the bug it really did fail, but I just updated from v0.4.6 to v0.4.7 and now it outputs a compound data type as expected. Thanks for the tips on how to move forward. So the goal is an H5PY module similar to JLD.jl, but with much less complexity? Like yourself I am quite busy with other things, but I may get around to it at some point. |
Yes. I have long-term plans to split JLD out into a separate repository, so probably that would be best for H5PY, too. In other words, it could be your own package. MAT is another example, and probably closest in spirit to what you're trying to achieve. |
On 12/03/2014 11:16 AM, Tim Holy wrote:
Thanks, that looks like a much better module to base this on. |
Sorry to necro an old issue, but I was struggling with this today and this issue was high on the list of search results. The I'm a pretty green Julia programmer, but I managed to cobble something together in this gist: https://gist.github.com/bhawkins/6edaab42b9907758eeb58a24399b9426 You can use the low-level HDF5.jl routines to create the h5py complex type given a Julia Complex{T} and vice-versa. The other difficulty I had was not being able to slice datasets with compound types, so you can't write I also noticed that |
I think that complex number support would be nice to have built into HDF5.jl. Requiring a general serialization framework like JLD or writing custom code just to conveniently save/load arrays of complex numbers feels like overkill. The precedent of h5py/octave seem to indicate that transparently adding complex number support to hdf5 wrappers via compound datatypes is a reasonable approach. Would people be open to a pull request implementing this approach? |
@kleinhenz PRs that improve HDF5.jl are always welcome |
@kleinhenz, @musm: I have started working on this, on this branch: write support is there, although I am not sure if I added it to the correct layer. Maybe it would be better to let Read support is still missing. |
Or more precisely: I know how to read and interpret the data, but we somehow need to special case the compound data code in that case, and I am not sure what would be the cleanest way for that. |
Although there is no standardized way of storing complex numbers in an HDF5 file, a few de facto standards have emerged using compound datatypes. Octave, for instance, uses a compound datatype with fields "real" and "imag", while pytables and h5py both use fields "r" and "i".
Since the goal is to get to the point where we can read any HDF5 file, I think it would be wonderful if HDF5.jl could load arrays from these files into arrays of complex numbers.
The following Python program can be used to make an HDF5 file with two matrices: one real and one complex:
The goal is to get Julia to load both matrices using the following code:
However, currently it fails on the last line while reading the array
m2
containing complex numbers.The text was updated successfully, but these errors were encountered: