nice.  Thank you.

some timings:

   + boxscan2  (;/ i.1e1), <0 10
45 55
   ts '+  boxscan2 (;/ i.1e5), < 0 10'
28.3202/sec 16.7722MB
   ts '+  L:0/ (;/ i.1e5), < 0 10'
28.1126/sec 16.7698MB


surprisingly faster than a straight sum that naively does half the work.

   10 ts '+ boxscan2  ;/ i.1e5'
21.51/sec 15.7212MB
   10 ts '+ leaf/  ;/ i.1e5'
22.3158/sec 15.7213MB

   10 ts '(] , [ + {:@]) boxscan2  (;/ i.1e4), < 1 11'
18.5193/sec 2.02419MB
   10 ts '(] , [ + {:@]) L:0/  (;/ i.1e4), < 1 11'
18.2314/sec 2.02381MB


on my kset verb (posted in past week)

   ts'(;~"0  i.1e3) kvset powerA h'
2.34987/sec 0.614144MB
   10 ts 'kvset  boxscan2  (<"1 ;~"0  i.1e3) , <h'
3.08833/sec 0.614144MB
   10 ts 'kvset  L:1/  (<"1 ;~"0  i.1e3) , <h'
2.98749/sec 0.614528MB



________________________________
From: Ric Sherlock <[email protected]>
To: Programming JForum <[email protected]> 
Sent: Wednesday, October 2, 2013 2:11:56 PM
Subject: Re: [Jprogramming] boxscan adverb - could performance be improved?


Perhaps this what you are looking for?
boxscan2=: 1 : '>@:(u&.>/)'
On Oct 3, 2013 5:54 AM, "Pascal Jasmin" <[email protected]> wrote:

> Recently I asked for a cleaner version of PowerA at bottom of quoted
> message.
>
> One such implementation is boxscan:
>
> boxscan =: 1 : '>@:(<@(>@[ u >@])/)'
>
>
> for any dyadic verb V, as long as x V y produces a shape that can be
> digested as the right argument to V, then V boxscan < each x, < y will work
> like '/' for any shapes/boxing of x and y.  The major usefulness is that
> '/' only works when x and initial y are the same shape because they have to
> fit in the same list together.
>
>  + boxscan ;/ i.1e1
> 45
>
> (;/ i.1e1), < 1 11
> ┌─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬────┐
> │0│1│2│3│4│5│6│7│8│9│1 11│
> └─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴────┘
>    (] , [ + {:@]) boxscan (;/ i.1e1), < 1 11
> 1 11 20 28 35 41 46 50 53 55 56 56
>
> Something that almost works instead of boxscan is (leaf /)
>
>   + leaf/ ;/ i.1e1
> ┌──┐
> │45│
> └──┘
>    (] , [ + {:@]) leaf / (;/ i.1e1), < 1 11
> ┌──────────────────────────────────┐
> │1 11 20 28 35 41 46 50 53 55 56 56│
> └──────────────────────────────────┘
>
> This actually only almost works, because it assumes unboxed core x and y
> shapes.  For verbs that can expect boxed x items and boxed y, then (leaf /)
> fails, but (L:1 /) works.  So double boxing the inputs:
>
>     + leaf L:1/ <"0 ;/ i.1e1
> ┌────┐
> │┌──┐│
> ││45││
> │└──┘│
> └────┘
>
> V could be a relatively complex inputs, but relatively simple operation of
> insert records into data structure, and so functions that support boxed
> parameters are useful.
>
> The only issue with the above is that it is 100x slower: (50x slower when
> you move the boxing outside of timing loop)
>
>     ts '+ leaf L:1/ <"0 ;/ i.1e5'
> 10.1755/sec 30.3905MB
>    ts '+ leaf/  ;/ i.1e5'
> 19.1274/sec 15.7213MB
>    ts '+ boxscan  ;/ i.1e5'
>
> 13.4397/sec 15.722MB
>    ts '+/  i.1e5'
> 1520.68/sec 1.05075MB
>
> although, actually it appears slow, just because +/ is incredibly fast
>
> These 2 very similar versions have only 10% speed difference
>
>    10 ts '(] , [ + {:@]) L:0 / (;/ i.1e4), < 1 11'
> 17.9466/sec 2.02381MB
>    10 ts '(] , [ + {:@])  / ( i.1e4+2)'
> 19.647/sec 0.39744MB
>
>
>    10 ts '(;/ i.1e4) (] , [ + {:@])  powerA L:0 < 1 11'
> 13.5675/sec 3.12538MB
>    10 ts '(] , [ + {:@]) boxscan (;/ i.1e4), < 1 11'
> 14.5873/sec 2.02483MB
>
> So I'd guess that f L:0 / is already special coded because the first 2
> functions speed differ by just 1% when the noun is created/assigned outside
> of the timing loop.
>
> I hope this post is still useful just for laying out the boxscan concept,
> which seems pretty useful, and not something I've seen presented elsewhere.
>
>
>
> ----- Original Message -----
> powerA =: 1 : 0
> :
> c =. y
> while. 0<#x do.
> a=. {. x
> c =. a u c
> x =. }. x
> end.
> c
> )
>
>    (;~"0  i.10) kvset powerA h
> ┌─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┐
> │1│3│a│5│0│2│4│6│7│8│9│
> ├─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
> │1│3│3│5│0│2│4│6│7│8│9│
> └─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘
>
>    ts '(;~"0  i.1e3) kvset powerA h'
> 2.82845/sec 0.630528MB
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to