Skip to content

Writing non-contiguous views of multidimensional arrays produces incorrect data #1190

@ResStump

Description

@ResStump

Description:
When writing a view of a three-dimensional (or higher) array to an HDF5 file, if the view is non-contiguous, the data is not written correctly. Reading the data back results in an incorrect array.

Minimal Working Example:

using HDF5

arr1 = reshape(collect(1:8), 2, 2, 2)

h5open("test.h5", "w") do file
    file["arr"] = @view arr1[:, 1, :]
end

arr2 = h5read("test.h5", "arr")

println(arr2 == arr1[:, 1, :]) # false
println(arr2 == arr1[:, :, 1]) # true

Expected Behavior:
The data written to "test.h5" should match arr1[:, 1, :]. Or if views with non-contiguous arrays are not supported an error should be raised.

Actual Behavior:
Instead of writing the 4 numbers in the view, the first 4 numbers of arr1 are written.

Additional Context:
This issue seems to occur only when writing non-contiguous views of multidimensional arrays to an HDF5 file. Writing contiguous slices (e.g., arr1[:, :, 1]) works correctly.
If the first index is fixed (e.g. arr1[1, :, :]) then an error is raised (as expected).

System Information:
HDF5.jl version: 0.17.2
Julia version: 1.11.3
OS: Ubuntu 22.04.5 LTS (x86_64)

I'm looking forward to your thoughts on this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions