Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fast-to-load cross-platform alternative to MX files (Mathematica)

In Mathematica, one can save intermediate results / the partial state of the workspace with Save (.m files) or DumpSave (.mx files).

.m files are portable, but are very slow to load (with large data).

.mx files are fast to load, but are not portable between platforms/architectures.

Is there a way to save generic Mathematica expressions in a way that loading them is fast, and they're portable between platforms? Has anyone experimented with / benchmarked different methods to do this?

One possible solution is to save .m files (cross-platform), then convert them to .mx files when starting work on a new platform (a one-time operation). Is there a fully automatic way to convert .m files to .mx files?

like image 483
Szabolcs Avatar asked May 26 '11 09:05

Szabolcs


1 Answers

  • From the posts Alexey linked:

    str=OpenWrite[file,BinaryFormat->True];
    
    BinaryWrite[str,Compress[expr],"TerminatedString"];
    
    Close[str];
    

    This is not quite as fast as using an mx file, but it is still very fast.

    David Bailey


    Another alternative seems to be WDX (Wolfram Data eXchange) which I am using without problems on a variety of machines and which also seems to be portable, can be used exactly like MX files, is binary, is documented and thus I would consider officially supported. And it is used by the data paclet functionality, so I guess it is reasonably performant and well tested on all systems (an assumption which my experience does support up to now).

    (excerpt from answer by Albert Retey, also from Alexey's link)

But these do not work as Save/DumpSave does, in that it does not save the FullDefinition of expr, only the explicit value of expr.

like image 78
Mr.Wizard Avatar answered Oct 17 '22 17:10

Mr.Wizard