Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Julia - save workspace

Tags:

julia

Is there an official way to save all variables in the workspace? If not, is there a way to display all variables? Right now I use whos() but that displays all modules and functions aswell

like image 701
isebarn Avatar asked Dec 05 '16 09:12

isebarn


1 Answers

I think what you want is @save and @load pair of JLD.jl.

julia> n = 10
10

julia> x = randn(n, n)
10×10 Array{Float64,2}:
 -0.0197367  -0.176776    0.25441    1.27037    …   0.922747   -1.62709   -1.00135
 -0.926221    0.0511172   0.616038  -0.876974      -1.38141    -0.663528   0.0851561
 -1.16956     1.33495    -0.192604   0.986576       1.20383    -1.11466    0.654329
 -0.0358511  -2.18456    -0.253529   1.12241       -0.558712   -0.29862    1.52749
 -0.228209    0.21741     0.79077    0.104083      -0.109346    0.206167   1.6082
 -0.255945    0.185782    0.650366  -1.43969    …   0.367013   -1.20504   -3.03426
  0.801956   -1.03232    -0.13117    0.0241593     -0.0129462   2.2469     0.208836
 -1.09213    -0.723174    0.609008   0.175357       0.487224    0.97294    0.770932
 -1.12841     0.249794    0.134091   0.0268805     -0.832201   -1.0924    -1.08669
  0.0170944   0.945585   -0.915999   0.96237        2.03081    -0.800125  -0.584156

julia> using JLD

julia> @save "data.jld"

# restart Julia REPL

julia> using JLD

julia> @load "data.jld"
3-element Array{Symbol,1}:
 :ans
 :n
 :x

julia> n
10

julia> x
10×10 Array{Float64,2}:
 -0.0197367  -0.176776    0.25441    1.27037    …   0.922747   -1.62709   -1.00135
 -0.926221    0.0511172   0.616038  -0.876974      -1.38141    -0.663528   0.0851561
 -1.16956     1.33495    -0.192604   0.986576       1.20383    -1.11466    0.654329
 -0.0358511  -2.18456    -0.253529   1.12241       -0.558712   -0.29862    1.52749
 -0.228209    0.21741     0.79077    0.104083      -0.109346    0.206167   1.6082
 -0.255945    0.185782    0.650366  -1.43969    …   0.367013   -1.20504   -3.03426
  0.801956   -1.03232    -0.13117    0.0241593     -0.0129462   2.2469     0.208836
 -1.09213    -0.723174    0.609008   0.175357       0.487224    0.97294    0.770932
 -1.12841     0.249794    0.134091   0.0268805     -0.832201   -1.0924    -1.08669
  0.0170944   0.945585   -0.915999   0.96237        2.03081    -0.800125  -0.584156
like image 198
bicycle1885 Avatar answered Sep 21 '22 00:09

bicycle1885