Browse Source

LA: use provider MatrixMultiply, use more common idx names

pull/248/head
Christoph Ruegg 12 years ago
parent
commit
5798111b8d
  1. 12
      src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs
  2. 42
      src/Numerics/LinearAlgebra/Complex/Matrix.cs
  3. 12
      src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs
  4. 42
      src/Numerics/LinearAlgebra/Complex32/Matrix.cs
  5. 12
      src/Numerics/LinearAlgebra/Double/DenseMatrix.cs
  6. 26
      src/Numerics/LinearAlgebra/Double/Matrix.cs
  7. 12
      src/Numerics/LinearAlgebra/Single/DenseMatrix.cs
  8. 26
      src/Numerics/LinearAlgebra/Single/Matrix.cs
  9. 4
      src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex.cs
  10. 4
      src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex32.cs
  11. 4
      src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Double.cs
  12. 4
      src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Single.cs

12
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;
}

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

@ -371,16 +371,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// <param name="result">The result of the multiplication.</param>
protected override void DoMultiply(Matrix<Complex> other, Matrix<Complex> 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
/// <param name="result">The result of the multiplication.</param>
protected override void DoTransposeThisAndMultiply(Vector<Complex> rightSide, Vector<Complex> 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
/// <param name="result">The result of the multiplication.</param>
protected override void DoConjugateTransposeThisAndMultiply(Vector<Complex> rightSide, Vector<Complex> 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;
}
}

12
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;
}

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

@ -392,16 +392,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// <param name="result">The result of the multiplication.</param>
protected override void DoMultiply(Matrix<Complex32> other, Matrix<Complex32> 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
/// <param name="result">The result of the multiplication.</param>
protected override void DoTransposeThisAndMultiply(Vector<Complex32> rightSide, Vector<Complex32> 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
/// <param name="result">The result of the multiplication.</param>
protected override void DoConjugateTransposeThisAndMultiply(Vector<Complex32> rightSide, Vector<Complex32> 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;
}
}

12
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;
}

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

@ -388,16 +388,16 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// <param name="result">The result of the multiplication.</param>
protected override void DoMultiply(Matrix<double> other, Matrix<double> 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
/// <param name="result">The result of the multiplication.</param>
protected override void DoTransposeThisAndMultiply(Vector<double> rightSide, Vector<double> 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;
}
}

12
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;
}

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

@ -361,16 +361,16 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// <param name="result">The result of the multiplication.</param>
protected override void DoMultiply(Matrix<float> other, Matrix<float> 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
/// <param name="result">The result of the multiplication.</param>
protected override void DoTransposeThisAndMultiply(Vector<float> rightSide, Vector<float> 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;
}
}

4
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);
}
/// <summary>

4
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);
}
/// <summary>

4
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);
}
/// <summary>

4
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);
}
/// <summary>

Loading…
Cancel
Save