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

Broadcasted and indexed writes into a dataset fail silently #1185

Open
jaredjeya opened this issue Jan 7, 2025 · 1 comment
Open

Broadcasted and indexed writes into a dataset fail silently #1185

jaredjeya opened this issue Jan 7, 2025 · 1 comment

Comments

@jaredjeya
Copy link

Writing into an indexed dataset using the broadcasted assignment operator, .=, fails silently.

MWE:

using HDF5

A = zeros(5, 5)
h5write("data/test.h5", "A", A)

h5open("data/test.h5", "cw") do file
    file["A"][1, :] .= 1  # Issue occurs here
end

@show h5read("data/test.h5", "A");

The resultant file will still be all zeros.

I believe this is because the combination of indexing and broadcasting creates a copy of the dataset that is written to and then discarded; replacing the .= with a = fixes this, but this is unintuitive given that in Julia, doing so with an normal array on the LHS and scalar on the RHS would raise an error, ERROR: ArgumentError: indexed assignment with a single value to possibly many locations is not supported; perhaps use broadcasting '.=' instead?. (As a result it's basically muscle memory that I use .= whenever I do operations involving assigning to arrays).

When the LHS is not indexed into, i.e. file["A"] .= 1, broadcasting raises an error, although this error is extremely uninformative (ERROR: MethodError: no method matching ndims(::Type{HDF5.Dataset}) The function 'ndims' exists, but no method is defined for this combination of argument types.)

I don't think it's a problem if this use of the broadcasting operator is unsupported, but it should raise an error rather than just fail to write silently.

@mkitti
Copy link
Member

mkitti commented Jan 7, 2025

I concur this is an inconsistency that should be resolved.

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