Thanks both.

There's been quite a lot of subsequent correspondence about the relative performance
of u/\ and u/\.        .

What I was actually griping about was the relatively poor performance of
M&|@:u (distributed across an array in some manner) compared to plain u,
as here with add32 cf +     .

eg if I defer the residue calculations,  as in
a32mdplus=: ((1 add32 {:)(+ ((16) 33 b.])) (#add32(+/)))@:(+ scan)@(a.&i.)

we get (with apologies for any Thunderbirdy line-folding)

    100 st 'a32mdfast 1000$''The quick brown fox jumps over the lazy dog'''

+------------------------------------------------------------+-----+---------+-------+

|a32mdfast 1000$'The quick brown fox jumps over the lazy dog'|31616|0.0016239|51.3412|

+------------------------------------------------------------+-----+---------+-------+


    100 st 'a32mdplus 1000$''The quick brown fox jumps over the lazy dog'''

+------------------------------------------------------------+-----+-----------+-------+

|a32mdplus 1000$'The quick brown fox jumps over the lazy dog'|31488|0.000167354|5.26964|

+------------------------------------------------------------+-----+-----------+-------+


NB I haven't investigated the consequences of Bill's remark about the final
step properly being

({: (23 b.) 16&(33 b.)@{.) s2,s1

His remarks elsewhere about the chunk size being 32 or 64 kbytes suggest 
deferring the
residue calculation is acceptable.

Mike



On 26/08/2014 20:47, Jose Mario Quintana wrote:
Raul already described the problem; I often use an adverb (scan) instead of
(/\.) to solve this kind of issues:

    u ( scan=. ((~/)\.)(&.|.) )
u~/\.&.|.

Again, the difference between these adverbs can be appreciated by means of
symbolic nouns and verbs:

    ( YS=. <;._1 ' Y0 Y1 .. YN' )
┌──┬──┬──┬──┐
│Y0│Y1│..│YN│
└──┴──┴──┴──┘

    u e /\   YS
┌──┬─────────┬────────────────┬───────────────────────┐
│Y0│(Y0 u Y1)│(Y0 u (Y1 u ..))│(Y0 u (Y1 u (.. u YN)))│
└──┴─────────┴────────────────┴───────────────────────┘

    u e scan YS
┌──┬─────────┬────────────────┬───────────────────────┐
│Y0│(Y0 u Y1)│((Y0 u Y1) u ..)│(((Y0 u Y1) u ..) u YN)│
└──┴─────────┴────────────────┴───────────────────────┘

  Using scan for the case at hand:

    a32mdslow=. ((1 add32{:)(+ 16 (33 b.)]) (#add32(add32/)))@:(add32 /\
  )@(a.&i.)
    a32mdfast=. ((1 add32{:)(+ 16 (33 b.)]) (#add32(add32/)))@:(add32
scan)@(a.&i.)

    a32mdslow 'The quick brown fox jumps over the lazy dog'
1541148634
    a32mdfast 'The quick brown fox jumps over the lazy dog'
1541148634

    st=. (] , <@:(1&({::) * 2&({::)))@:(] ; 7!:2@:] ; 6!:2)

    100 st 'a32mdslow ''The quick brown fox jumps over the lazy dog'''
┌───────────────────────────────────────────────────────┬────┬───────────┬───────┐
│a32mdslow 'The quick brown fox jumps over the lazy
dog'│6400│0.000638435│4.08598│
└───────────────────────────────────────────────────────┴────┴───────────┴───────┘
    100 st 'a32mdfast ''The quick brown fox jumps over the lazy dog'''
┌───────────────────────────────────────────────────────┬────┬──────────┬────────┐
│a32mdfast 'The quick brown fox jumps over the lazy
dog'│5376│3.70866e_5│0.199378│
└───────────────────────────────────────────────────────┴────┴──────────┴────────┘

        st 'a32mdslow 10000 $ ''The quick brown fox jumps over the lazy
dog'''
┌───────────────────────────────────────────────────────────────┬──────┬───────┬─────────┐
│a32mdslow 10000 $ 'The quick brown fox jumps over the lazy
dog'│676736│21.8528│1.47886e7│
└───────────────────────────────────────────────────────────────┴──────┴───────┴─────────┘
        st 'a32mdfast 10000 $ ''The quick brown fox jumps over the lazy
dog'''
┌───────────────────────────────────────────────────────────────┬──────┬──────────┬───────┐
│a32mdfast 10000 $ 'The quick brown fox jumps over the lazy
dog'│414592│0.00841716│3489.69│
└───────────────────────────────────────────────────────────────┴──────┴──────────┴───────┘

I hope it helps.



On Sun, Aug 24, 2014 at 10:11 AM, Raul Miller <[email protected]> wrote:

On Sun, Aug 24, 2014 at 6:43 AM, [email protected]
<[email protected]> wrote:
I continue to be puzzled by the poor performance of something
like add32/\ compared to +/\  .
The answer, here, can be explained in terms of an issue which I remember
being taught in gradeschool - "the associative law". (Of course, most
gradeschool students are not sufficiently terrified or interested or
whatever
it takes, to retain an interest in such things.)

u/\ 1 2 3 4 is

1, (1 u 2), (1 u (2 u 3)), (1 u (2 u (3 u 4)))

+ is known to be associative, so +/\ rearranges the order of computation,
and instead computes this sequence:

1, (1+2), ((1+2)+3), (((1+2)+3)+4)

Note also that with floating point numbers addition is in some cases just
an approximation, so it's possible to construct a sequence of numbers
which reveals this issue.

Thanks,

--
Raul
----------------------------------------------------------------------




-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2014.0.4716 / Virus Database: 4007/8107 - Release Date: 08/26/14

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to