This answer doesn't help you with past uses of DumpSave
to store variables, but rather it offers an alternative. One obvious way to store a variable to be retrieved later is to use Put
, as in:
m = RandomReal[1, {1000,1000}];
Put[m, "matrix.m"]; //AbsoluteTiming
stored = Get["matrix.m"]; //AbsoluteTiming
m === stored
{2.22504, Null}
{1.40961, Null}
True
As the timing shows, this method is rather slow. It also has an issue where some objects change when run through this Put
/Get
round trip. An alternative that I like is to define new functions, PutMX
and GetMX
(note that this can be made more robust by using a package):
PutMX[expr_, file_] := Block[{res=expr}, DumpSave[file, res]]
GetMX[file_] := Block[{res}, Get[file]; res]
As you can see, PutMX
and GetMX
use DumpSave
under the hood, but in such a way that they mimic Put
and Get
. As an example:
PutMX[m, "matrix.mx"]; //AbsoluteTiming
stored = GetMX["matrix.mx"]; //AbsoluteTiming
m === stored
{0.015008, Null}
{0.005111, Null}
True
There have been some earlier suggestions to use Export[file, expr, "MX"]
and Import[file]
instead, but this approach is quite a bit slower, due to overhead in the Import
/Export
framework. For instance:
Export["matrix2.mx", m, "MX"]; //AbsoluteTiming
stored = Import["matrix2.mx"]; //AbsoluteTiming
m === stored
{0.07974, Null}
{0.055974, Null}
True
As you can see, PutMX
/GetMX
are quite a bit faster.
Export
to the.mx
format. If you use this method, then only the data will be saved, but any definitions. I much prefer this way. I can simply re-Import
and assign to whatever variable name I prefer. If I want to save several pieces of data, and even give them names, then I use an association (or rule list in earlier versions). $\endgroup$Export
/Import
does seem like the way to go. Thanks! $\endgroup$