In traditional APLs there would be no (speed) comparison between i.~ and #/.~ vs. (# +/[EMAIL PROTECTED]:@(0&,))@(#;.1)@(1,2~:/\]) and #;.1@(1,2~:/\]) , because dyadic iota can be very slow depending on the data.
----- Original Message ----- From: Roger Hui <[EMAIL PROTECTED]> Date: Tuesday, July 31, 2007 8:28 Subject: Re: RE: [Jprogramming] simple verb To: Programming forum <[email protected]> > Another alternative. Actually an alternative for i.~ for > this data > whose speed relative to i.~ depends on the kind of data. > > f2=: [EMAIL PROTECTED] - i.~ > f3=: [EMAIL PROTECTED] - (# +/[EMAIL PROTECTED]:@(0&,))@(#;.1)@(1,2~:/\]) > > c=: 1e5 [EMAIL PROTECTED] 10 > x=: c#i.#c > y=: 0.5 * x > > (f2 -: f3) x > 1 > (f2 -: f3) y > 1 > > ts=: 6!:2 , 7!:[EMAIL PROTECTED] > > ts 'f2 x' > 0.0192337 6.29222e6 > ts 'f3 x' > 0.0444705 7.86509e6 > > ts 'f2 y' > 0.150214 6.29222e6 > ts 'f3 y' > 0.0593807 7.86509e6 > > #;.1@(1,2~:/\]) is an alternative to #/.~ which may be > faster or slower depending on the kind of data. > (Slower on "easy" data; faster on "hard" data.) > > (#/.~ -: #;.1@(1,2~:/\])) x > 1 > (#/.~ -: #;.1@(1,2~:/\])) y > 1 > ts '#/.~ x' > 0.00797168 1.04941e6 > ts '#;.1@(1,2~:/\]) x' > 0.0135623 1.05043e6 > ts '#/.~ y' > 0.144353 6.29229e6 > ts '#;.1@(1,2~:/\]) y' > 0.0258773 1.05043e6 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
