Matrix multiplication: Difference between revisions
Content deleted Content added
Nimrod -> Nim |
Updated D versios 2 and 4 |
||
Line 996: | Line 996: | ||
<lang d>import std.stdio, std.range, std.array, std.numeric, std.algorithm; |
<lang d>import std.stdio, std.range, std.array, std.numeric, std.algorithm; |
||
T[][] matMul(T)(in T[][] A, in T[][] B) /* |
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; |
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; |
return A.map!(a => Bt.map!(b => a.dotProduct(b)).array).array; |
||
Line 1,042: | Line 1,042: | ||
void matrixMul(T, T2, size_t k, size_t m, size_t n) |
void matrixMul(T, T2, size_t k, size_t m, size_t n) |
||
(in ref T[m][k] A, in ref T[n][m] B, |
(in ref T[m][k] A, in ref T[n][m] B, |
||
/*out*/ ref T2[n][k] result) pure nothrow |
/*out*/ ref T2[n][k] result) pure nothrow /*@safe*/ @nogc |
||
if (is(T2 == Unqual!T)) { |
if (is(T2 == Unqual!T)) { |
||
static if (hasIndirections!T) |
|||
T2[m] aux; |
T2[m] aux; |
||
else |
|||
T2[m] aux = void; |
|||
foreach (immutable j; 0 .. n) { |
foreach (immutable j; 0 .. n) { |
||
foreach (immutable i, const ref bi; B) |
foreach (immutable i, const ref bi; B) |