Matrix multiplication: Difference between revisions

→‎{{header|Tailspin}}: syntax update and clearer algorithm
(Revise to be more idiomatic and not use local)
(→‎{{header|Tailspin}}: syntax update and clearer algorithm)
Line 4,446:
=={{header|Tailspin}}==
<lang tailspin>
templates matmul@&{B:}
$ -> \[i](def rA: $;
$A -> \[i](
[1..$B(1)::length -> \(def j: $; @: 0;
$B(1..$r::length) -> \[j](@: $@ + $r($) * $B($;$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;';|
Line 4,469 ⟶ 4,470:
'a:
' -> !OUT::write
$a -> printMatrix@&{w:2} -> !OUT::write
 
def b: [[0, 1], [2, 3], [4, 5]];
Line 4,475 ⟶ 4,476:
b:
' -> !OUT::write
$b -> printMatrix@&{w:2} -> !OUT::write
'
axb:
' -> !OUT::write
$a -> matmul@&{B: $b} -> printMatrix@&{w:2} -> !OUT::write
</lang>
{{out}}
Anonymous user