[Date Index]
[Thread Index]
[Author Index]
RE: Re: Unexpected behaviour of HoldRest
*To*: mathgroup at smc.vnet.net
*Subject*: [mg45844] RE: [mg45821] Re: Unexpected behaviour of HoldRest
*From*: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
*Date*: Tue, 27 Jan 2004 04:50:36 -0500 (EST)
*Sender*: owner-wri-mathgroup at wolfram.com
John,
well, your comparisons are not fair, e.g. the Hold-case goes like this
In[2]:= Quit[]
In[1]:=
Timing[SeedRandom[123456];
ranpick3 =
ReleaseHold[If[# > 0.01, Hold[], #] & /@ Table[Random[], {1000000}]];
MaxMemoryUsed[]]
Out[1]= {25.377 Second, 57292888}
and you see two things (1) it's clearly faster, (2) it consumes more memory
(as the Table is built first completely)
Now to me it's now totally unclear what you are after for. Perhaps you
should try to solve your problem along the lines:
In[2]:= Quit[]
In[1]:=
Timing[SeedRandom[123456];
Table[x = Random[Real, {0, .01}], {10000}];
MaxMemoryUsed[]]
Out[1]= {0.14 Second, 1475072}
Of course this is a joke, and also not one!
What is your problem: execution time or memory? The strategies to overcome
each are quite different. You must set your goal!
--
Hartmut Wolf
>-----Original Message-----
>From: John Tanner [mailto:john at janacek.demon.co.uk]
To: mathgroup at smc.vnet.net
>Sent: Monday, January 26, 2004 7:53 AM
>To: mathgroup at smc.vnet.net
>Subject: [mg45844] [mg45821] Re: Unexpected behaviour of HoldRest
>
>
>Thank you, Andrzej and Hartmut, you confirm my suspicions that Sequence
>is tricky and dangerous to use. I do however still have problems that
>are not resolved by the alternatives as I understand them at present.
>
>I rather regret now focusing on HoldRest as the issue here. There is a
>rather more general problem with selection from lists. The
>optimum list
>selection strategy has been addressed most extensively in a thread on
>DeleteCases (started March 2001) and the basic options were well aired
>then, with the main options being:
>
> Select
> DeleteCases (or Cases)
> Position
>
>The primary discrimination between these was in terms of the
>Timing, and
>here Select still seems to be marginally preferable to
>DeleteCases/Cases
>and distinctly faster than Position. My present problem is
>however with
>the internal memory allocation, such as reported by
>MaxMemoryUsed[], and
>in this case I thought Sequence would help.
>
>The problem comes when there is a large amount of data to be processed,
>with only selected parts returned. The specific case I have found is
>when selecting immediately on calculation, so using a similar
>example to
>that used previously for DeleteCases:
>
>CASE 1 - Sequence[]
>
>In[1]:=
>Unprotect[If];
>SetAttributes[If,SequenceHold];
>Protect[If];
>Timing[SeedRandom[123456];
> ranpick1=Table[x=Random[];If[x>0.01,Sequence[],x],{1000000}];
> MaxMemoryUsed[]]
>
>Out[4]=
>{31.876 Second,6343872}
>
>CASE 2 - Hold[]
>
>In[1]:=
>Timing[SeedRandom[123456];
>
>ranpick2=Table[x=Random[];ReleaseHold[If[x>0.01,Hold[],x]],{1000000}];
> MaxMemoryUsed[]]
>
>Out[1]=
>{47.288 Second,35045032}
>
>CASE 3 - Select
>
>In[1]:=
>Timing[SeedRandom[123456];
> ranpick3=Select[Table[Random[],{1000000}],#<=0.01&];
> MaxMemoryUsed[]]
>
>Out[1]=
>{18.486 Second,35112256}
>
>CASE 4 - Cases
>
>In[1]:=
>Timing[SeedRandom[123456];
> ranpick4=Cases[Table[Random[],{1000000}],_?(#<=0.01&)];
> MaxMemoryUsed[]]
>
>Out[1]=
>{24.465 Second,35115264}
>
>All of the above of course return identical results, and as UnPacked
>arrays. Timing results are for a 266MHz Pentium II running Windows NT.
>
>advantages over Hold[]. For raw Timing, Select and Cases are quicker
>than both, but also have very high MaxMemoryUsed[] results.
>
>However the use of Sequence[] here does require that If is given the
>Attribute SequenceHold so, given the limited application of the
>technique and the risks involved, I have now regretfully abandoned this
>approach and I am also reviewing the use of Sequence elsewhere.
>Actually (to be honest) I was hoping for equivalent improvements in
>MaxMemoryUsed[] when operating on big PackedArrays of stored data, but
>here the results are far worse when using Sequence[] than when using
>Select:
>
>In[1]:=
>Unprotect[If];
>SetAttributes[If,SequenceHold];
>Protect[If];
>Timing[SeedRandom[123456];
> randata=Table[Random[],{1000000}];
> ranpick1a=If[#>0.01,Sequence[],#]& /@ randata;
> MaxMemoryUsed[]]
>
>Out[4]=
>{26.868 Second,63143384}
>
>Basically I do need a new computer with LOTS more memory...
>
>John Tanner.
>
[rest snipped off]
Prev by Date:
**RE: Help browser**
Next by Date:
**Re: Re: Unexpected behaviour of HoldRest**
Previous by thread:
**Re: RE: Unexpected behaviour of HoldRest**
Next by thread:
**ctrl-I for italics?**
| |