Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #2444 > unrolled thread

Re: Get["file.mx"] doesn't work

Started by"Sjoerd C. de Vries" <sjoerd.c.devries@gmail.com>
First post2011-05-17 11:49 +0000
Last post2011-05-20 10:38 +0000
Articles 6 — 5 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Re: Get["file.mx"] doesn't work "Sjoerd C. de Vries" <sjoerd.c.devries@gmail.com> - 2011-05-17 11:49 +0000
    Re: Get["file.mx"] doesn't work David Bailey <dave@removedbailey.co.uk> - 2011-05-18 11:15 +0000
      Re: Get["file.mx"] doesn't work Albert Retey <awnl@gmx-topmail.de> - 2011-05-19 11:44 +0000
        Re: Get["file.mx"] doesn't work Peter Pein <petsie@dordos.net> - 2011-05-20 11:02 +0000
          Re: Get["file.mx"] doesn't work Albert Retey <awnl@gmx-topmail.de> - 2011-05-21 10:47 +0000
      Re: Get["file.mx"] doesn't work Ulf-Dietrich Braumann <braumann@uni-leipzig.de> - 2011-05-20 10:38 +0000

#2444 — Re: Get["file.mx"] doesn't work

From"Sjoerd C. de Vries" <sjoerd.c.devries@gmail.com>
Date2011-05-17 11:49 +0000
SubjectRe: Get["file.mx"] doesn't work
Message-ID<iqtnbm$io4$1@smc.vnet.net>
If you saved the file using DumpSave the result may be machine specific (MaxOS vs Win vs Linux; 32 bit vs 64 bit). Other kinds of saving results (a normal save in a .nb notebook or using Save are machine independent if I'm not mistaken).

Cheers -- Sjoerd

Mathematica questions quickly answered at StackOverflow
http://stackoverflow.com/questions/tagged/mathematica

[toc] | [next] | [standalone]


#2468

FromDavid Bailey <dave@removedbailey.co.uk>
Date2011-05-18 11:15 +0000
Message-ID<ir09p4$20l$1@smc.vnet.net>
In reply to#2444
On 17/05/2011 12:49, Sjoerd C. de Vries wrote:
> If you saved the file using DumpSave the result may be machine specific (MaxOS vs Win vs Linux; 32 bit vs 64 bit). Other kinds of saving results (a normal save in a .nb notebook or using Save are machine independent if I'm not mistaken).
>
> Cheers -- Sjoerd
>
> Mathematica questions quickly answered at StackOverflow
> http://stackoverflow.com/questions/tagged/mathematica
>
>
There is an interesting alternative to using MX files, which seems to be 
portable:

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
http://www.dbaileyconsultancy.co.uk

[toc] | [prev] | [next] | [standalone]


#2485

FromAlbert Retey <awnl@gmx-topmail.de>
Date2011-05-19 11:44 +0000
Message-ID<ir2vr9$h50$1@smc.vnet.net>
In reply to#2468
Hi,

> There is an interesting alternative to using MX files, which seems to
> be portable:
>
> str=OpenWrite[file,BinaryFormat->True];
> BinaryWrite[str,Compress[expr],"TerminatedString"]; Close[str];
>

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).

On the other hand that format seems to not be promoted by Wolfram very 
much. Has anyone any information what the "official" state of that 
format is, and whether WRI thinks it is save and recommended to be used 
by ordinary users or not?

Honestly I could well imagine that WDX basically does something very 
close to what David suggested :-). If anyone has time to do some 
performance comparison between the two, I would be interested to hear 
the results...

cheers,

albert


[toc] | [prev] | [next] | [standalone]


#2540

FromPeter Pein <petsie@dordos.net>
Date2011-05-20 11:02 +0000
Message-ID<ir5hov$9n$1@smc.vnet.net>
In reply to#2485
Am 19.05.2011 13:44, schrieb Albert Retey:
> Hi,
> 
>> There is an interesting alternative to using MX files, which seems to
>> be portable:
>>
>> str=OpenWrite[file,BinaryFormat->True];
>> BinaryWrite[str,Compress[expr],"TerminatedString"]; Close[str];
>>
> 
> 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).
> 
> On the other hand that format seems to not be promoted by Wolfram very 
> much. Has anyone any information what the "official" state of that 
> format is, and whether WRI thinks it is save and recommended to be used 
> by ordinary users or not?
> 
> Honestly I could well imagine that WDX basically does something very 
> close to what David suggested :-). If anyone has time to do some 
> performance comparison between the two, I would be interested to hear 
> the results...
> 
> cheers,
> 
> albert
> 
> 
> 

soory to say, Albert, but Ex- and Import is not an easy to handle
alternative to DumpSave:

In[1]:= f[x_]:=x+1
In[2]:= SetDirectory["C:\\Users\\Peter"];
In[3]:= DumpSave["f.mx",f];
In[4]:= Remove[f];
In[5]:= <<"f.mx"
In[6]:= f[a]
Out[6]= 1+a

this should work with an alternative. But:

In[7]:= Export["f.wdx",f];
In[8]:= Remove@f
In[9]:= Import["f.wdx"]
Out[9]= f
In[10]:= f[b]
Out[10]= f[b]

and of course the following leads to a real mess:

In[11]:= f:=Import["f.wdx"]
In[12]:= f[c]
During evaluation of In[12]:= $RecursionLimit::reclim: Recursion depth
of 256 exceeded. >>
During evaluation of In[12]:= $RecursionLimit::reclim: Recursion depth
of 256 exceeded. >>
During evaluation of In[12]:= $RecursionLimit::reclim: Recursion depth
of 256 exceeded. >>
During evaluation of In[12]:= General::stop: Further output of
$RecursionLimit::reclim will be suppressed during this calculation. >>
Out[12]= $Aborted

One would have to find a way to save all (d)ownvalues, upvalues (and
possibly "inbetweenvalues" ;-) ) and to restore them. Not too trivial,
is it?

Cheers,
Peter

[toc] | [prev] | [next] | [standalone]


#2558

FromAlbert Retey <awnl@gmx-topmail.de>
Date2011-05-21 10:47 +0000
Message-ID<ir8574$bdu$1@smc.vnet.net>
In reply to#2540
Hi,
>
> soory to say, Albert, but Ex- and Import is not an easy to handle
> alternative to DumpSave:
>
> In[1]:= f[x_]:=x+1
> In[2]:= SetDirectory["C:\\Users\\Peter"];
> In[3]:= DumpSave["f.mx",f];
> In[4]:= Remove[f];
> In[5]:=<<"f.mx"
> In[6]:= f[a]
> Out[6]= 1+a
>
> this should work with an alternative. But:
>
> In[7]:= Export["f.wdx",f];
> In[8]:= Remove@f
> In[9]:= Import["f.wdx"]
> Out[9]= f
> In[10]:= f[b]
> Out[10]= f[b]
>
> and of course the following leads to a real mess:
>
> In[11]:= f:=Import["f.wdx"]
> In[12]:= f[c]
> During evaluation of In[12]:= $RecursionLimit::reclim: Recursion depth
> of 256 exceeded.>>
> During evaluation of In[12]:= $RecursionLimit::reclim: Recursion depth
> of 256 exceeded.>>
> During evaluation of In[12]:= $RecursionLimit::reclim: Recursion depth
> of 256 exceeded.>>
> During evaluation of In[12]:= General::stop: Further output of
> $RecursionLimit::reclim will be suppressed during this calculation.>>
> Out[12]= $Aborted

What you say is of course all true, I meant that wdx is capable of doing 
what an Import[filename,data,"MX"] can do, which means it can handle 
arbitrary mathematica expressions, it does not require data to be of a 
certain type, as most other binary export formats do. I should emphasize 
that Davids suggestion to write a Compressed binary representation of an 
expression does fulfill this requirement just as well, which is thanks 
to the power of Compress to handle expressions of any kind. I was lead 
to the assumption that that was what the OP wanted since he was talking 
about MX format, not DumpSave. Sorry if that was not clear from my 
previous post.

> One would have to find a way to save all (d)ownvalues, upvalues (and
> possibly "inbetweenvalues" ;-) ) and to restore them. Not too trivial,
> is it?

What you can do is to use Save, which works like DumpSave in that 
respect, it looks up all definitions that the expression you want to 
save potentially depend on. The drawback is of course that it is not a 
binary format, so it will much more space and time consuming to save and 
reload the definitions, but it will be portable.

Obviously there is no holy grail in that respect, namely a DumpSave to a 
portable format.

On the other hand my impression is that it should be relatively simple 
to create something that works as DumpSave but stores to WDX instead of 
MX for WRI, maybe someone listens and realizes that there might be a 
need for it. Or maybe the functionality is there but we have not found 
how to use it. If you'd want to program this yourself, you would have to 
rewrite some nontrivial code that already exists (not a motivating 
situation :-)) or get ahold of these internal functionalities in one way 
or the other. That is not something I would try without very urgent need...

I think that this does not come up more frequently is that most serious 
users of Mathematica have learned how to depart definitions (=code) from 
data, where former can best be stored to .m files (and be version 
controlled!) and the latter could e.g. be saved in .wdx files in a 
portable way or more often saved to more specific other file formats. Of 
course I know that the nature of Mathematica makes no clear distinctions 
between the two, but I rarely have seen real world examples where these 
concepts could not easily be distinguished. If in doubt I guess you can 
get away with: if it's large ("megabytes"), its data, if not it's ok to 
be treated "like" code and can go to a .m (text)file...

cheers,

albert

[toc] | [prev] | [next] | [standalone]


#2516

FromUlf-Dietrich Braumann <braumann@uni-leipzig.de>
Date2011-05-20 10:38 +0000
Message-ID<ir5gbt$t48$1@smc.vnet.net>
In reply to#2468
Hi,

if no expressions need to be stored, just datasets, you also might 
consider exporting to NASACDF (common data format specified by NASA). It 
of course is portable, is binary, and one can specify some lossless 
compression methods. Recently I have used it for storing some scalar 32bit 
real valued autoradiographic images (approx. 9000x7000 pixels, approx. 
150MB on disk):

Export["psl.cdf", {psl}, {"Datasets", {"Photo Stimulated Luminescence"}}, 
{"DataFormat" -> "Real32", "DataEncoding" -> "GZIP"}];

(NB: TIFF export/import in Mathematica still cannot deal with real-valued 
images, whereas my images' value range was somewhat exotic: 0,...,2.5).

One can check what named data sets are included simply typing:
Import["psl.cdf"]
and gets:
{"Photo Stimulated Luminescence"}

Loading is done like this:
psl=Import["psl.cdf", {"Datasets", {"Photo Stimulated Luminescence"}}];

To store more data sets in one file, simply extend the list of variables 
and data set names...

At the moment unfortunately I cannot do performance comparisons (WDX, 
BinaryWrite, MX, NASACDF, ...).

Regards - Ulf-Dietrich

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web