Phenomenal. A good new line of thought.

   n=. 1 0$~<:+:#b         NB. more general
   ts';n #^:_1!.(<a) b'
0.0122812 1.31219e6

   ts';((1 0$~_1 2 p.#) #^:_1!.(<a) ])b'    NB. even with integrated n
0.0276326 2.13248e6

   ts'(;@(#^:_1!.(<a))~  1 0$~_1 2 p.#)b'   NB. but! tacitizing helps more
0.0124368 1.57594e6

Interestingly, a similarly simpler expression
has poorer time and space:

   ts'}:;1j1 #!.(<a) b'     NB. }: is negligible
0.0780418 1.73027e7

   ts'}:1j1 ;@(#!.(<a)) b'  NB. and tacitizing doesn't help
0.0779945 1.70406e7


--- david alis <[EMAIL PROTECTED]> wrote:

> (#^:_1)!. is better.
> 
>    b=: 100000#<,'a'
>    a=:'-'
>    n=: 199999$1 0
>         ts'Q=:}:@;@:(,&a &.>) b'
> 0.0464003 7.85971e6
> 
>       ts'QQ=:;n(#^:_1)!.(<a) b'
> 0.0146013 1.31226e6
> 
>       QQ -: Q
> 1


--- Oleg Kobchenko <[EMAIL PROTECTED]> wrote:

>    a=. '-'
>    b=. 100000#<,'a'
> 
> (,&a &.>) has a lot of memory allocations at once,
> but it's very fast
> 
>    ts'}:@;@:(,&a &.>) b'
> 0.0267479 7.85965e6
> 
> 
> Explicit loop has fewer allocations, but
> loses because it's explicit.
>    ts'a join1 b'
> 0.625234 396032
> 
> (, a&,)&.>/ should have been most efficient,
> because it does not allocate (much) unnecessary memory,
> but it makes a lot of new allocations (see in Kernel times).
> 
>    ts'>@((, a&,)&.>/) b'
> 10.4247 789312
> 
> However this pattern (, f)&.>/ is treated
> as equivalent to join2:
> 
>    ts'a join2 b'
> 11.5594 1.46112e6
> 
> not as r=. r, ... as in join1, which is optimized.
> 
> 
> join1=: 4 : 0
>   r=. ''
>   for_i. y do.
>     if. #r do. r=. r,'-' end.
>     r=. r,>i
>   end.
> )
> 
> join2=: 4 : 0
>   r=. >{:y
>   for_i. |.}:y do.
>     r=. (>i), '-'&, r
>   end.
> )
> 
> 
> --- Björn Helgason <[EMAIL PROTECTED]> wrote:
> 
> >  }.,'-'  ,"1 > ,.'a';'bc';'def'
> > 

> > 2007/6/14, Henry Rich <[EMAIL PROTECTED]>:
> > >
> > > I often have boxed data like
> > >
> > > 'a';'bc';'def'
> > >
> > > that I want to run together with delimiters, for example
> > >
> > > a-bc-def
> > >
> > > I admit this is not such a challenge; my best solution is
> > >
> > > }:@;@:(,&'-'&.>) 'a';'bc';'def'
> > >
> > >
> > > But I don't like the way it looks; especially I don't like
> > > that }: is really the obverse of (,&'-') but that fact does not
> > > appear (and I don't want to add yet more code by replacing }:
> > > with ,&'-'^:_1 ).
> > >
> > > We have a function that runs boxes together: ;:^:_1 .  Why
> > > not let it take a Fit that gives the delimiter
> > > (' ' by default)?  Then I would write
> > >
> > > ;:^:_1!.'-' 'a';'bc';'def'



      
____________________________________________________________________________________
Park yourself in front of a world of choices in alternative vehicles. Visit the 
Yahoo! Auto Green Center.
http://autos.yahoo.com/green_center/ 
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to