diff --git a/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs index e3f45005..8e20573a 100644 --- a/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs +++ b/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs @@ -608,17 +608,13 @@ namespace MathNet.Numerics.LinearAlgebra.Complex } else { - Control.LinearAlgebraProvider.MatrixMultiplyWithUpdate( - Providers.LinearAlgebra.Transpose.DontTranspose, - Providers.LinearAlgebra.Transpose.DontTranspose, - 1.0, + Control.LinearAlgebraProvider.MatrixMultiply( _values, _rowCount, _columnCount, denseRight.Values, denseRight.Count, 1, - 0.0, denseResult.Values); } } @@ -634,17 +630,13 @@ namespace MathNet.Numerics.LinearAlgebra.Complex var denseResult = result as DenseMatrix; if (denseOther != null && denseResult != null) { - Control.LinearAlgebraProvider.MatrixMultiplyWithUpdate( - Providers.LinearAlgebra.Transpose.DontTranspose, - Providers.LinearAlgebra.Transpose.DontTranspose, - 1.0, + Control.LinearAlgebraProvider.MatrixMultiply( _values, _rowCount, _columnCount, denseOther._values, denseOther._rowCount, denseOther._columnCount, - 0.0, denseResult._values); return; } diff --git a/src/Numerics/LinearAlgebra/Complex/Matrix.cs b/src/Numerics/LinearAlgebra/Complex/Matrix.cs index 24fa7b08..8a8594ea 100644 --- a/src/Numerics/LinearAlgebra/Complex/Matrix.cs +++ b/src/Numerics/LinearAlgebra/Complex/Matrix.cs @@ -371,16 +371,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex /// The result of the multiplication. protected override void DoMultiply(Matrix other, Matrix result) { - for (var j = 0; j < RowCount; j++) + for (var i = 0; i < RowCount; i++) { - for (var i = 0; i != other.ColumnCount; i++) + for (var j = 0; j != other.ColumnCount; j++) { var s = Complex.Zero; - for (var l = 0; l < ColumnCount; l++) + for (var k = 0; k < ColumnCount; k++) { - s += At(j, l)*other.At(l, i); + s += At(i, k)*other.At(k, j); } - result.At(j, i, s); + result.At(i, j, s); } } } @@ -423,9 +423,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex for (var i = 0; i < RowCount; i++) { var s = Complex.Zero; - for (var l = 0; l < ColumnCount; l++) + for (var k = 0; k < ColumnCount; k++) { - s += At(i, l)*other.At(j, l); + s += At(i, k)*other.At(j, k); } result.At(i, j, s); } @@ -444,9 +444,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex for (var i = 0; i < RowCount; i++) { var s = Complex.Zero; - for (var l = 0; l < ColumnCount; l++) + for (var k = 0; k < ColumnCount; k++) { - s += At(i, l)*other.At(j, l).Conjugate(); + s += At(i, k)*other.At(j, k).Conjugate(); } result.At(i, j, s); } @@ -465,9 +465,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex for (var i = 0; i < ColumnCount; i++) { var s = Complex.Zero; - for (var l = 0; l < RowCount; l++) + for (var k = 0; k < RowCount; k++) { - s += At(l, i)*other.At(l, j); + s += At(k, i)*other.At(k, j); } result.At(i, j, s); } @@ -486,9 +486,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex for (var i = 0; i < ColumnCount; i++) { var s = Complex.Zero; - for (var l = 0; l < RowCount; l++) + for (var k = 0; k < RowCount; k++) { - s += At(l, i).Conjugate()*other.At(l, j); + s += At(k, i).Conjugate()*other.At(k, j); } result.At(i, j, s); } @@ -502,14 +502,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex /// The result of the multiplication. protected override void DoTransposeThisAndMultiply(Vector rightSide, Vector result) { - for (var i = 0; i < ColumnCount; i++) + for (var j = 0; j < ColumnCount; j++) { var s = Complex.Zero; - for (var j = 0; j < RowCount; j++) + for (var i = 0; i < RowCount; i++) { - s += At(j, i)*rightSide[j]; + s += At(i, j)*rightSide[i]; } - result[i] = s; + result[j] = s; } } @@ -520,14 +520,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex /// The result of the multiplication. protected override void DoConjugateTransposeThisAndMultiply(Vector rightSide, Vector result) { - for (var i = 0; i < ColumnCount; i++) + for (var j = 0; j < ColumnCount; j++) { var s = Complex.Zero; - for (var j = 0; j < RowCount; j++) + for (var i = 0; i < RowCount; i++) { - s += At(j, i).Conjugate()*rightSide[j]; + s += At(i, j).Conjugate()*rightSide[i]; } - result[i] = s; + result[j] = s; } } diff --git a/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs index c0015979..83a48790 100644 --- a/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs +++ b/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs @@ -603,17 +603,13 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 } else { - Control.LinearAlgebraProvider.MatrixMultiplyWithUpdate( - Providers.LinearAlgebra.Transpose.DontTranspose, - Providers.LinearAlgebra.Transpose.DontTranspose, - 1.0f, + Control.LinearAlgebraProvider.MatrixMultiply( _values, _rowCount, _columnCount, denseRight.Values, denseRight.Count, 1, - 0.0f, denseResult.Values); } } @@ -629,17 +625,13 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 var denseResult = result as DenseMatrix; if (denseOther != null && denseResult != null) { - Control.LinearAlgebraProvider.MatrixMultiplyWithUpdate( - Providers.LinearAlgebra.Transpose.DontTranspose, - Providers.LinearAlgebra.Transpose.DontTranspose, - 1.0f, + Control.LinearAlgebraProvider.MatrixMultiply( _values, _rowCount, _columnCount, denseOther._values, denseOther._rowCount, denseOther._columnCount, - 0.0f, denseResult._values); return; } diff --git a/src/Numerics/LinearAlgebra/Complex32/Matrix.cs b/src/Numerics/LinearAlgebra/Complex32/Matrix.cs index bee3b5c6..cc9d5c95 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Matrix.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Matrix.cs @@ -392,16 +392,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 /// The result of the multiplication. protected override void DoMultiply(Matrix other, Matrix result) { - for (var j = 0; j < RowCount; j++) + for (var i = 0; i < RowCount; i++) { - for (var i = 0; i != other.ColumnCount; i++) + for (var j = 0; j != other.ColumnCount; j++) { var s = Complex32.Zero; - for (var l = 0; l < ColumnCount; l++) + for (var k = 0; k < ColumnCount; k++) { - s += At(j, l)*other.At(l, i); + s += At(i, k)*other.At(k, j); } - result.At(j, i, s); + result.At(i, j, s); } } } @@ -418,9 +418,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 for (var i = 0; i < RowCount; i++) { var s = Complex32.Zero; - for (var l = 0; l < ColumnCount; l++) + for (var k = 0; k < ColumnCount; k++) { - s += At(i, l)*other.At(j, l); + s += At(i, k)*other.At(j, k); } result.At(i, j, s); } @@ -439,9 +439,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 for (var i = 0; i < RowCount; i++) { var s = Complex32.Zero; - for (var l = 0; l < ColumnCount; l++) + for (var k = 0; k < ColumnCount; k++) { - s += At(i, l)*other.At(j, l).Conjugate(); + s += At(i, k)*other.At(j, k).Conjugate(); } result.At(i, j, s); } @@ -460,9 +460,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 for (var i = 0; i < ColumnCount; i++) { var s = Complex32.Zero; - for (var l = 0; l < RowCount; l++) + for (var k = 0; k < RowCount; k++) { - s += At(l, i)*other.At(l, j); + s += At(k, i)*other.At(k, j); } result.At(i, j, s); } @@ -481,9 +481,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 for (var i = 0; i < ColumnCount; i++) { var s = Complex32.Zero; - for (var l = 0; l < RowCount; l++) + for (var k = 0; k < RowCount; k++) { - s += At(l, i).Conjugate()*other.At(l, j); + s += At(k, i).Conjugate()*other.At(k, j); } result.At(i, j, s); } @@ -497,14 +497,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 /// The result of the multiplication. protected override void DoTransposeThisAndMultiply(Vector rightSide, Vector result) { - for (var i = 0; i < ColumnCount; i++) + for (var j = 0; j < ColumnCount; j++) { var s = Complex32.Zero; - for (var j = 0; j < RowCount; j++) + for (var i = 0; i < RowCount; i++) { - s += At(j, i)*rightSide[j]; + s += At(i, j)*rightSide[i]; } - result[i] = s; + result[j] = s; } } @@ -515,14 +515,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 /// The result of the multiplication. protected override void DoConjugateTransposeThisAndMultiply(Vector rightSide, Vector result) { - for (var i = 0; i < ColumnCount; i++) + for (var j = 0; j < ColumnCount; j++) { var s = Complex32.Zero; - for (var j = 0; j < RowCount; j++) + for (var i = 0; i < RowCount; i++) { - s += At(j, i).Conjugate()*rightSide[j]; + s += At(i, j).Conjugate()*rightSide[i]; } - result[i] = s; + result[j] = s; } } diff --git a/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs index bcf9683e..496984cb 100644 --- a/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs +++ b/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs @@ -584,17 +584,13 @@ namespace MathNet.Numerics.LinearAlgebra.Double } else { - Control.LinearAlgebraProvider.MatrixMultiplyWithUpdate( - Providers.LinearAlgebra.Transpose.DontTranspose, - Providers.LinearAlgebra.Transpose.DontTranspose, - 1.0, + Control.LinearAlgebraProvider.MatrixMultiply( _values, _rowCount, _columnCount, denseRight.Values, denseRight.Count, 1, - 0.0, denseResult.Values); } } @@ -610,17 +606,13 @@ namespace MathNet.Numerics.LinearAlgebra.Double var denseResult = result as DenseMatrix; if (denseOther != null && denseResult != null) { - Control.LinearAlgebraProvider.MatrixMultiplyWithUpdate( - Providers.LinearAlgebra.Transpose.DontTranspose, - Providers.LinearAlgebra.Transpose.DontTranspose, - 1.0, + Control.LinearAlgebraProvider.MatrixMultiply( _values, _rowCount, _columnCount, denseOther._values, denseOther._rowCount, denseOther._columnCount, - 0.0, denseResult._values); return; } diff --git a/src/Numerics/LinearAlgebra/Double/Matrix.cs b/src/Numerics/LinearAlgebra/Double/Matrix.cs index 68d3b0e6..75dd70a0 100644 --- a/src/Numerics/LinearAlgebra/Double/Matrix.cs +++ b/src/Numerics/LinearAlgebra/Double/Matrix.cs @@ -388,16 +388,16 @@ namespace MathNet.Numerics.LinearAlgebra.Double /// The result of the multiplication. protected override void DoMultiply(Matrix other, Matrix result) { - for (var j = 0; j < RowCount; j++) + for (var i = 0; i < RowCount; i++) { - for (var i = 0; i < other.ColumnCount; i++) + for (var j = 0; j < other.ColumnCount; j++) { var s = 0.0; - for (var l = 0; l < ColumnCount; l++) + for (var k = 0; k < ColumnCount; k++) { - s += At(j, l)*other.At(l, i); + s += At(i, k)*other.At(k, j); } - result.At(j, i, s); + result.At(i, j, s); } } } @@ -414,9 +414,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double for (var i = 0; i < RowCount; i++) { var s = 0.0; - for (var l = 0; l < ColumnCount; l++) + for (var k = 0; k < ColumnCount; k++) { - s += At(i, l)*other.At(j, l); + s += At(i, k)*other.At(j, k); } result.At(i, j, s); } @@ -445,9 +445,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double for (var i = 0; i < ColumnCount; i++) { var s = 0.0; - for (var l = 0; l < RowCount; l++) + for (var k = 0; k < RowCount; k++) { - s += At(l, i)*other.At(l, j); + s += At(k, i)*other.At(k, j); } result.At(i, j, s); } @@ -471,14 +471,14 @@ namespace MathNet.Numerics.LinearAlgebra.Double /// The result of the multiplication. protected override void DoTransposeThisAndMultiply(Vector rightSide, Vector result) { - for (var i = 0; i < ColumnCount; i++) + for (var j = 0; j < ColumnCount; j++) { var s = 0.0; - for (var j = 0; j < RowCount; j++) + for (var i = 0; i < RowCount; i++) { - s += At(j, i)*rightSide[j]; + s += At(i, j)*rightSide[i]; } - result[i] = s; + result[j] = s; } } diff --git a/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs index 5658ad2f..7ec7905a 100644 --- a/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs +++ b/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs @@ -584,17 +584,13 @@ namespace MathNet.Numerics.LinearAlgebra.Single } else { - Control.LinearAlgebraProvider.MatrixMultiplyWithUpdate( - Providers.LinearAlgebra.Transpose.DontTranspose, - Providers.LinearAlgebra.Transpose.DontTranspose, - 1.0f, + Control.LinearAlgebraProvider.MatrixMultiply( _values, _rowCount, _columnCount, denseRight.Values, denseRight.Count, 1, - 0.0f, denseResult.Values); } } @@ -610,17 +606,13 @@ namespace MathNet.Numerics.LinearAlgebra.Single var denseResult = result as DenseMatrix; if (denseOther != null && denseResult != null) { - Control.LinearAlgebraProvider.MatrixMultiplyWithUpdate( - Providers.LinearAlgebra.Transpose.DontTranspose, - Providers.LinearAlgebra.Transpose.DontTranspose, - 1.0f, + Control.LinearAlgebraProvider.MatrixMultiply( _values, _rowCount, _columnCount, denseOther._values, denseOther._rowCount, denseOther._columnCount, - 0.0f, denseResult._values); return; } diff --git a/src/Numerics/LinearAlgebra/Single/Matrix.cs b/src/Numerics/LinearAlgebra/Single/Matrix.cs index 6abc5669..dc020b5a 100644 --- a/src/Numerics/LinearAlgebra/Single/Matrix.cs +++ b/src/Numerics/LinearAlgebra/Single/Matrix.cs @@ -361,16 +361,16 @@ namespace MathNet.Numerics.LinearAlgebra.Single /// The result of the multiplication. protected override void DoMultiply(Matrix other, Matrix result) { - for (var j = 0; j < RowCount; j++) + for (var i = 0; i < RowCount; i++) { - for (var i = 0; i < other.ColumnCount; i++) + for (var j = 0; j < other.ColumnCount; j++) { var s = 0.0f; - for (var l = 0; l < ColumnCount; l++) + for (var k = 0; k < ColumnCount; k++) { - s += At(j, l)*other.At(l, i); + s += At(i, k)*other.At(k, j); } - result.At(j, i, s); + result.At(i, j, s); } } } @@ -413,9 +413,9 @@ namespace MathNet.Numerics.LinearAlgebra.Single for (var i = 0; i < RowCount; i++) { var s = 0.0f; - for (var l = 0; l < ColumnCount; l++) + for (var k = 0; k < ColumnCount; k++) { - s += At(i, l)*other.At(j, l); + s += At(i, k)*other.At(j, k); } result.At(i, j, s); } @@ -444,9 +444,9 @@ namespace MathNet.Numerics.LinearAlgebra.Single for (var i = 0; i < ColumnCount; i++) { var s = 0.0f; - for (var l = 0; l < RowCount; l++) + for (var k = 0; k < RowCount; k++) { - s += At(l, i)*other.At(l, j); + s += At(k, i)*other.At(k, j); } result.At(i, j, s); } @@ -470,14 +470,14 @@ namespace MathNet.Numerics.LinearAlgebra.Single /// The result of the multiplication. protected override void DoTransposeThisAndMultiply(Vector rightSide, Vector result) { - for (var i = 0; i < ColumnCount; i++) + for (var j = 0; j < ColumnCount; j++) { var s = 0.0f; - for (var j = 0; j < RowCount; j++) + for (var i = 0; i < RowCount; i++) { - s += At(j, i)*rightSide[j]; + s += At(i, j)*rightSide[i]; } - result[i] = s; + result[j] = s; } } diff --git a/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex.cs b/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex.cs index 8bd0b943..e4a0812d 100644 --- a/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex.cs +++ b/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex.cs @@ -496,7 +496,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra ydata = y; } - MatrixMultiplyWithUpdate(Transpose.DontTranspose, Transpose.DontTranspose, Complex.One, xdata, rowsX, columnsX, ydata, rowsY, columnsY, Complex.Zero, result); + Array.Clear(result, 0, result.Length); + + CacheObliviousMatrixMultiply(Transpose.DontTranspose, Transpose.DontTranspose, Complex.One, xdata, 0, 0, ydata, 0, 0, result, 0, 0, rowsX, columnsY, columnsX, rowsX, columnsY, columnsX, true); } /// diff --git a/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex32.cs b/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex32.cs index ae36ff99..02c950c4 100644 --- a/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex32.cs +++ b/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex32.cs @@ -493,7 +493,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra ydata = y; } - MatrixMultiplyWithUpdate(Transpose.DontTranspose, Transpose.DontTranspose, Complex32.One, xdata, rowsX, columnsX, ydata, rowsY, columnsY, Complex32.Zero, result); + Array.Clear(result, 0, result.Length); + + CacheObliviousMatrixMultiply(Transpose.DontTranspose, Transpose.DontTranspose, Complex32.One, xdata, 0, 0, ydata, 0, 0, result, 0, 0, rowsX, columnsY, columnsX, rowsX, columnsY, columnsX, true); } /// diff --git a/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Double.cs b/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Double.cs index b73df945..d1e3318a 100644 --- a/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Double.cs +++ b/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Double.cs @@ -488,7 +488,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra ydata = y; } - MatrixMultiplyWithUpdate(Transpose.DontTranspose, Transpose.DontTranspose, 1.0, xdata, rowsX, columnsX, ydata, rowsY, columnsY, 0.0, result); + Array.Clear(result, 0, result.Length); + + CacheObliviousMatrixMultiply(Transpose.DontTranspose, Transpose.DontTranspose, 1.0, xdata, 0, 0, ydata, 0, 0, result, 0, 0, rowsX, columnsY, columnsX, rowsX, columnsY, columnsX, true); } /// diff --git a/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Single.cs b/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Single.cs index e47b174e..98dafcca 100644 --- a/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Single.cs +++ b/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Single.cs @@ -488,7 +488,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra ydata = y; } - MatrixMultiplyWithUpdate(Transpose.DontTranspose, Transpose.DontTranspose, 1.0f, xdata, rowsX, columnsX, ydata, rowsY, columnsY, 0.0f, result); + Array.Clear(result, 0, result.Length); + + CacheObliviousMatrixMultiply(Transpose.DontTranspose, Transpose.DontTranspose, 1.0f, xdata, 0, 0, ydata, 0, 0, result, 0, 0, rowsX, columnsY, columnsX, rowsX, columnsY, columnsX, true); } ///