From: Mikko Rasa Date: Thu, 9 Nov 2017 10:07:20 +0000 (+0200) Subject: Rename the low-level matrix inversion function to gauss_jordan X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=fb1e198;p=libs%2Fmath.git Rename the low-level matrix inversion function to gauss_jordan Since that's the name of the algorithm being used. Also remove an unnecessary assignment from the non-mutating case. --- diff --git a/source/linal/matrixops.h b/source/linal/matrixops.h index 5bf9f43..84c8012 100644 --- a/source/linal/matrixops.h +++ b/source/linal/matrixops.h @@ -17,7 +17,7 @@ public: template -inline T &invert_matrix(T &m, T &r) +inline T &gauss_jordan(T &m, T &r) { typedef typename T::ElementType V; using std::abs; @@ -54,7 +54,7 @@ inline T &invert_matrix(T &m, T &r) for(unsigned j=i; j-->0; ) r.add_row(i, j, -m.element(j, i)); - return m = r; + return r; } } // namespace LinAl diff --git a/source/linal/squarematrix.h b/source/linal/squarematrix.h index 0a97e61..b8531aa 100644 --- a/source/linal/squarematrix.h +++ b/source/linal/squarematrix.h @@ -47,14 +47,16 @@ template SquareMatrix &SquareMatrix::invert() { SquareMatrix r = identity(); - return invert_matrix(*this, r); + gauss_jordan(*this, r); + return *this = r; } template inline SquareMatrix invert(const SquareMatrix &m) { - SquareMatrix r = m; - return r.invert(); + SquareMatrix temp = m; + SquareMatrix r = SquareMatrix::identity(); + return gauss_jordan(temp, r); } } // namespace LinAl