In the case of updating lots of small arrays, there is
little difference between the 2.  But this version is
also a small improvement.  Though upfltr2 turns up to
be a bit faster.
 I asked the question, because I wondered if this was
the "right" way to do this common task.  I guess all
of these are fast enough. 

upfltr5 =: 4 : 0
        NB. update filtered y. x upV`fltrV, 
        '`up f' =. x
   (up (f y)#y) (I. f y)}y
)
zz=. 1e4 10 $?.2e2# 20

   6!:2 'zz=:+:`(10&>) upfltr"1 zz'
0.218465754726
   6!:2 'zz=:+:`(10&>) upfltr4"1 zz'
0.213576865216
   6!:2 'zz=:+:`(10&>) upfltr5"1 zz'
0.208311670897
   6!:2 'zz=:+:`(10&>) upfltr2"1 zz'
0.195342704171

--- Devon McCormick <[EMAIL PROTECTED]> wrote:

> May be slightly better to use a temporary instead of
> repeating "f y" (see
> "upfltr4" below):
> 
> upfltr2=: 4 : 0
> NB. update filtered y. x updateV`fltrV,
>    '`up f' =. x
>    (f y)}y,:up y
> )
> 
>    zz=. 1e4?1e9
>    6!:2 '+:`(10&>) upfltr2 zz'
> 0.0019156066                     NB. Not as fast...
>    6!:2 '+:`(10&>) upfltr zz'
> 0.00057269849
> 
> upfltr3=: 4 : 0
> NB. update filtered y. x updateV`fltrV,
>    '`up f' =. x
>    (up y#~f y) (I. f y) } y
> )
>    +:`(10&>) upfltr3 5 9 11 12
> 10 18 11 12
>    6!:2 '+:`(10&>) upfltr3 zz'
> 0.00056320007                 NB. Basically the
> same...
> 
> upfltr4=: 4 : 0
> NB. update filtered y. x updateV`fltrV,
>    '`up f' =. x
>    xx=. f y
>    (up xx#y) (I. xx)}y
> )
>    6!:2 '+:`(10&>) upfltr4 zz'
> 0.00045368895                 NB. Marginally faster?
>  Hard to conclude...
> 
> 
> On 4/19/06, Pascal Jasmin <[EMAIL PROTECTED]>
> wrote:
> >
> >         NB. update only selected items from y with
> monad
> > function of y, leave rest unchanged.
> > upfltr =: 4 : 0
> >         NB. update filtered y. x updateV`fltrV,
> >         '`up f' =. x
> >         (up (I. f y){ y) (I. f y) } y
> > )
> > NB. double items greater than 10:
> >    +:`(10&>) upfltr 5 9 11 12
> > 10 18 11 12
> >
> > is there a faster way to implement the above? 
> Seems
> > to me the above verb should be one of the built-in
> > gerund ammend options, (maybe it is, and I just
> don't
> > understand the documentation for it).
> >
> ...
> --
> Devon McCormick
> ^me^ at acm.
> org is my
> preferred e-mail
>
----------------------------------------------------------------------
> For information about J forums see
> http://www.jsoftware.com/forums.htm
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to