LU decomposition: Difference between revisions

Updated D entry
m (Fortran 90 rather than FORTRAN 77 highlighting)
(Updated D entry)
Line 686:
std.array, std.conv, std.string, std.range;
 
bool isRectangular(T)(in T[][] m) /*pure nothrow*/ {
return m.all!(r => r.length == m[0].length);
}
 
bool isSquare(T)(in T[][] m) /*pure nothrow*/ {
return isRectangular(m).isRectangular && m[0].length == m.length;
}
 
T[][] matrixMul(T)(in T[][] A, in T[][] B) /*pure nothrow*/
in {
assert(A.isRectangular && B.isRectangular &&
Line 715:
T[][] pivotize(T)(immutable T[][] m) /*pure nothrow*/
in {
assert(isSquare(m).isSquare);
} body {
immutable n = m.length;
Line 723:
 
foreach (immutable i; 0 .. n) {
// immutable row = iota(i, n).reduce!(max!(j => m[j][i])();
T maxm = m[i][i];
size_t row = i;
Line 743:
lu(T)(immutable T[][] A) /*pure nothrow*/
in {
assert(isSquare(A).isSquare);
} body {
immutable n = A.length;
Line 753:
}
 
const P = A.pivotize!T(A);
const A2 = matrixMul!T(P, A);
 
Line 784:
[2.0, 5, 7, 1]];
 
//auto f = "[%([%(%.1f, %)],\n %)]]\n\n".replicate(3);
auto f = std.array.replicate("[%([%(%.1f, %)],\n %)]]\n\n", 3);
foreach (m; [a, b])