It would be interesting to see some examples of these four cases.
2007/5/5, Henry Rich <[EMAIL PROTECTED]>:
/\. 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. Recognizing
this 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
--
Björn Helgason, Verkfræðingur
Fugl&Fiskur ehf, Þerneyjarsund 23, Box 127
801 Grímsnes ,t-póst: [EMAIL PROTECTED]
Skype: gosiminn, gsm: +3546985532
Landslags og skrúðgarðagerð, gröfuþjónusta
http://groups.google.com/group/J-Programming
Tæknikunnátta höndlar hið flókna, sköpunargáfa er meistari einfaldleikans
góður kennari getur stigið á tær án þess að glansinn fari af skónum
/|_ .-----------------------------------.
,' .\ / | Með léttri lund verður |
,--' _,' | Dagurinn í dag |
/ / | Enn betri en gærdagurinn |
( -. | `-----------------------------------'
| ) | (\_ _/)
(`-. '--.) (='.'=)
`. )----' (")_(")
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm