MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg119074] Re: Get["file.mx"] doesn't work
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Sat, 21 May 2011 06:47:12 -0400 (EDT)
  • References: <iqtnbm$io4$1@smc.vnet.net> <ir09p4$20l$1@smc.vnet.net> <ir2vr9$h50$1@smc.vnet.net> <ir5hov$9n$1@smc.vnet.net>

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


  • Prev by Date: Re: unable to import csv-Data
  • Next by Date: Re: unable to import csv-Data
  • Previous by thread: Re: Get["file.mx"] doesn't work
  • Next by thread: Plot image changes size during animation