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: [mg52231] Re: [mg52194] Re: Counting Runs
  • From: DrBob <drbob at bigfoot.com>
  • Date: Mon, 15 Nov 2004 20:56:45 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

That seems to prove only that there's an optimization for packed arrays -- not for integer input.

Am I missing something?

Bobby

On Mon, 15 Nov 2004 16:54:37 +0900, Andrzej Kozlowski <akoz at mimuw.edu.pl> 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/
>
>
>
>



-- 
DrBob at bigfoot.com
www.eclecticdreams.net


  • Prev by Date: Re: Re: 64 bit cpu and Mathematica on windows.
  • Next by Date: neat sums and pattered randomness
  • Previous by thread: Re: Re: Counting Runs
  • Next by thread: Functions with optional parameters