Skip to content

Read complex datasets written by Julia HDF5.jl and h5py#40

Merged
Wentzell merged 3 commits into
unstablefrom
complex-from-julia-h5py
Jun 9, 2026
Merged

Read complex datasets written by Julia HDF5.jl and h5py#40
Wentzell merged 3 commits into
unstablefrom
complex-from-julia-h5py

Conversation

@Wentzell

@Wentzell Wentzell commented May 5, 2026

Copy link
Copy Markdown
Member

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::array read paths already handled compound complex; this PR extends it to:

  • python/h5/h5py_io.cpph5_read_bare allocates the destination as NPY_CDOUBLE when the file dataset is the {r,i} compound; array_interface::read then retypes the view to dcplx_t for a direct read.
  • c++/h5/stl/vector.hppstd::vector<std::complex<double>> reinterprets a rank-1 compound dataset as std::vector<dcplx_t>, mirroring std::array.
  • c++/h5/array_interface.cpparray_interface::read transparently swaps a FLOAT-with-trailing-2-dim view to a dcplx_t view 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_complexarray_view::has_cplx_trailing_dim. The flag describes the trailing-2 buffer-layout convention, 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>.

Test plan

  • New test/c++/h5_complex_external.cpp covers scalar, std::vector, std::array, and the generic array_interface read paths against both Julia- and h5py-written reference archives.
  • New test/python/external_complex.py covers the HDFArchive Python entry point.
  • Reference archives julia_complex.ref.h5 and h5py_complex.ref.h5 plus their generators (gen_julia_complex.jl, gen_h5py_complex.py, gen_external_complex_refs.sh) are checked in.
  • Full ctest suite (20/20) passes.
  • CI green.

🤖 Generated with Claude Code

@Wentzell Wentzell requested a review from Thoemi09 May 5, 2026 21:29
@Wentzell Wentzell force-pushed the complex-from-julia-h5py branch from 8b35796 to f05415d Compare May 6, 2026 14:01
@Wentzell Wentzell force-pushed the complex-from-julia-h5py branch from f05415d to e3330a1 Compare June 8, 2026 19:44
Wentzell added 3 commits June 8, 2026 15:57
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>
@Wentzell Wentzell force-pushed the complex-from-julia-h5py branch from e3330a1 to 989d116 Compare June 8, 2026 19:58

@Thoemi09 Thoemi09 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@Wentzell Wentzell force-pushed the complex-from-julia-h5py branch from 989d116 to 83f55cd Compare June 9, 2026 14:42
@Wentzell Wentzell merged commit 3e710d5 into unstable Jun 9, 2026
4 checks passed
@Wentzell Wentzell deleted the complex-from-julia-h5py branch June 9, 2026 14:43
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.

2 participants