Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*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 2004

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

Search the Archive

Re: Re: Counting Runs

  • To: mathgroup at smc.vnet.net
  • Subject: [mg52229] Re: [mg52194] Re: Counting Runs
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Mon, 15 Nov 2004 03:17:43 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Actually, this is not a very good test, since unpacking a large array 
also takes a non-negligible amount of time. The real effect should be 
somewhat larger.

Andrzej

On 15 Nov 2004, at 16:54, Andrzej Kozlowski wrote:

>>> I think Abs, Tr, and BitXor are very fast because they are probably
>>> optimized for integer input and the use of packed arrays.
>>
>> I don't think an optimization for integers can be effective if 
>> functions take time to CHECK whether the array contains only 
>> integers. Is that precomputed for packed arrays, somehow?
>>
>> Bobby
>
>
> Yes, that's precisely what packed arrays do. Actually you can check 
> precisely the effect of packed arrays in this case:
>
>
> << "Developer`"
>
>
> runs[int_, data_] := Module[{modlist},
>    modlist = Sign[Abs[data - int]];
>     Tr[BitXor[modlist, RotateRight[modlist]]]/2 + 1 -
>      BitOr[modlist[[1]], modlist[[-1]]]]
>
>
> runs1[int_, data_] :=
>   Module[{modlist, dt = FromPackedArray[data]},
>    modlist = FromPackedArray[Sign[Abs[dt - int]]];
>     Tr[BitXor[modlist, RotateRight[modlist]]]/2 + 1 -
>      BitOr[modlist[[1]], modlist[[-1]]]]
>
>
> seq = Table[Random[Integer, 10], {10^6}];
>
>
> Timing[runs[3, seq]]
>
>
> {0.4299999999999997*Second, 83183}
>
>
> Timing[runs1[3, seq]]
>
>
> {0.9299999999999997*Second, 83183}
>
> So just over 50% performance increase.
>
>
> Andrzej Kozlowski
> Chiba, Japan
> http://www.akikoz.net/~andrzej/
> http://www.mimuw.edu.pl/~akoz/
>


  • Prev by Date: [LinearAlgebra] Re: Matrix Dot Product
  • Next by Date: [DSolve] Re: newbie question DSolve (revisited again)
  • Previous by thread: Re: Re: Counting Runs
  • Next by thread: Re: Re: Counting Runs