ts=: 6!:2 , 7!:[EMAIL PROTECTED]
y=: <"1 ] 10000 5 [EMAIL PROTECTED] 0
b=: <"1 ] 10000 5 [EMAIL PROTECTED] 2
ts '>@(+&.>/\.) y'
0.020435 3.38144e6
ts '+&.>/\. y'
0.0162339 2.85677e6
ts '>@(+.&.>/\.) b'
0.0189664 2.28282e6
ts '+.&.>/\. b'
0.015533 2.2169e6
Not much to be gained.
----- Original Message -----
From: Henry Rich <[EMAIL PROTECTED]>
Date: Saturday, May 5, 2007 1:51 pm
Subject: [Jprogramming] Proposal: unboxing suffix scans
> /\. is such a workhorse in J that some common cases might
> be worth special code:
>
> 0. >@(f&.>/\.)
>
> Here, if the result of f is small, it would be nice to produce the
> unboxed result directly, saving the boxing overhead on the suffix
> results.
>
> 1. m&{.@>@(f&.>/\.)
>
> This is a potential huge gain. For many scan-type operations, the
> intermediate result contains a lot of state that is needed for the
> computation of f but is not needed in the final result. In the form
> given, the interpreter knows enough to keep each result of f, unboxed,
> for the next call to f, and then to discard the items that are not
> needed in the final result. This would save not just the boxing
> overhead but also the storage of the intermediate vector for each
> input item.
>
> 2. (f&.>/\.)@:(<"n) and variants like 0 and 1 above
>
> To cause the scan to work on the appropriate cells when they are not
> items, the cells must be boxed. The boxing/unboxing could be avoided.
>
> 3. (f&.>/\.)@:(<"[EMAIL PROTECTED] , <@]) and variants like 0 and 1 above
>
> A very common case is where the scan is to be applied to an array
> with an initial value given. Usually, the initial value has the shape
> of a result of f, which is different from the shape of an item of
> the array. Then, it is necessary to box everything up, append the
> intial value to the end of the array, and perform the scan.
> Recognizingthis pattern would save the boxing and the append,
> which will be a
> big gain if the items of the array are small.
>
> Henry Rich
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm