Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: Vectorization

  • To: mathgroup at smc.vnet.net
  • Subject: [mg60653] Re: Vectorization
  • From: Maxim <ab_def at prontomail.com>
  • Date: Fri, 23 Sep 2005 04:19:58 -0400 (EDT)
  • References: <dgtjh4$2bk$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On Thu, 22 Sep 2005 06:38:28 +0000 (UTC), Marcelo Mayall  
<mmayall at bol.com.br> 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: sporadic failure of SingularValueDecomposition[] in Mathematica 5.2
  • Next by Date: Re: Vectorization
  • Previous by thread: Re: Vectorization
  • Next by thread: Re: Vectorization