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)];