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

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

Search the Archive

Re: Re: recode procedural algorithm to faster functional module

  • To: mathgroup at smc.vnet.net
  • Subject: [mg44075] Re: [mg44059] Re: [mg44034] recode procedural algorithm to faster functional module
  • From: "Peter Pein" <nospam at spam.no>
  • Date: Tue, 21 Oct 2003 02:07:48 -0400 (EDT)
  • References: <01435F28-0230-11D8-812A-00039311C1CC@mimuw.edu.pl>
  • Sender: owner-wri-mathgroup at wolfram.com

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
Subject: [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>


  • Prev by Date: Re: Integrate with piecewise function
  • Next by Date: Re: Mystery: NIntegrate'ing indeterminate-length integrand!
  • Previous by thread: Re: recode procedural algorithm to faster functional module
  • Next by thread: Re: Re: recode procedural algorithm to faster functional module