I had a chance to digest the K-way of lists of a list method Raul presented in 
J. 

After I understood it somewhat and its use of the leaf operator. I was curious 
as 
how fast these things ran, as implied by Raghu and Raul it was fairly slow 
compared to
the J matrix implementation proposed by Raul.

   kmat1 =: <"1]1+i.400 300
   kmat2 =: <"1]1+i.300 400
   10 timex '+/@:>L:1 kmat1 *&.> L:0 1 kmat2'
0.434604

   bmat1 =: (1+i. 400 300)
   bmat2 =: (1+i. 300 400)

   10 timex 'bmat1 +/@:*"1 _ bmat2'
0.0477105
   10 timex 'bmat1 +/ . * bmat2'
0.0053597

 I always forget that combinations of operators using ‘atop' or ‘at’ can also 
be expressed
as forks. So being lazy and trying not to think to hard. I updated my original 
function but this
time using the rank modifiers from Raul’s solution (this gets rid of the need 
for transpose operator). 
I used the 13 : definition and found the fork implementation. Then I realized 
this was just 
Raul’s solution written as a fork:

   matmul3 =: 13 : '+/ x *"1 _ y'
   matmul3
[: +/ *"1 _

Now the wierd thing is the timing for matmul3 is slow on par with emulating K 
matrices in J

    10 timex 'bmat1 matmul3 bmat2’
0.324845

But if I use the fork directly it is as fast as Raul’s solution

    10 timex 'bmat1 ([: +/ *)"1 _ bmat2’
0.0459252

I suppose there is a hit for looking up the name and parsing its definition 
each iteration of timex?

Thanks for all your replies. This little exercise deepened my understanding of 
Rank and what I may 
accomplish when operating on multidimensional arrays. I learned about the ‘L:’ 
function as well. 

Tom McGuire

> On Jul 13, 2022, at 4:47 AM, Raul Miller <[email protected]> wrote:
. . .

> Oh... yes... K is highly optimized for nested rank 1 lists of rank 1
> lists -- J... not so much. J's rank winds up being mostly unnecessary
> overhead when emulating K's data structures.
> 
> Still, if you wanted to represent matrices that way, here would be a
> way of implementing matrix multiplication on nested lists in J (not
> the part in parenthesis -- that could use some more work to approach
> "k-like notation" -- but that's just the starting matrices):
> 
>   +/@:>L:1 (<"1]1+i.4 3) *&.> L:0 1 (<"1]1+i.3 4)
> +-----------+-------------+---------------+---------------+
> |38 44 50 56|83 98 113 128|128 152 176 200|173 206 239 272|
> +-----------+-------------+---------------+———————+
. . .

> Thanks,
> 
> --
> Raul
> ----------------------------------------------------------------------
> 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