R.E.  Boss wrote:
> 
> fiR_OOPS=: (0:`((>:@(i.{.)}.[) $: }.@])@.(e.~{.))`1:@.(''-:])"1
> fiR_ES=: +./@((*. 1 |.!.0 +./\.)/@(=/ |:)~)
> fiR_BO=: (('_',~"1 [)((>:@(i."1 {.) |.!.'' "_1 [) $: }.@])`(' ' ~:
> {."1@[)@.(0 = #@]) ])
>       NB. Guinns approach tacitly with rank _
> 
> Performance heavily depends on number  and length of strings.
>    AA=: data 20 3e3
>    BB=: data 1e3
> 
>    ts 'AA fiR_OOPS BB'        NB. Clear winner in this case
> 0.032740055 5488000
> 
>    ts 'AA fiR_ES BB'
> 0.26523284 67438720
> 
>    ts 'AA fiR_BO BB'
> 0.12177118 2.277536e8
> 
>    AA=: data 2000 3e1
>    BB=: data 1e1
> 
>    ts 'AA fiR_OOPS BB'        NB. Winner in product of time and space
> 0.029594062 31744
> 
>    ts 'AA fiR_ES BB'
> 0.0026858734 1378432
> 
>    ts 'AA fiR_BO BB'
> 0.0027664029 2504704
> 
> So overall fiR_OOPS gives the best performance.
>  fiR_ES is the most elegant, IMO.
> 
> 
> R.E. Boss
> 
> [...]
> 

I've optimized my chop-reduce code from other posts to:

NB. Reduce from left:  x u RL y === (...((x u y0) u y1)... u yn)

   RL =: 1 : 0
:
  for_e.y do.x=.x u e end.
  x
)

   findinrow=: {:@] e. ((>:@i. }. [)RL }:)


Benchmarks:

   ts=:6!:2,7!:2@]
   data=: 'ACGT' {~ 4 ?.@$~ ]

   fiR_OOPS=: (0:`((>:@(i.{.)}.[) $: }.@])@.(e.~{.))`1:@.(''-:])"1
   fiR_ES=: +./@((*. 1 |.!.0 +./\.)/@(=/ |:)~)
   fiR_BO=: (('_',~"1 [)((>:@(i."1 {.) |.!.'' "_1 [) $: }.@])`(' ' ~:
{."1@[)@.(0 = #@]) ])
  
   A=: data 2000 30
   B=: data 10
   (, 20j4 ": ts)"1 'A fiR_OOPS B','A fiR_ES B','A fiR_BO B',:'A findinrow"1
B'
A fiR_OOPS B                 0.0566          31744.0000
A fiR_ES B                   0.0021        1378432.0000
A fiR_BO B                   0.0087        2508160.0000
A findinrow"1 B              0.0824          11904.0000

   A=:data 20 3e5
   B=:data 10
   (, 20j4 ": ts)"1 'A fiR_OOPS B','A fiR_ES B','A fiR_BO B',:'A findinrow"1
B'
A fiR_OOPS B                 0.0565        5776768.0000
A fiR_ES B                   0.3677      109054080.0000
A fiR_BO B                   0.2213      176167168.0000
A findinrow"1 B              0.0172        1580032.0000

   A=:data 20 3e3
   B=:data 1000
   (, 20j4 ": ts)"1 'A fiR_OOPS B','A fiR_ES B','A fiR_BO B',:'A findinrow"1
B'
A fiR_OOPS B                 0.0808        5488000.0000
A fiR_ES B                   0.2321       67438720.0000
A fiR_BO B                   0.2721      227753600.0000
A findinrow"1 B              0.0820          23296.0000

   A=:data 20 3e4
   B=:data 1000
   (, 20j4 ": ts)"1 'A fiR_OOPS B','A fiR_ES B','A fiR_BO B',:'A findinrow"1
B'
A fiR_OOPS B                 0.6917       34189440.0000
A fiR_ES B                   2.6377     1078986880.0000
A fiR_BO B                   2.1861     2099330688.0000
A findinrow"1 B              0.2090         109312.0000

-- 
View this message in context: 
http://old.nabble.com/Search-for-ordered-letters-within-lines-of-matrix-tp32300638s24193p32303169.html
Sent from the J Programming mailing list archive at Nabble.com.

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to