From 548de3010015516071bfd143f05a81d017038cd5 Mon Sep 17 00:00:00 2001 From: Robert Altner Date: Thu, 24 Jan 2019 04:26:57 +0100 Subject: [PATCH] Added some more functions for convenience --- Matrix/Matrix.hpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/Matrix/Matrix.hpp b/Matrix/Matrix.hpp index 02fbd59..bebdad5 100644 --- a/Matrix/Matrix.hpp +++ b/Matrix/Matrix.hpp @@ -50,6 +50,8 @@ public: void Transpose(); void Invert(); + friend Matrix Transpose(const Matrix& mat); + friend Matrix Invert(const Matrix& mat); void MultiplyRow(uint row, double factor); void SwapRows(uint left, uint right); void AddMultiplesToRow(uint base, uint target, double factor); @@ -87,7 +89,7 @@ private: bool DimensionsFitting(const Matrix& left, const Matrix& right); void Resize(uint rows, uint cols, doubleMatrix& matrix); - + Matrix _transpose(const Matrix& mat); }; @@ -269,6 +271,25 @@ inline void Matrix::Transpose() } +//////////////////////////////////////////////////// +/// \brief Transposes the matrix (friend function) +/// +//////////////////////////////////////////////////// +inline Matrix Transpose(const Matrix& mat) +{ + Matrix transposed = mat; + transposed.Transpose(); + return transposed; +} + +Matrix Matrix::_transpose(const Matrix& mat) +{ + Matrix transposed = mat; + transposed.Transpose(); + return transposed; +} + + //////////////////////////////////////////////////// /// \brief Inverts the matrix /// @@ -291,6 +312,18 @@ inline void Matrix::Invert() } +//////////////////////////////////////////////////// +/// \brief Invertss the matrix (friend function) +/// +//////////////////////////////////////////////////// +inline Matrix Invert(const Matrix& mat) +{ + Matrix inverse = mat; + inverse.Invert(); + return inverse; +} + + //////////////////////////////////////////////////// /// \brief Multiplies each value of a given row by a given factor