MathGroup Archive 2006

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

Search the Archive

Re: Compile Fourier (2)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg64908] Re: Compile Fourier (2)
  • From: Peter Pein <petsie at dordos.net>
  • Date: Tue, 7 Mar 2006 06:12:00 -0500 (EST)
  • References: <duh2s0$5qg$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Alberto Verga schrieb:
> (Please, forget my last question, the answer is in the third argument of 
> Compile; but...)
> Someone could explain why the compiled version is slower than the uncompiled 
> one in the following example?
> 
> (* Compiled *)
> cf = Compile[{{m, _Complex, 2}}, Module[{a, b = {m}}, a = m;
> Do[a = a + Fourier[Re[InverseFourier[m]]]; AppendTo[b, a];, {100}];
> Return[Re[b]]], {{Fourier[_], _Complex,
> 2}, {InverseFourier[_], _Complex, 2}}]
> 
> mm = cf[Table[N[i - j], {i, 64}, {j, 64}]]; // Timing
> {2.654 Second, Null}
> 
> (*Uncompiled*)
> 
> f[m_] := Module[{a, b = {m}}, a = m;
> Do[a = a + Fourier[Re[InverseFourier[m]]]; AppendTo[b, a];, {100}];
> Return[Re[b]]];
> 
> mmf = f[Table[N[i - j], {i, 64}, {j, 64}]]; // Timing
> {0.35 Second, Null}
> 
> Thanks,
> 
> Alberto Verga
> Alberto.Verga at irphe.univ-mrs.fr
> 
> 
> 
> 
Hi Alberto,

  I've overlooked this second posting when answering the first - sorry.

I can't tell you, why the uncompiled code is faster than the compiled version, but if you want to speed it up...

f[m_] := Module[{a, b = {m}}, a = m; Do[a = a + Fourier[Re[InverseFourier[m]]];
        AppendTo[b, a]; , {100}]; Return[Re[b]]];
Timing[mmf = f[Table[N[i - j], {i, 64}, {j, 64}]]; ]
--> {0.156*Second, Null}

and because Fourier[Re[InverseFourier[m]]] is a constant matrix,

Timing[mmf2 = Fourier[Re[InverseFourier[t = Table[N[i - j], {i, 64}, {j, 64}]]]];
    mmf2 = Re[(t + #1*mmf2 & ) /@ Range[0, 100]]; ]
--> {0.047*Second, Null}

mmf == mmf2
--> True

Hope this helps a bit,
   Peter


  • Prev by Date: Re: Compile Fourier
  • Next by Date: Re: Extract values and multilpicities from list
  • Previous by thread: Compile Fourier (2)
  • Next by thread: Re: Compile Fourier (2)