-
Notifications
You must be signed in to change notification settings - Fork 82
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
Upgrading old structures with parametric composite types #474
Comments
Hi @dcerkoney, this should be possible with (note, that I removed the type parameter from the OldStruct)
However, because of a bug, this still doesn't work. I think I fixed it in #475 |
Great, thanks for the swift response! |
One problem comes to mind with the proposed solution: doesn't it mean that an archive holding different specializations of For example, suppose we have a situation like this: using JLD2
struct OldStruct{T}
x::T
end
struct NewStruct{T}
x::T
b::Bool
end
function JLD2.rconvert(::Type{NewStruct{T}}, nt::NamedTuple) where {T}
return NewStruct{T}(nt.x, true)
end
jldsave(
"test.jld2";
a=OldStruct{Int}(1),
b=OldStruct{Vector{Int}}([1, 0]),
c=OldStruct{Matrix{Int}}([1 0; 0 1])
) Since I have defined # Option 1: Try to upgrade every OldStruct{T} to NewStruct{T} where {T}
d1 = load(
"test.jld2";
typemap=Dict("Main.OldStruct" => JLD2.Upgrade(NewStruct))
)
# Option 2: Upgrade OldStruct{T} to NewStruct{T} for explicitly specified values of T
d2 = load(
"test.jld2";
typemap=Dict(
"Main.OldStruct{Vector{Int}}" => JLD2.Upgrade(NewStruct{Vector{Int}}),
"Main.OldStruct{Matrix{Int}}" => JLD2.Upgrade(NewStruct{Matrix{Int}}),
)
) Any thoughts? |
Would it work to define a single upgrade statement that does |
Sure, that approach makes sense to me. |
Hello,
I am encountering a small issue related to upgrading old structures on load using JLD2 v0.4.32 which I am struggling to debug.
Are parametric composite types supported for
JLD2.rconvert
andJLD2.Upgrade
?If so, how should the type mapping be specified?
Here is a small example illustrating the behavior I am expecting, which does not work as intended:
If there is a way to achieve something like this, it would be great if we could add an example to the docs.
Thanks,
Daniel
The text was updated successfully, but these errors were encountered: