MathGroup Archive 1996

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

Search the Archive

Re: Table[] Why such a hog?

  • To: mathgroup at
  • Subject: [mg3573] Re: Table[] Why such a hog?
  • From: espen.haslund at (Espen Haslund)
  • Date: Mon, 25 Mar 1996 21:35:03 -0500
  • Organization: Universitet i Oslo
  • Sender: owner-wri-mathgroup at

In article <4iqpo1$puj at>, newnews at 
>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]], 
>Why should this take so much resource?  Is there a better way to generate 
an array of function values?
>What is Mathematica doing that take so long?
>BTW, the equivalent expression in APL completes on the same machine in less 
than 6 seconds.
>Bob Shelby
Hi, Bob,

My idea is to use a CompiledFunction.
I still had to shorten your example to run it.

IN:  f[i_, j_] := 
     Exp[N[2 Pi I ((i-32)^2 + (j-32)^2)/64]]

IN:  g = Compile[{i,j},Evaluate[f[i, j] ] ]

OUT: CompiledFunction[{i, j}, 
                         2             2
  0.0981748 I ((-32. + i)  + (-32. + j) )
 E                                       , 

IN:  Timing[fdata = Table[f[i, j],
     {i,.001,5.,.125},{j,.001,5.,.125}]; ]

OUT: {6.59 Second, Null}

IN:  Timing[gdata = Map[g[#[[1]], #[[2]] ] &,
     Table[{i,j}, {i,.001,5.,.125},{j,.001,5.,.125}],
     {2} ];]

OUT: {1.54 Second, Null}

IN:  Chop[gdata - fdata] == 0*fdata

OUT: True



  • Prev by Date: Re: mathematica-macppp conflict
  • Next by Date: Re: ListContourPlot: AxesLabels? (Q)
  • Previous by thread: Re: mathematica-macppp conflict
  • Next by thread: Subscripts in graphics labels