JuliaArrays / StaticArrays.jl

Statically sized arrays for Julia
Other
761 stars 147 forks source link

Load error of parametric type using StaticArrays from .jld file #877

Open BoZenKhaa opened 3 years ago

BoZenKhaa commented 3 years ago

Hello, I am having issues loading saved custom parametric type using JLD in Julia 1.5.

The following example:

using JLD
using StaticArrays

struct MyType{N}
    a::SVector{N, Int64}
end

MyType{2}(SA[1,2])

JLD.save("test.jld", "s", MyType{2}(SA[1,2]))
load("test.jld")

produces this error:

ERROR: stored type MyType{2} does not match currently loaded type

I get the same error if the parameter is the type and not the size.

Everything works fine when using the StaticArray directly:

julia> JLD.save("test.jld", "s", SVector{2, Int64}(1,2))

julia> load("test.jld")
Dict{String,Any} with 1 entry:
  "s" => [1, 2]

Similarly, using custom nested parametric types works fine as well:

struct MyType3{T}
    a::T
end

struct MyType4{T}
    b::MyType3{T}
end

MyType4{Int64}(MyType3{Int64}(1))

JLD.save("test.jld", "s", MyType4{Int64}(MyType3{Int64}(1)))

julia> load("test.jld")
Dict{String,Any} with 1 entry:
  "s" => MyType4{Int64}(MyType3{Int64}(1))

What could be causing this? I get this error only with my own parametric types using StaticArrays. I have posted this also in JLD: https://github.com/JuliaIO/JLD.jl/issues/294

andyferris commented 3 years ago

I suspect this is probably a JLD issue.

BoZenKhaa commented 3 years ago

Probabably, but since the issue does not come up with generic parametric types, couldn't there be something special about the SVectors that's triggering the error in JLD?