Permalink
Browse files

[Matrix] LeftMultiply with vector is exactly the same as TransposeThi…

…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...
1 parent ba4ddfb commit 48037d122a4db2687de5d8801a4fb7af96473df7 @alexkaratarakis committed with cuda Jun 9, 2011
@@ -380,37 +380,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>
/// <param name="other">The matrix to multiply with.</param>
@@ -208,25 +208,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>
/// <param name="other">The matrix to multiply with.</param>
@@ -380,37 +380,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>
/// <param name="other">The matrix to multiply with.</param>
@@ -218,25 +218,6 @@ protected override void DoDivide(Complex32 scalar, Matrix<Complex32> 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>
/// <param name="other">The matrix to multiply with.</param>
@@ -421,37 +421,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>
/// <param name="other">The matrix to multiply with.</param>
@@ -208,25 +208,6 @@ protected override void DoDivide(double scalar, Matrix<double> 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>
/// <param name="other">The matrix to multiply with.</param>
@@ -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.
@@ -420,37 +420,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>
/// <param name="other">The matrix to multiply with.</param>
@@ -198,25 +198,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>
/// <param name="other">The matrix to multiply with.</param>

0 comments on commit 48037d1

Please sign in to comment.