Skip to content

Commit

Permalink
[Matrix] LeftMultiply with vector is exactly the same as TransposeThi…
Browse files Browse the repository at this point in the history
…sAndMultiplty() 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>
  • Loading branch information
alexkaratarakis authored and cuda committed Jun 10, 2011
1 parent ba4ddfb commit 48037d1
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 201 deletions.
31 changes: 0 additions & 31 deletions src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs
Expand Up @@ -379,37 +379,6 @@ protected override void DoMultiply(Vector<Complex> rightSide, Vector<Complex> re
}
}

/// <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>
Expand Down
19 changes: 0 additions & 19 deletions src/Numerics/LinearAlgebra/Complex/Matrix.cs
Expand Up @@ -207,25 +207,6 @@ protected override void DoMultiply(Vector<Complex> rightSide, Vector<Complex> re
}
}

/// <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>
Expand Down
31 changes: 0 additions & 31 deletions src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs
Expand Up @@ -379,37 +379,6 @@ protected override void DoMultiply(Vector<Complex32> rightSide, Vector<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>
Expand Down
19 changes: 0 additions & 19 deletions src/Numerics/LinearAlgebra/Complex32/Matrix.cs
Expand Up @@ -217,25 +217,6 @@ protected override void DoDivide(Complex32 scalar, Matrix<Complex32> result)
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>
Expand Down
31 changes: 0 additions & 31 deletions src/Numerics/LinearAlgebra/Double/DenseMatrix.cs
Expand Up @@ -420,37 +420,6 @@ protected override void DoMultiply(Vector<double> rightSide, Vector<double> resu
}
}

/// <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>
Expand Down
19 changes: 0 additions & 19 deletions src/Numerics/LinearAlgebra/Double/Matrix.cs
Expand Up @@ -207,25 +207,6 @@ protected override void DoDivide(double scalar, Matrix<double> result)
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>
Expand Down
5 changes: 4 additions & 1 deletion src/Numerics/LinearAlgebra/Generic/Matrix.Arithmetic.cs
Expand Up @@ -420,7 +420,10 @@ public virtual void LeftMultiply(Vector<T> leftSide, Vector<T> result)
/// </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.
Expand Down
31 changes: 0 additions & 31 deletions src/Numerics/LinearAlgebra/Single/DenseMatrix.cs
Expand Up @@ -419,37 +419,6 @@ protected override void DoMultiply(Vector<float> rightSide, Vector<float> 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<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>
Expand Down
19 changes: 0 additions & 19 deletions src/Numerics/LinearAlgebra/Single/Matrix.cs
Expand Up @@ -197,25 +197,6 @@ protected override void DoMultiply(Vector<float> rightSide, Vector<float> 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<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>
Expand Down

0 comments on commit 48037d1

Please sign in to comment.