HDF5.jl icon indicating copy to clipboard operation
HDF5.jl copied to clipboard

c-indexing and dimension ordering in `attach_scale` function

Open Chiil opened this issue 3 years ago • 2 comments

I have implemented a simple example adding dimensions to an HDF5 file with the code below. I noticed that I need to swap the dimensions to c-ordering and use c-indexing to attach the scales correctly. Is this intentional?

using HDF5

filename = "test.h5"

x = 0.:10:100 |> collect
y = 0.:2:10 |> collect
z = [ i^2 + j for i in x, j in y ]

h5open(filename, "w") do fid
    fid["x"] = x[:]
    fid["y"] = y[:]
    fid["z"] = z[:, :]
    HDF5.h5ds_set_scale(fid["x"], "x")
    HDF5.h5ds_set_scale(fid["y"], "y")
    HDF5.h5ds_attach_scale(fid["z"], fid["x"], 1)
    HDF5.h5ds_attach_scale(fid["z"], fid["y"], 0)
end

Chiil avatar Oct 17 '21 13:10 Chiil

That looks correct since Julia is column major whereas the hdf5 lib is row-major. We probably should figure out a way to make this more 'julian'/ergonomic

musm avatar Oct 17 '21 23:10 musm

Note that this example may need to use HDF5.API in v0.16.0 for h5ds_set_scale and h5ds_attach_scale.

For the transition, I usually define const HDF5API = HDF5 for before 0.16.0 and const HDF5API = HDF5.API for 0.16 and beyond.

When using the low-level C API, one should expect to use C conventions.

mkitti avatar Jan 22 '22 16:01 mkitti