From fb1e19889b85112eca096d7ec55b318859cea333 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 9 Nov 2017 12:07:20 +0200 Subject: [PATCH] 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. --- source/linal/matrixops.h | 4 ++-- source/linal/squarematrix.h | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) 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 -- 2.43.0