Or, more concisely,

A =: >:@[ %@:+ + -:@:* >:@:+

is considerably faster than

A =: >:@[ %@+ + -:@* >:@+

in this context.

Thanks,

-- 
Raul

On Sun, Feb 15, 2015 at 5:46 PM, Tikkanz <[email protected]> wrote:
> I suspect that a significant reason for the speed increase is that the verb
> ranks of * and + are 0.
> * b. 0
> + b. 0
>
> This means that %@+ for example will calculate % for each item of the right
> argument, whereas if you use %@:+ then % will wait until all the items have
> been processed and then calculate % on the whole array.
>
> In general J performs better if you give it whole arrays to work on at
> once, rather than forcing it to operate on the individual items in an
> array.
>
>
> Perhaps this will help to visualise the difference:
>     7 9 4 <@* 2 9 5
>
> ┌──┬──┬──┐
>
> │14│81│20│
>
> └──┴──┴──┘
>
>    7 9 4 <@:* 2 9 5
>
> ┌────────┐
>
> │14 81 20│
>
> └────────┘
>
> If the verb rank of v is infinite, then is no difference in the processing
> of u@v and u@:v so for example:
>     ([ * ]) b. 0   NB. user-defined verbs (in this case a fork) have
> infinite rank
> _ _ _
>
>
>     7 9 4 <@([ * ]) 2 9 5
>
> ┌────────┐
>
> │14 81 20│
>
> └────────┘
>
>    7 9 4 <@:([ * ]) 2 9 5
>
> ┌────────┐
>
> │14 81 20│
>
> └────────┘
>
> HTH
> Ric
>
>
> On Mon, Feb 16, 2015 at 10:08 AM, Robert Clausecker <[email protected]>
> wrote:
>
>>
>> Hello!
>>
>> To see how J compares to other languages out there, I tried to implement
>> the spectral-norm [1] language benchmark in J. Part of my code [2] for
>> this looks like this:
>>
>>     NB. entry at x,y of infinite matrix A
>>     A =: >:@:[ %@:+ -:@:(* >:)@:+
>>     NB. get the first y by y elements of A
>>     subA =: A"0 _~&i. M.
>>
>> subA 5500 is called in the benchmark. In the beginning, my definition
>> for A looked like this:
>>
>>     A =: >:@[ %@+ + -:@* >:@+
>>
>> and was about five times slower than the definition above, even though
>> it computes the same values. Why is that the case?
>>
>> Yours,
>> Robert Clausecker
>>
>> [1]:
>>
>> http://benchmarksgame.alioth.debian.org/u32/performance.php?test=spectralnorm
>>
>> [2]:
>>
>> https://gist.github.com/fuzxxl/ea936084dd5038cc4c06/c0db428c351af069332d456a2c5368c5fecb8d11
>>
>>
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to