MathGroup Archive 2005

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

Search the Archive

Re: For Loop and Array related

  • To: mathgroup at
  • Subject: [mg58226] Re: For Loop and Array related
  • From: Maxim <ab_def at>
  • Date: Thu, 23 Jun 2005 05:34:12 -0400 (EDT)
  • References: <d8oucl$t6q$> <d8rjjj$irp$>
  • Sender: owner-wri-mathgroup at

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

> 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  

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:

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

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:

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

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

Maxim Rytin
m.r at

  • 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?