34 lines
717 B
Text
34 lines
717 B
Text
operator (A matmul B)
|
|
$A -> \[i](
|
|
$B(1) -> \[j](@: 0;
|
|
1..$B::length -> @: $@ + $A($i;$) * $B($;$j);
|
|
$@ !\) !
|
|
\) !
|
|
end matmul
|
|
|
|
templates printMatrix&{w:}
|
|
templates formatN
|
|
@: [];
|
|
$ -> #
|
|
'$@ -> $::length~..$w -> ' ';$@(last..1:-1)...;' !
|
|
when <1..> do ..|@: $ mod 10; $ ~/ 10 -> #
|
|
when <=0?($@ <[](0)>)> do ..|@: 0;
|
|
end formatN
|
|
$... -> '|$(1) -> formatN;$(2..last)... -> ', $ -> formatN;';|
|
|
' !
|
|
end printMatrix
|
|
|
|
def a: [[1, 2, 3], [4, 5, 6]];
|
|
'a:
|
|
' -> !OUT::write
|
|
$a -> printMatrix&{w:2} -> !OUT::write
|
|
|
|
def b: [[0, 1], [2, 3], [4, 5]];
|
|
'
|
|
b:
|
|
' -> !OUT::write
|
|
$b -> printMatrix&{w:2} -> !OUT::write
|
|
'
|
|
axb:
|
|
' -> !OUT::write
|
|
($a matmul $b) -> printMatrix&{w:2} -> !OUT::write
|