LU decomposition: Difference between revisions

Content added Content deleted
m (Fixed a small error in the pivotize code: initially would keep a zero on the main diagonal in favor of a negative number (I am not very familiar with D syntax but I believe this was done correctly))
(Updated D entry)
Line 684: Line 684:
{{trans|Common Lisp}}
{{trans|Common Lisp}}
<lang d>import std.stdio, std.algorithm, std.typecons, std.numeric,
<lang d>import std.stdio, std.algorithm, std.typecons, std.numeric,
std.array, std.conv, std.string, std.range, std.math;
std.array, std.conv, std.string, std.range;


bool isRectangular(T)(in T[][] m) pure nothrow {
bool isRectangular(T)(in T[][] m) pure nothrow {
Line 724: Line 724:
foreach (immutable i; 0 .. n) {
foreach (immutable i; 0 .. n) {
// immutable row = iota(i, n).reduce!(max!(j => m[j][i]));
// immutable row = iota(i, n).reduce!(max!(j => m[j][i]));
T maxm = abs(m[i][i]);
T maxm = m[i][i];
size_t row = i;
size_t row = i;
foreach (immutable j; i .. n)
foreach (immutable j; i .. n)
if (abs(m[j][i]) > maxm) {
if (m[j][i] > maxm) {
maxm = m[j][i];
maxm = m[j][i];
row = j;
row = j;
Line 784: Line 784:
[2.0, 5, 7, 1]];
[2.0, 5, 7, 1]];


//auto f = "[%([%(%.1f, %)],\n %)]]\n\n".replicate(3);
auto f = "[%([%(%.1f, %)],\n %)]]\n\n".replicate(3);
auto f = std.array.replicate("[%([%(%.1f, %)],\n %)]]\n\n", 3);
foreach (m; [a, b])
foreach (m; [a, b])
writefln(f, lu(m).tupleof);
writefln(f, lu(m).tupleof);