Re: For Loop and Array related
- To: mathgroup at smc.vnet.net
- Subject: [mg58226] Re: For Loop and Array related
- From: Maxim <ab_def at prontomail.com>
- Date: Thu, 23 Jun 2005 05:34:12 -0400 (EDT)
- References: <d8oucl$t6q$1@smc.vnet.net> <d8rjjj$irp$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
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