From 2234560a7aa98bf257866234cf1d9ef2ec426582 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 9 Jun 2011 21:18:12 +0800 Subject: [PATCH] [Matrix] LeftMultiply with vector is exactly the same as TransposeThisAndMultiplty() with vector Change LeftMultiply to a protected method (from protected abstract) and it now calls TransposeThisAndMultiply(). TransposeThisAndMultiply has unit tests so it was chosen as the "main" method. Overrides of LeftMultiply were removed, because now only TransposeThisAndMultiply() needs to be overriden. Signed-off-by: Alexander Karatarakis --- .../LinearAlgebra/Complex/DenseMatrix.cs | 31 ------------------- src/Numerics/LinearAlgebra/Complex/Matrix.cs | 19 ------------ .../LinearAlgebra/Complex32/DenseMatrix.cs | 31 ------------------- .../LinearAlgebra/Complex32/Matrix.cs | 19 ------------ .../LinearAlgebra/Double/DenseMatrix.cs | 31 ------------------- src/Numerics/LinearAlgebra/Double/Matrix.cs | 19 ------------ .../Generic/Matrix.Arithmetic.cs | 5 ++- .../LinearAlgebra/Single/DenseMatrix.cs | 31 ------------------- src/Numerics/LinearAlgebra/Single/Matrix.cs | 19 ------------ 9 files changed, 4 insertions(+), 201 deletions(-) diff --git a/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs index e156a272..f88f614a 100644 --- a/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs +++ b/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs @@ -379,37 +379,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex } } - /// - /// Left multiply a matrix with a vector ( = vector * matrix ) and place the result in the result vector. - /// - /// The vector to multiply with. - /// The result of the multiplication. - protected override void DoLeftMultiply(Vector leftSide, Vector result) - { - var denseLeft = leftSide as DenseVector; - var denseResult = result as DenseVector; - - if (denseLeft == null || denseResult == null) - { - base.DoLeftMultiply(leftSide, result); - } - else - { - Control.LinearAlgebraProvider.MatrixMultiplyWithUpdate( - Algorithms.LinearAlgebra.Transpose.DontTranspose, - Algorithms.LinearAlgebra.Transpose.DontTranspose, - 1.0, - denseLeft.Data, - 1, - denseLeft.Count, - Data, - RowCount, - ColumnCount, - 0.0, - denseResult.Data); - } - } - /// /// Multiplies this matrix with another matrix and places the results into the result matrix. /// diff --git a/src/Numerics/LinearAlgebra/Complex/Matrix.cs b/src/Numerics/LinearAlgebra/Complex/Matrix.cs index 8a72071b..6e6c76f8 100644 --- a/src/Numerics/LinearAlgebra/Complex/Matrix.cs +++ b/src/Numerics/LinearAlgebra/Complex/Matrix.cs @@ -207,25 +207,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex } } - /// - /// Left multiply a matrix with a vector ( = vector * matrix ) and place the result in the result vector. - /// - /// The vector to multiply with. - /// The result of the multiplication. - protected override void DoLeftMultiply(Vector leftSide, Vector result) - { - for (var j = 0; j < ColumnCount; j++) - { - var s = Complex.Zero; - for (var i = 0; i != leftSide.Count; i++) - { - s += leftSide[i] * At(i, j); - } - - result[j] = s; - } - } - /// /// Multiplies this matrix with another matrix and places the results into the result matrix. /// diff --git a/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs index 29b66e5f..b2e16a64 100644 --- a/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs +++ b/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs @@ -379,37 +379,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 } } - /// - /// Left multiply a matrix with a vector ( = vector * matrix ) and place the result in the result vector. - /// - /// The vector to multiply with. - /// The result of the multiplication. - protected override void DoLeftMultiply(Vector leftSide, Vector result) - { - var denseLeft = leftSide as DenseVector; - var denseResult = result as DenseVector; - - if (denseLeft == null || denseResult == null) - { - base.DoLeftMultiply(leftSide, result); - } - else - { - Control.LinearAlgebraProvider.MatrixMultiplyWithUpdate( - Algorithms.LinearAlgebra.Transpose.DontTranspose, - Algorithms.LinearAlgebra.Transpose.DontTranspose, - 1.0f, - denseLeft.Data, - 1, - denseLeft.Count, - Data, - RowCount, - ColumnCount, - 0.0f, - denseResult.Data); - } - } - /// /// Multiplies this matrix with another matrix and places the results into the result matrix. /// diff --git a/src/Numerics/LinearAlgebra/Complex32/Matrix.cs b/src/Numerics/LinearAlgebra/Complex32/Matrix.cs index 650174fa..a3f1944c 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Matrix.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Matrix.cs @@ -217,25 +217,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 DoMultiply(1.0f / scalar, result); } - /// - /// Left multiply a matrix with a vector ( = vector * matrix ) and place the result in the result vector. - /// - /// The vector to multiply with. - /// The result of the multiplication. - protected override void DoLeftMultiply(Vector leftSide, Vector result) - { - for (var j = 0; j < ColumnCount; j++) - { - var s = Complex32.Zero; - for (var i = 0; i != leftSide.Count; i++) - { - s += leftSide[i] * At(i, j); - } - - result[j] = s; - } - } - /// /// Multiplies this matrix with another matrix and places the results into the result matrix. /// diff --git a/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs index 22930321..2f8d6cd0 100644 --- a/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs +++ b/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs @@ -420,37 +420,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double } } - /// - /// Left multiply a matrix with a vector ( = vector * matrix ) and place the result in the result vector. - /// - /// The vector to multiply with. - /// The result of the multiplication. - protected override void DoLeftMultiply(Vector leftSide, Vector result) - { - var denseLeft = leftSide as DenseVector; - var denseResult = result as DenseVector; - - if (denseLeft == null || denseResult == null) - { - base.DoLeftMultiply(leftSide, result); - } - else - { - Control.LinearAlgebraProvider.MatrixMultiplyWithUpdate( - Algorithms.LinearAlgebra.Transpose.DontTranspose, - Algorithms.LinearAlgebra.Transpose.DontTranspose, - 1.0, - denseLeft.Data, - 1, - denseLeft.Count, - Data, - RowCount, - ColumnCount, - 0.0, - denseResult.Data); - } - } - /// /// Multiplies this matrix with another matrix and places the results into the result matrix. /// diff --git a/src/Numerics/LinearAlgebra/Double/Matrix.cs b/src/Numerics/LinearAlgebra/Double/Matrix.cs index bf46f7f3..811d1ab1 100644 --- a/src/Numerics/LinearAlgebra/Double/Matrix.cs +++ b/src/Numerics/LinearAlgebra/Double/Matrix.cs @@ -207,25 +207,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double DoMultiply(1.0 / scalar, result); } - /// - /// Left multiply a matrix with a vector ( = vector * matrix ) and place the result in the result vector. - /// - /// The vector to multiply with. - /// The result of the multiplication. - protected override void DoLeftMultiply(Vector leftSide, Vector result) - { - for (var j = 0; j < ColumnCount; j++) - { - var s = 0.0; - for (var i = 0; i != leftSide.Count; i++) - { - s += leftSide[i] * At(i, j); - } - - result[j] = s; - } - } - /// /// Multiplies this matrix with another matrix and places the results into the result matrix. /// diff --git a/src/Numerics/LinearAlgebra/Generic/Matrix.Arithmetic.cs b/src/Numerics/LinearAlgebra/Generic/Matrix.Arithmetic.cs index faa68ea2..69899694 100644 --- a/src/Numerics/LinearAlgebra/Generic/Matrix.Arithmetic.cs +++ b/src/Numerics/LinearAlgebra/Generic/Matrix.Arithmetic.cs @@ -420,7 +420,10 @@ namespace MathNet.Numerics.LinearAlgebra.Generic /// /// The vector to multiply with. /// The result of the multiplication. - protected abstract void DoLeftMultiply(Vector leftSide, Vector result); + protected void DoLeftMultiply(Vector leftSide, Vector result) + { + DoTransposeThisAndMultiply(leftSide, result); + } /// /// Multiplies this matrix with another matrix and places the results into the result matrix. diff --git a/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs index 3fe1d392..663b1033 100644 --- a/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs +++ b/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs @@ -419,37 +419,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single } } - /// - /// Left multiply a matrix with a vector ( = vector * matrix ) and place the result in the result vector. - /// - /// The vector to multiply with. - /// The result of the multiplication. - protected override void DoLeftMultiply(Vector leftSide, Vector result) - { - var denseLeft = leftSide as DenseVector; - var denseResult = result as DenseVector; - - if (denseLeft == null || denseResult == null) - { - base.DoLeftMultiply(leftSide, result); - } - else - { - Control.LinearAlgebraProvider.MatrixMultiplyWithUpdate( - Algorithms.LinearAlgebra.Transpose.DontTranspose, - Algorithms.LinearAlgebra.Transpose.DontTranspose, - 1.0f, - denseLeft.Data, - 1, - denseLeft.Count, - Data, - RowCount, - ColumnCount, - 0.0f, - denseResult.Data); - } - } - /// /// Multiplies this matrix with another matrix and places the results into the result matrix. /// diff --git a/src/Numerics/LinearAlgebra/Single/Matrix.cs b/src/Numerics/LinearAlgebra/Single/Matrix.cs index 685fe010..144b3c73 100644 --- a/src/Numerics/LinearAlgebra/Single/Matrix.cs +++ b/src/Numerics/LinearAlgebra/Single/Matrix.cs @@ -197,25 +197,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single } } - /// - /// Left multiply a matrix with a vector ( = vector * matrix ) and place the result in the result vector. - /// - /// The vector to multiply with. - /// The result of the multiplication. - protected override void DoLeftMultiply(Vector leftSide, Vector result) - { - for (var j = 0; j < ColumnCount; j++) - { - var s = 0.0f; - for (var i = 0; i != leftSide.Count; i++) - { - s += leftSide[i] * At(i, j); - } - - result[j] = s; - } - } - /// /// Multiplies this matrix with another matrix and places the results into the result matrix. ///