Anonymous user
Matrix multiplication: Difference between revisions
Updated both D entries
(Updated D entry) |
(Updated both D entries) |
||
Line 855:
}
return result;
}
Line 865 ⟶ 861:
immutable b = [[-3, -8, 3,], [-2, 1, 4]];
writefln("A * B = \n" ~ form, matrixMul(a, b));
}</lang>
{{out}}
<pre>A =
[[1, 2],
Line 883 ⟶ 880:
[-17, -20, 25],
[-21, -18, 33]]</pre>
===Stronger Statically Typed Version===
All array sizes are verified at compile-time (and no matrix is copied)
<lang d>import std.stdio, std.string, std.conv, std.numeric,
std.array, std.algorithm, std.traits;
Line 903 ⟶ 900:
result[i][j] = dotProduct(ai, aux);
}
}
void main() {
writefln("B = \n" ~ form ~ "\n", b);
TMMul!(typeof(a), typeof(b)) result
matrixMul(a, b, result);
}</lang>
|