bug-apl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: better apl array coding


From: enztec
Subject: Re: better apl array coding
Date: Wed, 16 Jun 2021 16:05:37 -0600

Hi

you suggested changes to the loop code reduced run time from 41 seconds to 29 
seconds but still doesn't compare to the ¨/⌷/⊂ code at 50 msec
size of data is 30000 and i ran in a ram drive

Has anyone tried this on some faster machines?

I'm going to run all on a rasp pi and see what times are





On Wed, 1 6 Jun 2021 12:35:25 +0200
Dr. Jürgen Sauermann <mail@xn--jrgen-sauermann-zvb.de> wrote:

> Hi,
>
> the biggest problem with your old loop code is its quadratic runtime.
>
> The statement
>
> rs←rs,ar[a[i]; b[i]]
> takes more and more time as rs grows. GNU APL has occasionally been
> blamed for being slow, but in most cases the above coding pattern was
> the real reason. A faster way in your old loop code is to:
>
> rs←(⍴A)⍴0
>
> before the loop and then
>
> rs[i]←ar[a[i]; b[i]]
>
> inside the loop, which takes only linear time.
>
> In general: never use , or ⍪ inside a (long) loop, even
> though the code may look more intuitive or elegant.
>
> Best Regards,
> Jürgen
>
>
> On 6/16/21 4:39 AM, enztec@gmx.com wrote:
>
> Hi
>
> thanks for this code - first time actually using ¨ and ⌷
>
> in my comparison test on an old hp dual core linux machine - with only 
> mplayer running
> with ⍴a and ⍴b 29882 chars
>
> according to ⎕ts   my loop code takes ~39 seconds to put results into rs
> 2021 6 15 19 46 11 277
> 2021 6 15 19 46 50 354
>
> and the new code takes ~50 msec to put results into rs1    yes msec vs 
> seconds   what is that 39000 msec vs 59 msec
> 2021 6 15 19 46 50 354
> 2021 6 15 19 46 50 404
>
> +/rs1=rs    and rs and rs1 don't exist before running them in fns
> 29882
>
> ----
>
> the only problem i have is in a fresh ws running the )copy as
>
> ⍎')copy mn9     mn9 is a file which has a string of 29882 chars assigned to 
> mn9←'xxxxx' in it
> a←mn9             gives mn9 value error consistently - though when i check 
> the )vars it is there and complete - running it in ram drive has no effect
>
> the unquoted ')copy'  doesn't actually finish coping the file into the ws as 
> fast as the code returns and goes to the next line
>
> no real problem as i usually hard code the sequnces (cutnpaste) into the 
> script - but with some in the 100K range i will have to do the )copy manually 
> and run in workspace
>
> thank you for giving me this code - much appreciated
>
>
>
> On Tue, 15 Jun 2021 15:20:27 +0200
> Dr. Jürgen Sauermann <mail@xn--jrgen-sauermann-zvb.de> wrote:
>
> Hi,
>
> how about:
>
>       (a,¨b)⌷¨⊂ar
> 11 22 33 44 44 33 22 11
>
>
> Best Regards,
> Jürgen
>
>
> On 6/15/21 2:45 AM, enztec@gmx.com wrote:
> hello
>
> i've been using this looping for array work but there has to be a better apl 
> way of coding the indexing of the ar array
> any suggestions
>
>
>
> ∇rs←lp;a;b;ar;i
> 'lp'
> 'ar'
> +ar←4 4⍴11 12 13 14 21 22 23 24 31 32 33 34 41 42 43 44
> 'a '
> +a←1 2 3 4 4 3 2 1
> 'b '
> +b←1 2 3 4 4 3 2 1
> i←1
> rs←⍴0
> sp:
> rs←rs,ar[a[i]; b[i]]
> →((i←i+1)⍴a)/sp
> ''
>
>
>
>
>
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]