Hi, I wrote the original essay. The ngn/k version is much better for the K array model, and it's intended as a nice and short description of the algorithm for nested lists. Your translation looks correct, and you might get a one-to-one translation with boxed arrays and table. J doesn't really encourage boxed arrays, so I think Raul's version makes the most sense here.
Raghu R On Wed, Jul 13, 2022 at 9:38 AM Henry Rich <henryhr...@gmail.com> wrote: > I have to question the use of 'elegant' here. > > Matrix multiplication has a similarly short representation in J. But the > actual code: it breaks the operation into several layers of loops: one > sized to the registers, one sized to D1$, one sized to D2$. > > Simply following the definition of the operation is very slow. J is a > description of what you want done, not necessarily how to do it. > > Henry Rich > > On 7/12/2022 11:09 PM, Thomas McGuire wrote: > > Devon had shared a kx example of performing matrix multiplication > backing out the loops from a wikipedia pseudocode. Providing an elegant > solution in K. > > > > You can see it in the NYCJUG notes here: > https://code.jsoftware.com/wiki/NYCJUG/2022-07-12 < > https://code.jsoftware.com/wiki/NYCJUG/2022-07-12> > > > > The Kx solution is as follows: > > > > matmul: {x{+/x*y}/:\:+y} > > > > The each right (/:) and each left operators (\:) in sequence appear to > perform in a similar way to Jās table operator ā/ā. > > > > After some messing around with rank I came up with the following J > equivalent: > > > > matmul =: {{x {{+/x*y}}ā1 1/ |:y}} > > > > (1+i. 4 3) matmul 1+i. 3 4 > > 38 44 50 56 > > 83 98 113 128 > > 128 152 176 200 > > 173 206 239 272 > > (1+i. 4 3) +/ . * 1+i. 3 4 > > 38 44 50 56 > > 83 98 113 128 > > 128 152 176 200 > > 173 206 239 272 > > > > By transposing the y operand I deliver columns of y to rows of x which > gets operated on by the inner anonymous dfns. Wondering if there is a more > elegant way that does not play around with rank? > > > > Tom McGuire > > ---------------------------------------------------------------------- > > For information about J forums see http://www.jsoftware.com/forums.htm > > > -- > This email has been checked for viruses by AVG. > https://www.avg.com > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm