Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
16
Task/Matrix-multiplication/D/matrix-multiplication-2.d
Normal file
16
Task/Matrix-multiplication/D/matrix-multiplication-2.d
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import std.stdio, std.range, std.array, std.numeric, std.algorithm;
|
||||
|
||||
T[][] matMul(T)(in T[][] A, in T[][] B) pure nothrow /*@safe*/ {
|
||||
const Bt = B[0].length.iota.map!(i=> B.transversal(i).array).array;
|
||||
return A.map!(a => Bt.map!(b => a.dotProduct(b)).array).array;
|
||||
}
|
||||
|
||||
void main() {
|
||||
immutable a = [[1, 2], [3, 4], [3, 6]];
|
||||
immutable b = [[-3, -8, 3,], [-2, 1, 4]];
|
||||
|
||||
immutable form = "[%([%(%d, %)],\n %)]]";
|
||||
writefln("A = \n" ~ form ~ "\n", a);
|
||||
writefln("B = \n" ~ form ~ "\n", b);
|
||||
writefln("A * B = \n" ~ form, matMul(a, b));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue