JuliaIO / JLD.jl

Saving and loading julia variables while preserving native types
MIT License
277 stars 55 forks source link

Loading `Base.SparseArrays.SparseMatrixCSC` (Julia 0.6.4) in Julia 1.0 #234

Open carstenbauer opened 6 years ago

carstenbauer commented 6 years ago

In Julia 0.6.4

julia> using JLD

julia> save("myfile.jld", "x", sprand(10,10,0.01));

Afterwards in Julia 1.0

julia> using JLD

julia> x = load("myfile.jld", "x")
┌ Warning: type Base.SparseArrays.SparseMatrixCSC{Core.Float64,Core.Int64} not present in workspace; reconstructing
└ @ JLD C:\Users\carsten\.julia\packages\JLD\5N2lz\src\jld_types.jl:707
getfield(JLD, Symbol("##Base.SparseArrays.SparseMatrixCSC{Core.Float64,Core.Int64}#360"))(10, 10, [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [1], [0.189298])

The SparseMatrixCSC struct hasn't changed in 1.0. However it has been moved from Base.SparseArrays to the SparseArrays stdlib.

How do I load sparse matrices stored with Julia 0.6.4 in Julia 1.0?

kalmarek commented 5 years ago

any news/solutions to this puzzle? I do on julia-1.0

julia> using SparseArrays # brings SparseMatrixCSC to workspace

julia> using JLD

julia> x = load("myfile.jld", "x")
┌ Warning: type Base.SparseArrays.SparseMatrixCSC{Core.Float64,Core.Int64} not present in workspace; reconstructing
└ @ JLD ~/.julia/packages/JLD/1BoSz/src/jld_types.jl:703
getfield(JLD, Symbol("##Base.SparseArrays.SparseMatrixCSC{Core.Float64,Core.Int64}#361"))(10, 10, [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], Int64[], Float64[])
kalmarek commented 5 years ago

@JeffBezanson if I read correctly you're the maintainer of JLD.jl; Is this issue a quick-fix or requires something more?

(sorry to bother if it has been brought to your attention, but You just lack the time to investigate. This actually looks like an issue/testcase for JLDArchives, but it seems even less maintained...

kalmarek commented 5 years ago

just for the record: the fields of loaded sparse matrix/vector are available (and understandable by julia-1.0) so if you need a workaround:

               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: https://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.6.4 (2018-07-09 19:09 UTC)
 _/ |\__'_|_|_|\__'_|  |  Official http://julialang.org/ release
|__/                   |  x86_64-pc-linux-gnu

julia> using JLD

julia> x = sprand(100, 0.1)
100-element SparseVector{Float64,Int64} with 10 stored entries:
  [14 ]  =  0.217239
  [44 ]  =  0.202958
  [48 ]  =  0.0830395
  [53 ]  =  0.796969
  [55 ]  =  0.598821
  [62 ]  =  0.784618
  [72 ]  =  0.939342
  [78 ]  =  0.895276
  [95 ]  =  0.787481
  [96 ]  =  0.432606

julia> save("/tmp/x.jld", "x", x)
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.1.1 (2019-05-16)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using SparseArrays

julia> using JLD

julia> w = load("/tmp/x.jld", "x");
┌ Warning: type Base.SparseArrays.SparseVector{Core.Float64,Core.Int64} not present in workspace; reconstructing
└ @ JLD ~/.julia/packages/JLD/1BoSz/src/jld_types.jl:703

julia> x = SparseVector(w.n, w.nzind, w.nzval)
100-element SparseVector{Float64,Int64} with 10 stored entries:
  [14 ]  =  0.217239
  [44 ]  =  0.202958
  [48 ]  =  0.0830395
  [53 ]  =  0.796969
  [55 ]  =  0.598821
  [62 ]  =  0.784618
  [72 ]  =  0.939342
  [78 ]  =  0.895276
  [95 ]  =  0.787481
  [96 ]  =  0.432606