I have an HDF5 file. I want to read or allocate its data in variable r
repeatedly instead of allocating in different places in memory.
using HDF5
fname = tempname(); # temporary file
fid = h5open(fname, "w")
create_group(fid, "mygroup")
fid["mydataset"] = rand(Float32, 18, 872)
r = zeros(Float32,18)
for i in 1:872
read!((fid["mydataset"][:,1]), r)
end
i get following error.
ERROR: MethodError: no method matching read!(::Vector{Float32}, ::Vector{Float32})
The functionread!
exists, but no method is defined for this combination of argument types.
Closest candidates are:
read!(::IO, ::StridedArray{T}) where T
@ Base io.jl:930
read!(::IO, ::AbstractArray{T}) where T
@ Base io.jl:911
read!(::AbstractString, ::Any)
@ Base io.jl:517
How to make it read on the same place in memory to reduce allocations?