From cfe636c11b92e069a341dcecb21e34b8a4e5dc98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Wed, 15 May 2013 01:10:18 +0000 Subject: [PATCH] Replaced an uggly for by a bit less uggly while for the matrix inversion. --- src/ndim/nmat.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/ndim/nmat.rs b/src/ndim/nmat.rs index e399e0d3..5589e639 100644 --- a/src/ndim/nmat.rs +++ b/src/ndim/nmat.rs @@ -107,23 +107,30 @@ Inv for NMat // FIXME: this is kind of uggly… // … but we cannot use position_betwee since we are iterating on one // columns - let mut n0 = dim; // index of a non-zero entry + let mut n0 = 0u; // index of a non-zero entry - for uint::range(k, dim) |i| + while (n0 != dim) { - n0 = k; - - if (cpy[(i, k)] != _0T) + if (cpy[(n0, k)] != _0T) { break; } + + n0 += 1; } assert!(n0 != dim); // non inversible matrix // swap pivot line - for uint::range(0u, dim) |j| + if (n0 != k) { - swap(cpy.mij, NMat::offset::(n0, j), NMat::offset::(k, j)); - swap(res.mij, NMat::offset::(n0, j), NMat::offset::(k, j)); + for uint::range(0u, dim) |j| + { + swap(cpy.mij, + NMat::offset::(n0, j), + NMat::offset::(k, j)); + swap(res.mij, + NMat::offset::(n0, j), + NMat::offset::(k, j)); + } } let pivot = cpy[(k, k)];