I’m trying to read large datasets from HDF5 files into StaticArray
s but I’m really struggling to understand how to get the data into a StaticArray
.
I’m using the following function to read the HDF5 file and it works fine, returning the expected data:
function get_property(filepath::String, property::String)
timestep_key = filename_base(filepath)
fid = h5open(filepath, "r")
timestep_key = keys(fid["TimestepData"])[1]
query = read(fid["TimestepData"][timestep_key][property])
# for testing purposes query is a (3, 44843) Matrix of Float64
close(fid)
# Some code here that converts data to StaticArray?
return query
end
Typically I always know one dimension (I’m getting force data so there would always be 3 components, so (3,n) size) so I thought it should be straightforward to convert to a StaticArray to take advantage of the faster computation speeds.
But I’m not able to do that conversion of the data before returning from the function.
I’ve tried:
SVector{3,Float64}query
> Internal Error: MethodError: no method matching *(::Type{StaticArrays.SVector{3, Float64}}, ::Matrix{Float64})
SVector{3,Float64}(query)
> Internal Error: DimensionMismatch("expected input array of length 3, got length 134529")
SA_F64[query]
>Internal Error: MethodError: Cannot `convert` an object of type Matrix{Float64} to an object of type Float64
Closest candidates are:
convert(::Type{T}, !Matched::Static.StaticFloat64{N}) where {N, T<:AbstractFloat} at C:\Users\jpmor\.julia\packages\Static\pkxBE\src\float.jl:26
convert(::Type{T}, !Matched::Base.TwicePrecision) where T<:Number at C:\Users\jpmor\.julia\juliaup\julia-1.7.1+0~x64\share\julia\base\twiceprecision.jl:262
convert(::Type{T}, !Matched::AbstractChar) where T<:Number at C:\Users\jpmor\.julia\juliaup\julia-1.7.1+0~x64\share\julia\base\char.jl:185
SMatrix{3,44843}(query) # This is still running after almost 1hr....
Can someone point out to me how to achieve this - I am assuming it is possible and simple, but the StaticArrays
documentation is very basic and doesn’t seem to cover this.
If it’s a slow and computationally intensive task, then I will probably stick to a standard matrix, but I can’t get this to work at all.