Browse Source

[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 <alex@karatarakis.com>
la-knuth
Alexander Karatarakis 16 years ago
committed by Marcus Cuda
parent
commit
2234560a7a
  1. 31
      src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs
  2. 19
      src/Numerics/LinearAlgebra/Complex/Matrix.cs
  3. 31
      src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs
  4. 19
      src/Numerics/LinearAlgebra/Complex32/Matrix.cs
  5. 31
      src/Numerics/LinearAlgebra/Double/DenseMatrix.cs
  6. 19
      src/Numerics/LinearAlgebra/Double/Matrix.cs
  7. 5
      src/Numerics/LinearAlgebra/Generic/Matrix.Arithmetic.cs
  8. 31
      src/Numerics/LinearAlgebra/Single/DenseMatrix.cs
  9. 19
      src/Numerics/LinearAlgebra/Single/Matrix.cs

31
src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs

@ -379,37 +379,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
}
/// <summary>
/// Left multiply a matrix with a vector ( = vector * matrix ) and place the result in the result vector.
/// </summary>
/// <param name="leftSide">The vector to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected override void DoLeftMultiply(Vector<Complex> leftSide, Vector<Complex> 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);
}
}
/// <summary>
/// Multiplies this matrix with another matrix and places the results into the result matrix.
/// </summary>

19
src/Numerics/LinearAlgebra/Complex/Matrix.cs

@ -207,25 +207,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
}
/// <summary>
/// Left multiply a matrix with a vector ( = vector * matrix ) and place the result in the result vector.
/// </summary>
/// <param name="leftSide">The vector to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected override void DoLeftMultiply(Vector<Complex> leftSide, Vector<Complex> 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;
}
}
/// <summary>
/// Multiplies this matrix with another matrix and places the results into the result matrix.
/// </summary>

31
src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs

@ -379,37 +379,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
}
/// <summary>
/// Left multiply a matrix with a vector ( = vector * matrix ) and place the result in the result vector.
/// </summary>
/// <param name="leftSide">The vector to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected override void DoLeftMultiply(Vector<Complex32> leftSide, Vector<Complex32> 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);
}
}
/// <summary>
/// Multiplies this matrix with another matrix and places the results into the result matrix.
/// </summary>

19
src/Numerics/LinearAlgebra/Complex32/Matrix.cs

@ -217,25 +217,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
DoMultiply(1.0f / scalar, result);
}
/// <summary>
/// Left multiply a matrix with a vector ( = vector * matrix ) and place the result in the result vector.
/// </summary>
/// <param name="leftSide">The vector to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected override void DoLeftMultiply(Vector<Complex32> leftSide, Vector<Complex32> 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;
}
}
/// <summary>
/// Multiplies this matrix with another matrix and places the results into the result matrix.
/// </summary>

31
src/Numerics/LinearAlgebra/Double/DenseMatrix.cs

@ -420,37 +420,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
}
/// <summary>
/// Left multiply a matrix with a vector ( = vector * matrix ) and place the result in the result vector.
/// </summary>
/// <param name="leftSide">The vector to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected override void DoLeftMultiply(Vector<double> leftSide, Vector<double> 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);
}
}
/// <summary>
/// Multiplies this matrix with another matrix and places the results into the result matrix.
/// </summary>

19
src/Numerics/LinearAlgebra/Double/Matrix.cs

@ -207,25 +207,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
DoMultiply(1.0 / scalar, result);
}
/// <summary>
/// Left multiply a matrix with a vector ( = vector * matrix ) and place the result in the result vector.
/// </summary>
/// <param name="leftSide">The vector to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected override void DoLeftMultiply(Vector<double> leftSide, Vector<double> 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;
}
}
/// <summary>
/// Multiplies this matrix with another matrix and places the results into the result matrix.
/// </summary>

5
src/Numerics/LinearAlgebra/Generic/Matrix.Arithmetic.cs

@ -420,7 +420,10 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// </summary>
/// <param name="leftSide">The vector to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected abstract void DoLeftMultiply(Vector<T> leftSide, Vector<T> result);
protected void DoLeftMultiply(Vector<T> leftSide, Vector<T> result)
{
DoTransposeThisAndMultiply(leftSide, result);
}
/// <summary>
/// Multiplies this matrix with another matrix and places the results into the result matrix.

31
src/Numerics/LinearAlgebra/Single/DenseMatrix.cs

@ -419,37 +419,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
}
/// <summary>
/// Left multiply a matrix with a vector ( = vector * matrix ) and place the result in the result vector.
/// </summary>
/// <param name="leftSide">The vector to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected override void DoLeftMultiply(Vector<float> leftSide, Vector<float> 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);
}
}
/// <summary>
/// Multiplies this matrix with another matrix and places the results into the result matrix.
/// </summary>

19
src/Numerics/LinearAlgebra/Single/Matrix.cs

@ -197,25 +197,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
}
/// <summary>
/// Left multiply a matrix with a vector ( = vector * matrix ) and place the result in the result vector.
/// </summary>
/// <param name="leftSide">The vector to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected override void DoLeftMultiply(Vector<float> leftSide, Vector<float> 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;
}
}
/// <summary>
/// Multiplies this matrix with another matrix and places the results into the result matrix.
/// </summary>

Loading…
Cancel
Save