Store num_complex datatypes
Hi,
I am wondering what the best way is to store a Complex<f32> in a hdf5 dataset.
Since the type is defined in the num_complex crate, I cannot easily derive H5Type. Do I need to define a wrapper type? Or, can this be added to hdf5-rust maybe as a Cargo feature?
What other options do I have?
The best way depends a lot on your application. Some prefer having the fields in different datasets, others do this through a packed struct. Since Complex is c-compatible with _Complex it would be a good idea to add this to this crate as an optional dependency. Would you like to make a PR?
Since I want to store a ArrayDyn<Complex
I used this workaround which also requires an additional copy to make real/imag contiguous:
fn store_cplx(&self, grp: &Group, data: ArrayViewD<Complex32>) -> Result<()> {
let complex = data.split_complex();
grp.new_dataset_builder().with_data(complex.re.as_standard_layout().view()).create("re")?;
grp.new_dataset_builder().with_data(complex.im.as_standard_layout().view()).create("im")?;
Ok(())
Would you like to make a PR?
Sure, will try.