-
Notifications
You must be signed in to change notification settings - Fork 143
Description
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.