MathGroup Archive 2005

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

Search the Archive

Re: For Loop and Array related


On Thu, 16 Jun 2005 10:17:23 +0000 (UTC), Maxim <ab_def at prontomail.com>  
wrote:

>
> Lattice = Last@ Reap[
>    Sow[0, Range@ 100];
>    Sow[0, Table[Random[Integer, {1, 100}], {16000}]],
>    _, Length@ #2 - 1&];
>

For this particular task we don't have to create a large list in one go,  
but generally Sow and Reap seem to be too memory-consuming to be really  
useful:

Reap[Sow[0, Range[10^6]], _, 0&]

This will make the Mathematica kernel crash (I believe this happens when  
the memory usage exceeds 2Gb). Another problem is that MemoryConstrained  
doesn't have any effect on Sow/Reap:

MemoryConstrained[
   Reap[Sow[0, Range[10^6]], _, 0&],
   10^8]

will still try to allocate more than 2Gb of memory.

Generating an associative array with assignments f[key] = {f[key], value}  
or some similar way to emulate Sow works for a larger number of keys:

Module[{f},
   f[_] = {};
   (f[#] = {f[#], 0})& /@ Range[nkey];
]

This will crash when nkey is around 2*10^7.

Maxim Rytin
m.r at inbox.ru


  • Prev by Date: Simplify and Memory
  • Next by Date: Re: Mathematica program generating sequence of points stalls for no apparent reason.
  • Previous by thread: Re: For Loop and Array related
  • Next by thread: How to rotate a PolarPlot?