Read complex datasets written by Julia HDF5.jl and h5py#40
Merged
Conversation
8b35796 to
f05415d
Compare
f05415d to
e3330a1
Compare
TRIQS/h5 stores complex arrays as a real array with a trailing-2 dim
plus a __complex__ attribute, while Julia HDF5.jl and h5py use the
standard {r,i} compound type (matching h5::dcplx_t). The scalar and
std::array read paths already handled compound complex; this extends
support to:
- python/h5/h5py_io.cpp: h5_read_bare reads compound-complex arrays
directly into NPY_CDOUBLE buffers.
- c++/h5/stl/vector.hpp: std::vector<std::complex<double>> reinterprets
rank-1 compound datasets as std::vector<dcplx_t>, mirroring std::array.
- c++/h5/array_interface.cpp: array_interface::read transparently swaps
a FLOAT view (with is_complex/trailing-2 dim) to a dcplx_t view when
the file dataset is the {r,i} compound, so generic array libraries
read external archives without changes.
Tests cover both Julia- and h5py-written archives across the scalar,
std::vector, std::array, and array_interface paths, plus the Python
HDFArchive entry point. Reference archives and their generators are
checked in.
Closes #13.
Assisted-by: Claude <noreply@anthropic.com>
The flag describes a buffer-layout convention (TRIQS encodes complex data as a FLOAT array with a trailing dim of size 2), not "the data is complex valued". A view with ty=dcplx_t holds complex data with the flag set to false. The old name conflated the layout with the C++ type trait is_complex_v<T>, which is genuinely about std::complex<...>. Renames the field on array_view and the matching ctor parameters on array_view and hyperslab; updates docs and the lone local in make_av_from_npy. No behavior change. Assisted-by: Claude <noreply@anthropic.com>
The version is already at 2.0.0 on unstable and the changelog moved to doc/ChangeLog.md, so this only adds the two new v2.0.0 items: reading complex datasets written by Julia HDF5.jl and h5py (#13) and the array_view::is_complex -> has_cplx_trailing_dim breaking rename. Assisted-by: Claude <noreply@anthropic.com>
e3330a1 to
989d116
Compare
989d116 to
83f55cd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extends complex-read support to archives produced by Julia HDF5.jl and h5py, which store complex values as the standard
{r:double, i:double}HDF5 compound type rather than TRIQS's trailing-2-dim FLOAT +__complex__attribute convention.The scalar and
std::arrayread paths already handled compound complex; this PR extends it to:python/h5/h5py_io.cpp—h5_read_bareallocates the destination asNPY_CDOUBLEwhen the file dataset is the{r,i}compound;array_interface::readthen retypes the view todcplx_tfor a direct read.c++/h5/stl/vector.hpp—std::vector<std::complex<double>>reinterprets a rank-1 compound dataset asstd::vector<dcplx_t>, mirroringstd::array.c++/h5/array_interface.cpp—array_interface::readtransparently swaps a FLOAT-with-trailing-2-dim view to adcplx_tview when the file dataset is the{r,i}compound, so generic array libraries (e.g. nda) read external archives without changes.Closes #13.
Also includes a follow-up rename:
array_view::is_complex→array_view::has_cplx_trailing_dim. The flag describes the trailing-2 buffer-layout convention, not "the data is complex valued" — a view withty=dcplx_tholds complex data with the flag set to false. The old name conflated the layout with the C++ type traitis_complex_v<T>.Test plan
test/c++/h5_complex_external.cppcovers scalar,std::vector,std::array, and the genericarray_interfaceread paths against both Julia- and h5py-written reference archives.test/python/external_complex.pycovers theHDFArchivePython entry point.julia_complex.ref.h5andh5py_complex.ref.h5plus their generators (gen_julia_complex.jl,gen_h5py_complex.py,gen_external_complex_refs.sh) are checked in.ctestsuite (20/20) passes.🤖 Generated with Claude Code