Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ResStump opened this issue Mar 6, 2025 · 1 comment

Comments

@ResStump
Copy link

ResStump commented Mar 6, 2025

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.

@mkitti
Copy link
Member

mkitti commented Mar 7, 2025

Yes, there are probably too many methods that take AbstractArray arguments which probably should check assumptions.

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

No branches or pull requests

2 participants