Anonymous user
LU decomposition: Difference between revisions
Improved D code
(Updated D code) |
(Improved D code) |
||
Line 589:
std.array, std.conv;
bool isRectangular(T)(in T[][]
//return !canFind!((r){ return r.length !=
foreach (row;
if (row.length !=
return false;
return true;
}
return
}
string prettyPrint(T)(in T[][] m) {
return "[" ~ array(map!text(m)).join(",\n ") ~ "]";
}
Line 622 ⟶ 626:
in {
assert(n >= 0);
} out(result) {
assert(isSquare(result));
} body {
auto m = new typeof(return)(n, n);
Line 634 ⟶ 640:
T[][] pivotize(T)(in T[][] m) pure nothrow
in {
} body {
immutable
auto P = identityMatrix!T(n);
foreach (i; 0 .. n) {
T max = m[i][i];
foreach (j; i .. n)
if (m[j][i] > max) {
Line 659 ⟶ 664:
lu(T)(in T[][] A) pure nothrow
in {
} body {
immutable
auto L = new T[][](n, n);
auto U = new T[][](n, n);
Line 669 ⟶ 673:
U[i][0 .. i] = 0;
}
const auto P = pivotize!T(A);▼
foreach (j; 0 .. n) {
|