When something is slow, it's usually because you
are operating with too low a rank.

Here, you are interpreting up82 6400 times,
which is about 2/3 of the problem.

Also, it's better to use &.> to do the boxing
and unboxing, since that's optimized.

The following runs fast (I'm on J6):

,.   {&(,M0 , (< 0 0))&.>   ,&.>   ,m

I had to ,&.> the m to get the same results as the
original.

I suspect   ,M0 , (< 0 0)   is not creating what you
think.

Henry Rich

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of p j
> Sent: Thursday, February 23, 2006 5:41 PM
> To: [email protected]
> Subject: [Jprogramming] Strange performance problem
> 
> At the bottom of this message is timing code for what
> I naively think should be the same function call.  But
> one is over 1000 times faster.  
> 
> The code (x up82 y) is called with x as a column of
> boxes, where each box contains 1 to 3 indexes to look
> up in y.
> x up82"1 y returns the result without filling (what I
> want), but is slow.  IE if a box in x has only one
> index, the function returns only one box in the result
> instead of filling the result with 0{y.
> x up82 y fills result with 0{y
> 
> 1. I don't really understand the difference between
> the 2 function calls, so thank you for any patience in
> explaining the difference.
> 2. I'm curious why one is 1400x times slower
> 
> -------SETUP CODE
> 
> 
>  M =: i.80 80
>  m=: (1+i.(80*80)),(80+i.(80*80)),(_80+i.(80*80))
>  m=: 80 80 $(<"1 (>"1 (|: (3 6400 $ m))))
>  m=: (<"1 (}:"1 (>0{m))) 0}m
>  m=: (<"1 (0 2 {"1 (>_1{m))) _1}m
>  m=: (<"0 (1+ 80*i.80) ) (< a: ; 0) } m
>  m=: (<"0 (80$ 6400)) (< a: ; _1) } m NB. add trailing
> 0 in 6401st position of input matrix
>  M0 =. 80 80 $ <"1 (,. , +/\."1 M),"1 (,.,M)
> 
> up82 =: 4 : 0
> <"1((> x.) { y.)
> )
> 
> ------------TIMING CODE
> ts '(,. ,m) up82 ,M0 , (< 0 0)'
> 0.0216966 994048
> ts '(,. ,m) up82"1 ,M0 , (< 0 0)'
> 27.8915 1.27974e6
> 
> 
>       
> 
>       
>               
> __________________________________________________________ 
> Find your next car at http://autos.yahoo.ca
> ----------------------------------------------------------------------
> 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