MathGroup Archive 1996

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

Search the Archive

Re: Table[] Why such a hog?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg3586] Re: Table[] Why such a hog?
  • From: wagner at bullwinkle.cs.Colorado.EDU (Dave Wagner)
  • Date: Wed, 27 Mar 1996 03:26:25 -0500
  • Organization: University of Colorado, Boulder
  • Sender: owner-wri-mathgroup at wolfram.com

In article <4iqpo1$puj at dragonfly.wolfram.com>,
 <newnews at almaden.ibm.com> wrote:
>Seems like the Table[] function for building arrays takes way longer than it ought to.  I hope someone can
>tell me why:
>
>The following expression takes around twenty minutes to complete on my RS/6000 workstation:
>
>Table[Exp[N[2 Pi I ((i-32)^2 + (j-32)^2)/64]], {i,.001,63.876,.125},{j,.001,63.876,.125}]
>
>Why should this take so much resource?  Is there a better way to generate an array of function values?

Try compiling the expression that you are iterating.  First, for
comparison here is the uncompiled version on my machine (note the much
abbreviated limits of iteration):

(Local) In[3]:=
    Table[Exp[N[2 Pi I ((i-32)^2 + (j-32)^2)/64]],
	{i,.001,3.876,.125},{j,.001,3.876,.125}]; // Timing
(Local) Out[3]=
    {2.4 Second, Null}

Now for the compiled version:

(Local) In[11]:=
    f = Compile[{i, j},
	Exp[2 Pi I ((i-32)^2 + (j-32)^2)/64]]
(Local) Out[11]=
    CompiledFunction[{i, j}, 
     
			  2           2
	  2 Pi I ((i - 32)  + (j - 32) )
      Exp[------------------------------], -CompiledCode-]
			64

(Local) In[12]:=
    Table[f[i,j],
	{i,.001,3.876,.125},{j,.001,3.876,.125}]; // Timing
(Local) Out[12]=
    {0.616667 Second, Null}

By the way, I hope you're not trying to print the result of your Table
command in the front-end.  The amount of time necessary to format the result
and transmit it to the front-end considerably outweighs the computation time.

		Dave Wagner
		Principia Consulting
		(303) 786-8371
		dbwagner at princon.com
		http://www.princon.com/princon

==== [MESSAGE SEPARATOR] ====


  • Prev by Date: Re: mathematica-macppp conflict
  • Next by Date: Re: addressing matrix elements
  • Previous by thread: Table[] Why such a hog?
  • Next by thread: Re: ?? Lot of errors when loading <<Calculus VectorAnalysis twice