---Devon McCormick wrote:
> As a rule, code that avoids globals is better than code that
> uses globals.
I agree and I wasn't suggesting that those verbs using globals be used in
production. I was just looking for a method to compare the different algorithms
(that replaced 0 in M with _ and reassigned the result to M), in a way that
algorithms using in-place assignment would have a chance to shine.
> However, when I changed one of these functions to use an
> explicit argument,
> I was surprised by the performance difference:
>
> amZ1y=: 3 : 0
> zeros=. 0=y
> inf=. ($y)$_
> zeros} y,: inf
> )
>
> NB. versus the original
>
> amZ1=: 3 : 0
> zeros=. M = 0
> inf=. ($M) $ _
> M=: zeros} M ,: inf
> )
>
> M=: M2 NB. As in the preceding messages...
> ts 'amZ1 '''''
> 0.077218335 4.4459898e8
> ts 'amZ1y M'
> 0.27146536 4.1104422e8
I don't think these compare apples with apples. The second one doesn't apply
the result to M. To do that I think you need to do:
ts 'M=: amZ1y M'
But then assignment in no longer "in place".
> NB. Big difference - but it's because of "cheating":
> ts 'amZ1 '''' [ M=: M2'
> 0.27324012 3.7749037e8
I don't understand what you're getting at here?
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm