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

Reply via email to