MathGroup Archive 2005

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

Search the Archive

Re:Re: Vectorization

  • To: mathgroup at smc.vnet.net
  • Subject: [mg60820] Re:[mg60653] Re: Vectorization
  • From: "Marcelo Mayall" <mmayall at bol.com.br>
  • Date: Thu, 29 Sep 2005 05:42:00 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Dear Maxim Rytin,

Although it is not very intuitive, using N[I] instead of I really reduces significantly the computational cost:

In[1]:=
Sin[Table[I Random[],{300000}]]//Timing//First
Sin[Table[N[I] Random[],{300000}]]//Timing//First

Out[1]=
0.766 Second

Out[2]=
0.297 Second

Curious however, that with complex numbers there is almost no difference (in terms of computational cost) among using Table[Sin [...],...] or Sin[Table [...],...].    
Will it be due to some limitation of the processor?

In[3]:=
Table[Sin[N[I] Random[]],{300000}]//Timing//First
Sin[Table[N[I] Random[],{300000}]]//Timing//First

Out[3]=
0.328 Second

Out[4]=
0.313 Second

In[5]:=
Table[Sin[Random[]],{1000000}]//Timing//First
Sin[Table[Random[],{1000000}]]//Timing//First

Out[5]=
0.344 Second

Out[6]=
0.203 Second



Thanks,

Marcelo Mayall


---------- Início da mensagem original ----------- 
De: "Maxim" ab_def at prontomail.com 
Para: mathgroup at smc.vnet.net 
Data: Fri, 23 Sep 2005 04:19:58 -0400 (EDT) 
Assunto: [mg60653] Re: Vectorization 
> On Thu, 22 Sep 2005 06:38:28 +0000 (UTC), Marcelo Mayall 
> wrote: 
> 
> > It's possible to initialize a vector starting from an elementary 
> > functions: 
> > 
> > In[1]:= 
> > Table[Sin[Random[]],{10000000}]//Timing//First 
> > 
> > Out[1]= 
> > 3.203 Second 
> > 
> > The same problem can be done a bit more efficiently if the elementary 
> > function is applied to the numerical vector: 
> > 
> > In[2]:= 
> > Sin[Table[Random[],{10000000}]]//Timing//First 
> > 
> > Out[2]= 
> > 1.969 Second 
> > 
> > But why the tendency is opposed when the numbers are complex ? Is this a 
> > bug ? 
> > 
> > In[3]:= 
> > Table[Sin[I Random[]],{1000000}]//Timing//First 
> > Sin[Table[I Random[],{1000000}]]//Timing//First 
> > 
> > Out[3]= 
> > 2.484 Second 
> > 
> > Out[4]= 
> > 2.656 Second 
> > 
> > 
> > Thanks, 
> > 
> > Marcelo Mayall 
> > 
> 
> There was a discussion of a similar problem in sci.math.symbolic recently: 
> Table[1.*I*Random[], {10^6}] doesn't generate a packed array, and neither 
> does Table[Complex[0., 1.]*Random[], {10^6}]. You need to use Table[(0. 
> + 1.*I)*Random[], {10^6}] or Table[N[I]*Random[], {10^6}] instead, which 
> is not very obvious, as Complex[0., 1.], (0. + 1.*I) and N[I] evaluate to 
> the same thing. 
> 
> What's more, Table[N[Complex[0, 1]]*Random[], {10^6}] doesn't produce a 
> packed array either. Apparently some symbolic preprocessing is taking 
> place, and the preprocessor is very picky. 
> 
> Maxim Rytin 
> m.r at inbox.ru 
> 
> 


  • Prev by Date: Re: Importing (and dealing with) multiple files
  • Next by Date: Re: Importing (and dealing with) multiple files
  • Previous by thread: Re:Re: Vectorization
  • Next by thread: Generate polynomial of specified degree