MathGroup Archive 2003

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

Search the Archive

Re: Re: Re: recode procedural algorithm to faster functional module

  • To: mathgroup at smc.vnet.net
  • Subject: [mg44088] Re: [mg44075] Re: [mg44059] Re: [mg44034] recode procedural algorithm to faster functional module
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Wed, 22 Oct 2003 03:24:43 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Sorry, I did not see your posting before replying to Tom Burton's 
message.
Andrzej


On Tuesday, October 21, 2003, at 03:07 PM, Peter Pein wrote:

> Andrzej,
> you're right. Even if one tunes the code a bit, it becomes again 5-7 
> times
> faster (on my machine):
>
> Concurrence = Compile[{{v1, _Real, 2}, {v2, _Real, 2}},
>     Module[{i, j, r = 0},
>      Do[If[If[v1[[i,1]] > v2[[j,1]], v1[[i,1]] < v2[[j,2]],
>          v1[[i,2]] > v2[[j,1]]], r++], {i, Length[v1], 1, -1},
>        {j, Length[v2], 1, -1}]; r], {{{i|j|r}, _Integer}}];
>
> But we have been asked by Robert, to recode this module in functional 
> style.
>
> Peter Pein, Berlin
> petsie at arcAND.de
> replace && by || to write to me
>
>
> ----- Original Message -----
> From: "Andrzej Kozlowski" <akoz at mimuw.edu.pl>
To: mathgroup at smc.vnet.net
> To: mathgroup at smc.vnet.net
> Subject: [mg44088] [mg44075] Re: [mg44059] Re: [mg44034] recode procedural 
> algorithm to faster
> functional module
>
>
>> Actually in this sort of situation  a procedural algorithm will be  at
>> least as fast if it is compiled.
>> Using your own codes with the only difference made by compilation,
>> procConcurrence now wins. at least on my machine.
>>
>> procConcurrence = Compile[{{v1, _Real, 2}, {v2, _Real, 2}}
>>        , Module[{c = 0},
>>     Do[Do[Which[
>>     v1[[i]][[1]] == v2[[k]][[1]], c++,
>>     v1[[i]][[1]] < v2[[k]][[1]] && v1[[i]][[2]] > v2[[k]][[1]], c++,
>>     v1[[i]][[1]] > v2[[k]][[1]] && v1[[i]][[1]] < v2[[k]][[2]], c++],
>>     {i, Length[v1], 1, -1}], {k, Length[v2], 1, -1}]; c]];
>>
>>
>>
>>
>> v1=Table[{i-Random[],i+Random[]},{i,100}];
>> v2=Table[{i-Random[],i+Random[]},{i,1000}];
>>
>>
>> (Timing[#1[v1, v2]] & ) /@ {Concurrence, procConcurrence}
>> (Timing[#1[v2, v1]] & ) /@ {Concurrence, procConcurrence}
>>
>>
>> {{2.08 Second,181},{1.79 Second,181}}
>>
>>
>> {{2. Second,181},{1.76 Second,181}}
>>
>> Andrzej Kozlowski
>> Yokohama, Japan
>> http://www.mimuw.edu.pl/~akoz/
>> http://platon.c.u-tokyo.ac.jp/andrzej/
>>
>>
> <old messages omitted>
>
>
>
Andrzej Kozlowski
Yokohama, Japan
http://www.mimuw.edu.pl/~akoz/
http://platon.c.u-tokyo.ac.jp/andrzej/


  • Prev by Date: Re: Run[] and Mathlink
  • Next by Date: Re: Re: recode procedural algorithm to faster functional module
  • Previous by thread: Re: Re: recode procedural algorithm to faster functional module
  • Next by thread: Re: Re: recode procedural algorithm to faster functional module