LiorBanai / HDF5-CSharp

C# wrapper for windows/Linux systems for reading and writing H5 files
MIT License
54 stars 27 forks source link

Support System.Numerics.Complex #237

Open brechtvb opened 2 years ago

brechtvb commented 2 years ago

Is it possible to support System.Numerics.Complex

Today that has to be done through a [float float] compound, correct?

LiorBanai commented 2 years ago

@brechtvb , Yeah I don't think H5 data type has native complex type. It will have to be split into 2 fields.

LiorBanai commented 2 years ago

https://mathematica.stackexchange.com/questions/63983/hdf5-and-complex-numbers

brechtvb commented 2 years ago

Indeed, there is no other way.

An ugly hack could be provided through issue #236:

unsafe public void Write(Guid guid, ReadOnlySpan<double> valuePath, ReadOnlySpan<Complex> cdata, string groupName)
    {
        var groupId = h5.Hdf5.CreateGroupRecursively(hfile, loc(guid, valuePath));

        fixed (Complex* cptr = cdata)
        {
            double* dptr = (double*)cptr;

            var ddata = new ReadOnlySpan<double>(dptr, cdata.Length * 2);

            var ds = h5.Hdf5.WriteDatasetFromArray<double>(groupId, groupName, ddata.ToArray());
        }

    }